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(mypy): resolve missing return statements and type casting issues (#20618)

shin-bot-litellm29990c88ba9f
diff --git a/litellm/litellm_core_utils/token_counter.py b/litellm/litellm_core_utils/token_counter.py
index a99bd1cd0f3..6b9e51034c0 100644
--- a/litellm/litellm_core_utils/token_counter.py
+++ b/litellm/litellm_core_utils/token_counter.py
@@ -706,7 +706,7 @@ def _count_content_list(
if isinstance(c, str):
num_tokens += count_function(c)
elif c["type"] == "text":
- num_tokens += count_function(c.get("text", ""))
+ num_tokens += count_function(str(c.get("text", "")))
elif c["type"] == "image_url":
image_url = c.get("image_url")
num_tokens += _count_image_tokens(
@@ -722,7 +722,7 @@ def _count_content_list(
elif c["type"] == "thinking":
# Claude extended thinking content block
# Count the thinking text and skip signature (opaque signature blob)
- thinking_text = c.get("thinking", "")
+ thinking_text = str(c.get("thinking", ""))
if thinking_text:
num_tokens += count_function(thinking_text)
else:
diff --git a/litellm/proxy/guardrails/guardrail_hooks/pangea/pangea.py b/litellm/proxy/guardrails/guardrail_hooks/pangea/pangea.py
index ca3e6a90801..55c7e72c36f 100644
--- a/litellm/proxy/guardrails/guardrail_hooks/pangea/pangea.py
+++ b/litellm/proxy/guardrails/guardrail_hooks/pangea/pangea.py
@@ -1,6 +1,6 @@
# litellm/proxy/guardrails/guardrail_hooks/pangea.py
import os
-from typing import TYPE_CHECKING, Any, Optional, Type
+from typing import TYPE_CHECKING, Any, Dict, List, Optional, Type, cast
from fastapi import HTTPException
@@ -250,10 +250,13 @@ class PangeaHandler(CustomGuardrail):
if isinstance(response, TextCompletionResponse):
# Assume the earlier call type as well
input_messages = _TextCompletionRequest(data).get_messages()
- if not isinstance(response, ModelResponse):
- return
+ elif isinstance(response, ModelResponse):
+ messages = data.get("messages")
+ if messages is None:
+ return # No messages to check
+ input_messages = cast(List[Dict[Any, Any]], messages)
else:
- input_messages = data.get("messages")
+ return
if choices := response.get("choices"):
if isinstance(choices, list):
diff --git a/litellm/responses/litellm_completion_transformation/handler.py b/litellm/responses/litellm_completion_transformation/handler.py
index 7e0b4cfa243..74ad6675e1d 100644
--- a/litellm/responses/litellm_completion_transformation/handler.py
+++ b/litellm/responses/litellm_completion_transformation/handler.py
@@ -90,6 +90,7 @@ class LiteLLMCompletionTransformationHandler:
custom_llm_provider=custom_llm_provider,
litellm_metadata=kwargs.get("litellm_metadata", {}),
)
+ raise ValueError(f"Unexpected response type: {type(litellm_completion_response)}")
async def async_response_api_handler(
self,
@@ -140,3 +141,4 @@ class LiteLLMCompletionTransformationHandler:
),
litellm_metadata=kwargs.get("litellm_metadata", {}),
)
+ raise ValueError(f"Unexpected response type: {type(litellm_completion_response)}")