Refactor: Centralize call_type Literal definitions into TypeAliases #16408
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The
call_typeparameter's Literal type hint was duplicated across 36+ files (CustomLogger subclasses), causing:aembedding) required editing 36+ files manuallyCallTypesenum (singular:"embedding") and CustomLogger Literals (plural:"embeddings")"aembedding"supportSolution
Created centralized TypeAliases in
litellm/types/callbacks.py:PreCallHookCallType: Forasync_pre_call_hookmethodsModerationHookCallType: Forasync_moderation_hookmethodsUpdated 36 files to use these TypeAliases instead of duplicating Literal definitions.
Impact
Code reduction: -439 lines (603 deletions, 164 insertions)
Files changed:
litellm/types/callbacks.py(centralized TypeAlias definitions)litellm/integrations/custom_logger.py(base class)litellm/proxy/guardrails/guardrail_hooks/(24 files)litellm/proxy/hooks/(4 files)litellm/proxy/example_config_yaml/(2 files)enterprise/(6 files)Benefits
✅ Single source of truth: All call_type definitions in one place
✅ Easier maintenance: Adding new call types requires editing 1 file instead of 36+
✅ Fixes LSP violations: All subclasses now accept the same types as base class
✅ Consistent type checking: MyPy will catch type errors consistently
✅ Adds
aembeddingsupport: Async embeddings now supported (from PR #16328)✅ Future-proof: New call types can be added without touching 36+ files
Testing
This is a pure type system refactoring with no runtime changes:
Related Issues
Fixes #16362
Related: #16240 (guardrail validation bug), #16328 (aembedding PR)
Checklist:
CustomLogger)aembeddingto both TypeAliases