Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix: resolve 7 mypy linting errors on main (#21768)

Ishaan Jaff3840497109e7
diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py
index 10774ffb623..ddcdcf5f048 100644
--- a/litellm/proxy/_types.py
+++ b/litellm/proxy/_types.py
@@ -3668,6 +3668,7 @@ class LitellmMetadataFromRequestHeaders(TypedDict, total=False):
spend_logs_metadata: Optional[dict]
agent_id: Optional[str]
trace_id: Optional[str]
+ session_id: Optional[str]
class JWTKeyItem(TypedDict, total=False):
diff --git a/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/competitor_intent/airline.py b/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/competitor_intent/airline.py
index 7a744990275..583814de1ef 100644
--- a/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/competitor_intent/airline.py
+++ b/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/competitor_intent/airline.py
@@ -14,8 +14,11 @@ from pathlib import Path
from typing import Any, Dict, List, Tuple
from litellm.proxy.guardrails.guardrail_hooks.litellm_content_filter.competitor_intent.base import (
- BaseCompetitorIntentChecker, _compile_marker, _count_signals,
- _word_boundary_match)
+ BaseCompetitorIntentChecker,
+ _compile_marker,
+ _count_signals,
+ _word_boundary_match,
+)
# Location/travel context: prepositions, travel verbs, booking nouns, entry/geo nouns.
# No place-name list; these patterns detect "destination context" generically.
@@ -132,7 +135,7 @@ def _load_competitors_excluding_brand(brand_self: List[str]) -> List[str]:
continue
match_str = entry.get("match") or ""
variants = [v.strip().lower() for v in match_str.split("|") if v.strip()]
- words_in_match = set()
+ words_in_match: Set[str] = set()
for v in variants:
words_in_match.update(v.split())
if brand_set & words_in_match or any(v in brand_set for v in variants):
diff --git a/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/competitor_intent/base.py b/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/competitor_intent/base.py
index 7a86e5542b2..4ebff5fb3c1 100644
--- a/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/competitor_intent/base.py
+++ b/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/competitor_intent/base.py
@@ -7,8 +7,11 @@ import unicodedata
from typing import Any, Dict, List, Optional, Pattern, Set, Tuple, cast
from litellm.types.proxy.guardrails.guardrail_hooks.litellm_content_filter import (
- CompetitorActionHint, CompetitorIntentEvidenceEntry,
- CompetitorIntentResult)
+ CompetitorActionHint,
+ CompetitorIntentEvidenceEntry,
+ CompetitorIntentResult,
+ CompetitorIntentType,
+)
ZERO_WIDTH = re.compile(r"[\u200b-\u200d\u2060\ufeff]")
LEET = {"@": "a", "4": "a", "0": "o", "3": "e", "1": "i", "5": "s", "7": "t"}
@@ -253,20 +256,20 @@ class BaseCompetitorIntentChecker:
else:
intent = "other"
- action_hint: CompetitorActionHint = cast(
+ resolved_action_hint: CompetitorActionHint = cast(
CompetitorActionHint, self.policy.get(intent, "allow")
)
if intent == "log_only":
- action_hint = "log_only"
+ resolved_action_hint = "log_only"
if intent == "other":
- action_hint = "allow"
+ resolved_action_hint = "allow"
return {
- "intent": intent,
+ "intent": cast(CompetitorIntentType, intent),
"confidence": round(confidence, 2),
"entities": entities,
"signals": ["competitor_resolved"]
+ (["comparison"] if has_comparison else []),
- "action_hint": action_hint,
+ "action_hint": resolved_action_hint,
"evidence": evidence,
}
diff --git a/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/content_filter.py b/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/content_filter.py
index 0e75d8e73c6..d569e69e56e 100644
--- a/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/content_filter.py
+++ b/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/content_filter.py
@@ -1746,7 +1746,7 @@ class ContentFilterGuardrail(CustomGuardrail):
end_time=datetime.now().timestamp(),
duration=(datetime.now() - start_time).total_seconds(),
masked_entity_count=masked_entity_count,
- tracing_detail=GuardrailTracingDetail(**tracing_kw),
+ tracing_detail=GuardrailTracingDetail(**tracing_kw), # type: ignore[typeddict-item]
)
async def apply_guardrail(
diff --git a/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/guardrail_benchmarks/test_eval.py b/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/guardrail_benchmarks/test_eval.py
index e6f07b08adb..2c872258cec 100644
--- a/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/guardrail_benchmarks/test_eval.py
+++ b/litellm/proxy/guardrails/guardrail_hooks/litellm_content_filter/guardrail_benchmarks/test_eval.py
@@ -20,7 +20,7 @@ import json
import os
import time
from datetime import datetime, timezone
-from typing import List
+from typing import Any, List
import pytest
from fastapi import HTTPException
@@ -59,7 +59,7 @@ def _run(checker, text: str) -> dict:
return {"decision": "ALLOW", "score": 0.0, "matched_topic": None}
except HTTPException as e:
if e.status_code == 403:
- detail = e.detail if isinstance(e.detail, dict) else {}
+ detail: Dict[str, Any] = e.detail if isinstance(e.detail, dict) else {}
return {
"decision": "BLOCK",
"score": detail.get("score", 1.0),
@@ -228,7 +228,7 @@ def _content_filter(category: str):
guardrail = ContentFilterGuardrail(
guardrail_name=f"{category}_eval",
- categories=[ # type: ignore[arg-type]
+ categories=[ # type: ignore[arg-type,list-item]
{
"category": category,
"enabled": True,