From 0337fa79ea52674fa96c5155403b443d919fe952 Mon Sep 17 00:00:00 2001 From: Shin Date: Sat, 7 Feb 2026 01:14:02 +0000 Subject: [PATCH] fix(mypy): resolve missing return statements and type casting issues --- litellm/litellm_core_utils/token_counter.py | 4 ++-- litellm/proxy/guardrails/guardrail_hooks/pangea/pangea.py | 4 ++-- .../responses/litellm_completion_transformation/handler.py | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) 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..3f36e175461 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 @@ -253,7 +253,7 @@ class PangeaHandler(CustomGuardrail): if not isinstance(response, ModelResponse): return else: - input_messages = data.get("messages") + input_messages = cast(List[Dict[Any, Any]], data.get("messages")) 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)}")