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]

fixes mypy linting

Ishaan Jaffea377de5a5ba
diff --git a/litellm/llms/databricks/chat/transformation.py b/litellm/llms/databricks/chat/transformation.py
index cda372470a4..4852f2e7106 100644
--- a/litellm/llms/databricks/chat/transformation.py
+++ b/litellm/llms/databricks/chat/transformation.py
@@ -180,7 +180,7 @@ class DatabricksConfig(DatabricksBase, OpenAILikeChatConfig, AnthropicConfig):
return DatabricksTool(
type="function",
- function=DatabricksFunction(**kwags),
+ function=DatabricksFunction(name=tool["name"], **kwags),
)
def _map_openai_to_dbrx_tool(self, model: str, tools: List) -> List[DatabricksTool]:
@@ -338,7 +338,8 @@ class DatabricksConfig(DatabricksBase, OpenAILikeChatConfig, AnthropicConfig):
content_str = ""
for item in content:
if item.get("type") == "text":
- content_str += item.get("text", "")
+ text_value = item.get("text", "")
+ content_str += str(text_value) if text_value is not None else ""
return content_str
else:
raise Exception(f"Unsupported content type: {type(content)}")
@@ -369,18 +370,19 @@ class DatabricksConfig(DatabricksBase, OpenAILikeChatConfig, AnthropicConfig):
for item in content:
if item.get("type") == "reasoning":
summary_list = item.get("summary", [])
- for sum in summary_list:
- if reasoning_content is None:
- reasoning_content = ""
- reasoning_content += sum["text"]
- thinking_block = ChatCompletionThinkingBlock(
- type="thinking",
- thinking=sum.get("text", ""),
- signature=sum.get("signature", ""),
- )
- if thinking_blocks is None:
- thinking_blocks = []
- thinking_blocks.append(thinking_block)
+ if isinstance(summary_list, list):
+ for sum in summary_list:
+ if reasoning_content is None:
+ reasoning_content = ""
+ reasoning_content += sum["text"]
+ thinking_block = ChatCompletionThinkingBlock(
+ type="thinking",
+ thinking=sum.get("text", ""),
+ signature=sum.get("signature", ""),
+ )
+ if thinking_blocks is None:
+ thinking_blocks = []
+ thinking_blocks.append(thinking_block)
return reasoning_content, thinking_blocks
@staticmethod
diff --git a/litellm/responses/mcp/litellm_proxy_mcp_handler.py b/litellm/responses/mcp/litellm_proxy_mcp_handler.py
index 7a9a21a9690..8470003b325 100644
--- a/litellm/responses/mcp/litellm_proxy_mcp_handler.py
+++ b/litellm/responses/mcp/litellm_proxy_mcp_handler.py
@@ -27,10 +27,10 @@ class LiteLLM_Proxy_MCP_Handler:
"""
if tools:
for tool in tools:
- if (isinstance(tool, dict) and
- tool.get("type") == "mcp" and
- tool.get("server_url", "").startswith(LITELLM_PROXY_MCP_SERVER_URL)):
- return True
+ if isinstance(tool, dict) and tool.get("type") == "mcp":
+ server_url = tool.get("server_url", "")
+ if isinstance(server_url, str) and server_url.startswith(LITELLM_PROXY_MCP_SERVER_URL):
+ return True
return False
@staticmethod
@@ -46,10 +46,12 @@ class LiteLLM_Proxy_MCP_Handler:
if tools:
for tool in tools:
- if (isinstance(tool, dict) and
- tool.get("type") == "mcp" and
- tool.get("server_url", "").startswith(LITELLM_PROXY_MCP_SERVER_URL)):
- mcp_tools_with_litellm_proxy.append(tool)
+ if isinstance(tool, dict) and tool.get("type") == "mcp":
+ server_url = tool.get("server_url", "")
+ if isinstance(server_url, str) and server_url.startswith(LITELLM_PROXY_MCP_SERVER_URL):
+ mcp_tools_with_litellm_proxy.append(tool)
+ else:
+ other_tools.append(tool)
else:
other_tools.append(tool)
@@ -74,8 +76,9 @@ class LiteLLM_Proxy_MCP_Handler:
if mcp_tools_with_litellm_proxy:
for _tool in mcp_tools_with_litellm_proxy:
# if user specifies servers as server_url: litellm_proxy/mcp/zapier,github then return zapier,github
- if _tool.get("server_url", "").startswith(LITELLM_PROXY_MCP_SERVER_URL_PREFIX):
- mcp_servers.append(_tool.get("server_url", "").split("/")[-1])
+ server_url = _tool.get("server_url", "") if isinstance(_tool, dict) else ""
+ if isinstance(server_url, str) and server_url.startswith(LITELLM_PROXY_MCP_SERVER_URL_PREFIX):
+ mcp_servers.append(server_url.split("/")[-1])
return await _get_tools_from_mcp_servers(
user_api_key_auth=user_api_key_auth,
@@ -588,7 +591,7 @@ class LiteLLM_Proxy_MCP_Handler:
from litellm.responses.mcp.mcp_streaming_iterator import create_mcp_call_events
- tool_execution_events = []
+ tool_execution_events: List[Any] = []
# Create events for each tool execution
for tool_result in tool_results:
diff --git a/litellm/responses/mcp/mcp_streaming_iterator.py b/litellm/responses/mcp/mcp_streaming_iterator.py
index bf6a9182522..e43426253de 100644
--- a/litellm/responses/mcp/mcp_streaming_iterator.py
+++ b/litellm/responses/mcp/mcp_streaming_iterator.py
@@ -45,15 +45,15 @@ async def create_mcp_list_tools_events(
LiteLLM_Proxy_MCP_Handler,
)
- events = []
+ events: List[ResponsesAPIStreamingResponse] = []
try:
# Extract MCP server names
mcp_servers = []
for tool in mcp_tools_with_litellm_proxy:
if isinstance(tool, dict) and "server_url" in tool:
- server_url = tool["server_url"]
- if server_url.startswith("litellm_proxy/mcp/"):
+ server_url = tool.get("server_url")
+ if isinstance(server_url, str) and server_url.startswith("litellm_proxy/mcp/"):
server_name = server_url.split("/")[-1]
mcp_servers.append(server_name)
@@ -72,7 +72,7 @@ async def create_mcp_list_tools_events(
# Convert tools to dict format for the event
mcp_tools_dict = []
for tool in filtered_mcp_tools:
- if hasattr(tool, 'model_dump'):
+ if hasattr(tool, 'model_dump') and callable(getattr(tool, 'model_dump')):
mcp_tools_dict.append(tool.model_dump())
elif hasattr(tool, '__dict__'):
mcp_tools_dict.append(tool.__dict__)
@@ -96,7 +96,8 @@ async def create_mcp_list_tools_events(
if mcp_tools_with_litellm_proxy:
first_tool = mcp_tools_with_litellm_proxy[0]
if isinstance(first_tool, dict):
- server_label = first_tool.get("server_label", "")
+ server_label_value = first_tool.get("server_label", "")
+ server_label = str(server_label_value) if server_label_value is not None else ""
# Format tools for OpenAI output_item.done format
formatted_tools = []
@@ -109,9 +110,9 @@ async def create_mcp_list_tools_events(
# Add input_schema if available
if hasattr(tool, 'inputSchema'):
- tool_dict["input_schema"] = tool.inputSchema
+ tool_dict["input_schema"] = getattr(tool, 'inputSchema')
elif hasattr(tool, 'input_schema'):
- tool_dict["input_schema"] = tool.input_schema
+ tool_dict["input_schema"] = getattr(tool, 'input_schema')
formatted_tools.append(tool_dict)
@@ -171,7 +172,7 @@ def create_mcp_call_events(
sequence_start: int = 1
) -> List[ResponsesAPIStreamingResponse]:
"""Create MCP call events following OpenAI's specification"""
- events = []
+ events: List[ResponsesAPIStreamingResponse] = []
item_id = base_item_id or f"mcp_{uuid.uuid4().hex[:8]}"
# MCP call in progress event