Skip to content

Conversation

@Chesars
Copy link
Contributor

@Chesars Chesars commented Nov 20, 2025

Summary

Closes #16495

This PR continues the refactoring started in #16362 (commit c96da44) by replacing inline Literal type definitions for call_type parameters with the centralized CallTypesLiteral import from litellm.types.utils across 17 additional files.

Changes

  • Added CallTypesLiteral import to 17 files
  • Removed duplicate inline Literal[...] definitions
  • Net reduction: 295 lines of code removed (45 insertions, 340 deletions)

Benefits

  • DRY Principle: Eliminates duplication of the same type definition across multiple files
  • Maintainability: Single source of truth for call_type values
  • Type Safety: Maintains full type checking while using centralized definition
  • Consistency: Follows the same pattern from commit c96da44

Files Modified (17 total)

  • litellm/cost_calculator.py
  • litellm/router.py (largest change: 67 lines removed)
  • litellm/litellm_core_utils/llm_response_utils/get_formatted_prompt.py
  • 14 guardrail hooks:
    • litellm/proxy/guardrails/guardrail_hooks/aporia_ai/aporia_ai.py
    • litellm/proxy/guardrails/guardrail_hooks/azure/prompt_shield.py
    • litellm/proxy/guardrails/guardrail_hooks/azure/text_moderation.py
    • litellm/proxy/guardrails/guardrail_hooks/custom_guardrail.py
    • litellm/proxy/guardrails/guardrail_hooks/grayswan/grayswan.py
    • litellm/proxy/guardrails/guardrail_hooks/guardrails_ai/guardrails_ai.py
    • litellm/proxy/guardrails/guardrail_hooks/lakera_ai.py
    • litellm/proxy/guardrails/guardrail_hooks/lasso/lasso.py
    • litellm/proxy/guardrails/guardrail_hooks/model_armor/model_armor.py
    • litellm/proxy/guardrails/guardrail_hooks/openai/moderations.py
    • litellm/proxy/guardrails/guardrail_hooks/panw_prisma_airs/panw_prisma_airs.py
    • litellm/proxy/guardrails/guardrail_hooks/pillar/pillar.py
    • litellm/proxy/guardrails/guardrail_hooks/tool_permission.py
    • litellm/proxy/hooks/prompt_injection_detection.py

Example

# Before:
call_type: Literal[
    "completion",
    "text_completion",
    "embeddings",
    # ... more values
]
  # After:
  call_type: CallTypesLiteral

Testing

  • Type checking remains intact (MyPy compatible)
  • No runtime behavior changes (type hints are not enforced at runtime)
  • All existing tests should pass without modification

Resolves BerriAI#16495

Replaced inline Literal type definitions for call_type parameters with
the centralized CallTypesLiteral import from litellm.types.utils across
17 files. This follows the same pattern established in commit c96da44
which resolved issue BerriAI#16362.

Changes:
- Added CallTypesLiteral import to 17 files
- Removed duplicate inline Literal[...] definitions (337 lines removed)
- Maintains type safety while improving code maintainability (DRY principle)

Files modified:
- litellm/cost_calculator.py
- litellm/router.py (67 lines removed)
- litellm/litellm_core_utils/llm_response_utils/get_formatted_prompt.py
- litellm/proxy/guardrails/guardrail_hooks/aporia_ai/aporia_ai.py
- litellm/proxy/guardrails/guardrail_hooks/azure/prompt_shield.py
- litellm/proxy/guardrails/guardrail_hooks/azure/text_moderation.py
- litellm/proxy/guardrails/guardrail_hooks/custom_guardrail.py
- litellm/proxy/guardrails/guardrail_hooks/grayswan/grayswan.py
- litellm/proxy/guardrails/guardrail_hooks/guardrails_ai/guardrails_ai.py
- litellm/proxy/guardrails/guardrail_hooks/lakera_ai.py
- litellm/proxy/guardrails/guardrail_hooks/lasso/lasso.py
- litellm/proxy/guardrails/guardrail_hooks/model_armor/model_armor.py
- litellm/proxy/guardrails/guardrail_hooks/openai/moderations.py
- litellm/proxy/guardrails/guardrail_hooks/panw_prisma_airs/panw_prisma_airs.py
- litellm/proxy/guardrails/guardrail_hooks/pillar/pillar.py
- litellm/proxy/guardrails/guardrail_hooks/tool_permission.py
- litellm/proxy/hooks/prompt_injection_detection.py

Total: 17 files changed, 42 insertions(+), 337 deletions(-)
@vercel
Copy link

vercel bot commented Nov 20, 2025

@Chesars is attempting to deploy a commit to the CLERKIEAI Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor: Additional files with duplicate call_type Literal definitions (21 files)

1 participant