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
fix(bedrock): stop forwarding no-op toolSpec.strict to Converse (#35688)
tin-berriec9acf7362c1
diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.jsonindex 07f04136bd0..848af54cbcf 100644--- a/litellm/model_prices_and_context_window_backup.json+++ b/litellm/model_prices_and_context_window_backup.json@@ -1975,6 +1975,7 @@"prompt_cache_min_tokens": 2048},"anthropic.claude-sonnet-5": {+ "bedrock_converse_supports_strict_tools": false,"cache_creation_input_token_cost": 2.5e-06,"cache_creation_input_token_cost_above_1hr": 4e-06,"cache_read_input_token_cost": 2e-07,@@ -2011,6 +2012,7 @@"prompt_cache_min_tokens": 1024},"global.anthropic.claude-sonnet-5": {+ "bedrock_converse_supports_strict_tools": false,"cache_creation_input_token_cost": 2.5e-06,"cache_creation_input_token_cost_above_1hr": 4e-06,"cache_read_input_token_cost": 2e-07,@@ -2047,6 +2049,7 @@"prompt_cache_min_tokens": 1024},"us.anthropic.claude-sonnet-5": {+ "bedrock_converse_supports_strict_tools": false,"cache_creation_input_token_cost": 2.75e-06,"cache_creation_input_token_cost_above_1hr": 4.4e-06,"cache_read_input_token_cost": 2.2e-07,@@ -2083,6 +2086,7 @@"prompt_cache_min_tokens": 1024},"eu.anthropic.claude-sonnet-5": {+ "bedrock_converse_supports_strict_tools": false,"cache_creation_input_token_cost": 2.75e-06,"cache_creation_input_token_cost_above_1hr": 4.4e-06,"cache_read_input_token_cost": 2.2e-07,@@ -2119,6 +2123,7 @@"prompt_cache_min_tokens": 1024},"au.anthropic.claude-sonnet-5": {+ "bedrock_converse_supports_strict_tools": false,"cache_creation_input_token_cost": 2.75e-06,"cache_creation_input_token_cost_above_1hr": 4.4e-06,"cache_read_input_token_cost": 2.2e-07,@@ -2155,6 +2160,7 @@"prompt_cache_min_tokens": 1024},"jp.anthropic.claude-sonnet-5": {+ "bedrock_converse_supports_strict_tools": false,"cache_creation_input_token_cost": 2.75e-06,"cache_creation_input_token_cost_above_1hr": 4.4e-06,"cache_read_input_token_cost": 2.2e-07,diff --git a/litellm/types/llms/bedrock.py b/litellm/types/llms/bedrock.pyindex d9f8229dbed..21de28a9b29 100644--- a/litellm/types/llms/bedrock.py+++ b/litellm/types/llms/bedrock.py@@ -301,7 +301,7 @@ class BedrockToolSpec(dict):"name": name,"description": description,}- if supports_strict_tools and strict is not None:+ if supports_strict_tools and strict:tool_spec["strict"] = strictsuper().__init__(toolSpec=tool_spec)diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.jsonindex 346f613ea3e..56e0391f419 100644--- a/model_prices_and_context_window.json+++ b/model_prices_and_context_window.json@@ -1975,6 +1975,7 @@"prompt_cache_min_tokens": 2048},"anthropic.claude-sonnet-5": {+ "bedrock_converse_supports_strict_tools": false,"cache_creation_input_token_cost": 2.5e-06,"cache_creation_input_token_cost_above_1hr": 4e-06,"cache_read_input_token_cost": 2e-07,@@ -2011,6 +2012,7 @@"prompt_cache_min_tokens": 1024},"global.anthropic.claude-sonnet-5": {+ "bedrock_converse_supports_strict_tools": false,"cache_creation_input_token_cost": 2.5e-06,"cache_creation_input_token_cost_above_1hr": 4e-06,"cache_read_input_token_cost": 2e-07,@@ -2047,6 +2049,7 @@"prompt_cache_min_tokens": 1024},"us.anthropic.claude-sonnet-5": {+ "bedrock_converse_supports_strict_tools": false,"cache_creation_input_token_cost": 2.75e-06,"cache_creation_input_token_cost_above_1hr": 4.4e-06,"cache_read_input_token_cost": 2.2e-07,@@ -2083,6 +2086,7 @@"prompt_cache_min_tokens": 1024},"eu.anthropic.claude-sonnet-5": {+ "bedrock_converse_supports_strict_tools": false,"cache_creation_input_token_cost": 2.75e-06,"cache_creation_input_token_cost_above_1hr": 4.4e-06,"cache_read_input_token_cost": 2.2e-07,@@ -2119,6 +2123,7 @@"prompt_cache_min_tokens": 1024},"au.anthropic.claude-sonnet-5": {+ "bedrock_converse_supports_strict_tools": false,"cache_creation_input_token_cost": 2.75e-06,"cache_creation_input_token_cost_above_1hr": 4.4e-06,"cache_read_input_token_cost": 2.2e-07,@@ -2155,6 +2160,7 @@"prompt_cache_min_tokens": 1024},"jp.anthropic.claude-sonnet-5": {+ "bedrock_converse_supports_strict_tools": false,"cache_creation_input_token_cost": 2.75e-06,"cache_creation_input_token_cost_above_1hr": 4.4e-06,"cache_read_input_token_cost": 2.2e-07,diff --git a/tests/test_litellm/litellm_core_utils/prompt_templates/test_bedrock_converse_strict_tools_opus_47_48.py b/tests/test_litellm/litellm_core_utils/prompt_templates/test_bedrock_converse_strict_tools_opus_47_48.pyindex 791982fc3dc..370ec4b6f60 100644--- a/tests/test_litellm/litellm_core_utils/prompt_templates/test_bedrock_converse_strict_tools_opus_47_48.py+++ b/tests/test_litellm/litellm_core_utils/prompt_templates/test_bedrock_converse_strict_tools_opus_47_48.py@@ -4,6 +4,11 @@ Bedrock Converse routes Claude Opus 4.7/4.8 and Claude Sonnet 4 through anAnthropic-compatible validator that rejects ``toolSpec.strict`` even thoughAnthropic's native API accepts ``strict`` as a top-level tool field. SeeBerriAI/litellm#31582.++That per-model gate only covers models whose cost-map entry carries the flag, so a+``strict: false`` that litellm itself synthesized still broke unflagged models. Since+``strict: false`` is the Chat Completions default, it is now dropped for every model+rather than forwarded as a no-op the provider can reject. See BerriAI/litellm#33193."""import pytest@@ -31,6 +36,16 @@ _STRICT_TOOL = [}]+_NON_STRICT_TOOL = [+ {+ "type": "function",+ "function": {+ **_STRICT_TOOL[0]["function"],+ "strict": False,+ },+ }+]+@pytest.mark.parametrize("model_id",@@ -48,12 +63,17 @@ _STRICT_TOOL = ["bedrock/us.anthropic.claude-sonnet-4-20250514-v1:0","bedrock/eu.anthropic.claude-sonnet-4-20250514-v1:0","bedrock/apac.anthropic.claude-sonnet-4-20250514-v1:0",+ # Sonnet 5 rejects it too, verified live against Bedrock in us-east-1+ "anthropic.claude-sonnet-5",+ "bedrock/us.anthropic.claude-sonnet-5",+ "bedrock/eu.anthropic.claude-sonnet-5",+ "bedrock/jp.anthropic.claude-sonnet-5",],)def test_bedrock_tools_pt_strict_dropped_for_strict_unsupported_models(model_id: str,) -> None:- """Opus 4.7/4.8 and Sonnet 4 reject toolSpec.strict and additionalProperties."""+ """Opus 4.7/4.8, Sonnet 4 and Sonnet 5 reject toolSpec.strict and additionalProperties."""result = _bedrock_tools_pt(_STRICT_TOOL, model=model_id)tool_spec = result[0]["toolSpec"]assert (@@ -81,6 +101,55 @@ def test_bedrock_tools_pt_strict_kept_for_other_anthropic(model_id: str) -> None), f"strict missing for {model_id}: {result[0]['toolSpec']}"+ "model_id",+ [+ "bedrock/us.anthropic.claude-sonnet-5",+ "bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0",+ "anthropic.claude-sonnet-4-5-20250929-v1:0",+ "bedrock/us.anthropic.claude-sonnet-4-6",+ "bedrock/us.anthropic.claude-opus-4-8",+ ],+)+def test_bedrock_tools_pt_falsy_strict_always_dropped(model_id: str) -> None:+ """``strict: false`` is the Chat Completions default, so forwarding it says nothing+ the provider does not already assume. Bedrock Converse rejects the key's presence+ for a growing set of Claude models, so it is dropped for every model, including the+ ones whose cost-map entry still allows ``strict: true`` through."""+ result = _bedrock_tools_pt(_NON_STRICT_TOOL, model=model_id)+ tool_spec = result[0]["toolSpec"]+ assert (+ "strict" not in tool_spec+ ), f"no-op strict: false leaked into toolSpec for {model_id}: {tool_spec}"+++def test_responses_bridge_function_tool_does_not_reach_bedrock_with_strict() -> None:+ """The Responses-to-Chat-Completions bridge stamps ``strict: false`` onto every+ function tool even when the caller never sent one, which is how Codex CLI requests+ acquired the key. Assert the fabricated value does not survive to toolSpec."""+ from litellm.responses.litellm_completion_transformation.transformation import (+ LiteLLMCompletionResponsesConfig,+ )++ responses_tool = {+ "type": "function",+ "name": "get_weather",+ "description": "Get the weather for a city",+ "parameters": {+ "type": "object",+ "properties": {"city": {"type": "string"}},+ "required": ["city"],+ },+ }+ chat_tools, _ = (+ LiteLLMCompletionResponsesConfig.transform_responses_api_tools_to_chat_completion_tools(+ [responses_tool]+ )+ )+ result = _bedrock_tools_pt(chat_tools, model="bedrock/us.anthropic.claude-sonnet-5")+ assert "strict" not in result[0]["toolSpec"]++@pytest.mark.parametrize("model_id",[@@ -129,6 +198,15 @@ def test_bedrock_converse_supports_strict_tools_helper() -> None:)is False)+ assert bedrock_converse_supports_strict_tools("anthropic.claude-sonnet-5") is False+ assert (+ bedrock_converse_supports_strict_tools("bedrock/us.anthropic.claude-sonnet-5")+ is False+ )+ assert (+ bedrock_converse_supports_strict_tools("bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0")+ is True+ )@pytest.mark.parametrize(@@ -143,6 +221,12 @@ def test_bedrock_converse_supports_strict_tools_helper() -> None:"us.anthropic.claude-sonnet-4-20250514-v1:0","eu.anthropic.claude-sonnet-4-20250514-v1:0","apac.anthropic.claude-sonnet-4-20250514-v1:0",+ "anthropic.claude-sonnet-5",+ "global.anthropic.claude-sonnet-5",+ "us.anthropic.claude-sonnet-5",+ "eu.anthropic.claude-sonnet-5",+ "au.anthropic.claude-sonnet-5",+ "jp.anthropic.claude-sonnet-5",],)def test_strict_tools_flag_set_in_model_cost_map(cost_map_key: str) -> None: