-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Open
Labels
Description
Summary
While reviewing issue #16362, I found 21 additional files that have the same problem: duplicate inline Literal definitions for call_type parameters instead of using the centralized CallTypesLiteral type alias.
The original issue identified 17 files, and PR #16408 successfully updated 16 of them. However, there are 21 more files throughout the codebase with the same pattern that were not included in the original list.
Current Status
From Original Issue #16362:
- ✅ 16 files updated in main
- ❌ 1 file still pending:
litellm/proxy/guardrails/guardrail_hooks/aporia_ai/aporia_ai.py(line 184)
Newly Identified Files (21):
Guardrails (12 files):
litellm/proxy/guardrails/guardrail_hooks/azure/prompt_shield.py(line 117)litellm/proxy/guardrails/guardrail_hooks/azure/text_moderation.py(line 210)litellm/proxy/guardrails/guardrail_hooks/custom_guardrail.py(multiple lines)litellm/proxy/guardrails/guardrail_hooks/grayswan/grayswan.py(line 113)litellm/proxy/guardrails/guardrail_hooks/guardrails_ai/guardrails_ai.py(line 201)litellm/proxy/guardrails/guardrail_hooks/lakera_ai.py(line 128)litellm/proxy/guardrails/guardrail_hooks/lasso/lasso.py(line 130)litellm/proxy/guardrails/guardrail_hooks/model_armor/model_armor.py(line 363)litellm/proxy/guardrails/guardrail_hooks/openai/moderations.py(line 187)litellm/proxy/guardrails/guardrail_hooks/panw_prisma_airs/panw_prisma_airs.py(line 567)litellm/proxy/guardrails/guardrail_hooks/pillar/pillar.py(line 191)litellm/proxy/guardrails/guardrail_hooks/tool_permission.py(line 274)
Proxy/Hooks (2 files):
litellm/proxy/hooks/prompt_injection_detection.py(line 222)litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py
Core Library (6 files):
litellm/router.pylitellm/llms/openai/cost_calculation.pylitellm/llms/vertex_ai/cost_calculator.pylitellm/llms/huggingface/embedding/handler.pylitellm/integrations/langfuse/langfuse_prompt_management.pylitellm/litellm_core_utils/llm_response_utils/get_formatted_prompt.py
Others
litellm/cost_calculator.py(line 1202) - This file usesCallTypesLiteralin most places but still has one inlineLiteraldefinition
Total: 22 files that need the same refactoring
Same as issue #16362:
- DRY - Adding new call types requires updating multiple files
- Liskov Substitution Principle violation - Subclasses may have more restrictive types than base class
- Maintainability - Centralized type definition is easier to maintain
- Consistency - All files follow the same pattern
Proposed Solution
Apply the same fix to these 21 files:
- Add import:
from litellm.types.utils import CallTypesLiteral - Replace inline
Literal[...]withCallTypesLiteral
Example:
Before:
from typing import Literal
async def async_pre_call_hook(
call_type: Literal[
"completion",
"embeddings",
"image_generation",
# ... more types
],
):
passAfter:
from litellm.types.utils import CallTypesLiteral
async def async_pre_call_hook(
call_type: CallTypesLiteral,
):
passVerification Command
To find all remaining files with inline Literal definitions:
find litellm -name "*.py" -type f -print0 | xargs -0 grep -l "call_type.*:.*Literal\[" 2>/dev/nullChecklist
- Update
aporia_ai.py(from original issue Refactor: duplicate call_type Literal definitions aross +21 CustomLogger subclasses #16362) - Update 12 guardrail files
- Update 2 proxy/hooks files
- Update 6 core library files
- Run MyPy to verify no type errors
- Run tests to ensure no breakage
Note: Happy to submit a PR for this if helpful!
Related to
- Issue Refactor: duplicate call_type Literal definitions aross +21 CustomLogger subclasses #16362 - Original refactor issue
- PR Refactor: Centralize call_type Literal definitions into TypeAliases #16408 - Partial implementation (16/17 files from original issue)