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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
add _is_bedrock_tool_block
Ishaan Jaffere6c1a656f413
diff --git a/litellm/litellm_core_utils/prompt_templates/factory.py b/litellm/litellm_core_utils/prompt_templates/factory.pyindex 98ee5e4fa86..0e1637a65ba 100644--- a/litellm/litellm_core_utils/prompt_templates/factory.py+++ b/litellm/litellm_core_utils/prompt_templates/factory.py@@ -4395,6 +4395,32 @@ def add_cache_point_tool_block(tool: dict) -> Optional[BedrockToolBlock]:return None+def _is_bedrock_tool_block(tool: dict) -> bool:+ """+ Check if a tool is already a BedrockToolBlock.++ BedrockToolBlock has one of: systemTool, toolSpec, or cachePoint.+ This is used to detect tools that are already in Bedrock format+ (e.g., systemTool for Nova grounding) vs OpenAI-style function tools+ that need transformation.++ Args:+ tool: The tool dict to check++ Returns:+ True if the tool is already a BedrockToolBlock, False otherwise++ Examples:+ >>> _is_bedrock_tool_block({"systemTool": {"name": "nova_grounding"}})+ True+ >>> _is_bedrock_tool_block({"type": "function", "function": {...}})+ False+ """+ return isinstance(tool, dict) and (+ "systemTool" in tool or "toolSpec" in tool or "cachePoint" in tool+ )++def _bedrock_tools_pt(tools: List) -> List[BedrockToolBlock]:"""OpenAI tools looks like:@@ -4448,7 +4474,13 @@ def _bedrock_tools_pt(tools: List) -> List[BedrockToolBlock]:tool_block_list: List[BedrockToolBlock] = []for tool in tools:- # Handle regular function tools+ # Check if tool is already a BedrockToolBlock (e.g., systemTool for Nova grounding)+ if _is_bedrock_tool_block(tool):+ # Already a BedrockToolBlock, pass it through+ tool_block_list.append(tool) # type: ignore+ continue++ # Handle regular OpenAI-style function toolsparameters = tool.get("function", {}).get("parameters", {"type": "object", "properties": {}})