From a5bee2645da13edbc1742b2a6b72e5b46b25c254 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Fri, 30 Oct 2026 03:04:07 -0700 Subject: [PATCH] fix(bedrock): stop naming typed tools on Bedrock invoke /v1/messages so toolset entries reach Claude A computer_toolset or browser_toolset entry carries no name, and Bedrock refuses any name on one, so the placeholder name LiteLLM added for nameless tools turned every toolset request into a 400. Only custom tools get the placeholder now. Typed tools pass through as the caller sent them. --- litellm/llms/bedrock/common_utils.py | 10 ++++--- .../test_anthropic_claude_transformation.py | 28 +++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/litellm/llms/bedrock/common_utils.py b/litellm/llms/bedrock/common_utils.py index d88d7e6280c..03be018aed6 100644 --- a/litellm/llms/bedrock/common_utils.py +++ b/litellm/llms/bedrock/common_utils.py @@ -683,17 +683,19 @@ def normalize_tool_input_schema_types_for_bedrock_invoke(request_body: dict) -> def ensure_bedrock_anthropic_messages_tool_names(request_body: dict) -> None: """ - Bedrock Invoke (Anthropic Messages) requires each tool to include ``name``. + Bedrock Invoke (Anthropic Messages) requires each custom tool to include ``name``. Some clients send only ``input_schema``; Bedrock then errors with ``tools.0.custom.name: Field required``. - In-place: set ``name`` to ``litellm_unnamed_tool_{index}`` when missing or blank. + In-place: set ``name`` to ``litellm_unnamed_tool_{index}`` on a custom tool whose name + is missing or blank. Typed tools pass through as sent, since a toolset entry refuses + any name and a dated tool accepts only its fixed one. """ tools: Final = request_body.get("tools") if not tools or not isinstance(tools, list): return - for i, tool in enumerate(tools): - if not isinstance(tool, dict): + for i, tool in enumerate(_TOOL_ITEMS_ADAPTER.validate_python(tools)): + if not _is_str_keyed_dict(tool) or tool.get("type") not in (None, "custom"): continue name = tool.get("name") if name is None or (isinstance(name, str) and not name.strip()): diff --git a/tests/unit/llms/bedrock/messages/invoke_transformations/test_anthropic_claude_transformation.py b/tests/unit/llms/bedrock/messages/invoke_transformations/test_anthropic_claude_transformation.py index 0bd480dcdbc..20936c3a813 100644 --- a/tests/unit/llms/bedrock/messages/invoke_transformations/test_anthropic_claude_transformation.py +++ b/tests/unit/llms/bedrock/messages/invoke_transformations/test_anthropic_claude_transformation.py @@ -706,6 +706,34 @@ def test_bedrock_invoke_messages_transform_adds_name_when_tool_missing_name(): assert result["tools"][0]["name"] == "litellm_unnamed_tool_0" +def test_bedrock_invoke_messages_transform_names_only_custom_tools(): + """Bedrock refuses any name on a toolset entry, so only the unnamed custom tool gets a placeholder.""" + from litellm.types.router import GenericLiteLLMParams + + cfg = AmazonAnthropicClaudeMessagesConfig() + result = cfg.transform_anthropic_messages_request( + model="us.anthropic.claude-sonnet-4-5-20250929-v1:0", + messages=[{"role": "user", "content": "Take a screenshot"}], + anthropic_messages_optional_request_params={ + "max_tokens": 128, + "tools": [ + {"type": "computer_toolset_20260801"}, + {"type": "browser_toolset_20260801"}, + {"type": "custom", "input_schema": {"type": "object", "properties": {}}}, + {"input_schema": {"type": "object", "properties": {}}}, + ], + }, + litellm_params=GenericLiteLLMParams(), + headers={}, + ) + assert result["tools"] == [ + {"type": "computer_toolset_20260801"}, + {"type": "browser_toolset_20260801"}, + {"type": "custom", "input_schema": {"type": "object", "properties": {}}, "name": "litellm_unnamed_tool_2"}, + {"input_schema": {"type": "object", "properties": {}}, "name": "litellm_unnamed_tool_3"}, + ] + + def test_bedrock_invoke_messages_skips_thinking_injection_when_already_enabled( local_model_cost_map, ):