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]

fix(bedrock): drop strict/additionalProperties from toolSpec for Claude Sonnet 4 (#31943)

Sameer Kankute64dc5080b98b
diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json
index 1a45731e915..bf63ef73c22 100644
--- a/litellm/model_prices_and_context_window_backup.json
+++ b/litellm/model_prices_and_context_window_backup.json
@@ -2093,7 +2093,8 @@
"supports_reasoning": true,
"supports_response_schema": true,
"supports_tool_choice": true,
- "supports_vision": true
+ "supports_vision": true,
+ "bedrock_converse_supports_strict_tools": false
},
"anthropic.claude-sonnet-4-5-20250929-v1:0": {
"cache_creation_input_token_cost": 3.75e-06,
@@ -2420,7 +2421,8 @@
"supports_reasoning": true,
"supports_response_schema": true,
"supports_tool_choice": true,
- "supports_vision": true
+ "supports_vision": true,
+ "bedrock_converse_supports_strict_tools": false
},
"assemblyai/best": {
"input_cost_per_second": 3.333e-05,
@@ -14824,7 +14826,8 @@
"supports_reasoning": true,
"supports_response_schema": true,
"supports_tool_choice": true,
- "supports_vision": true
+ "supports_vision": true,
+ "bedrock_converse_supports_strict_tools": false
},
"eu.anthropic.claude-sonnet-4-5-20250929-v1:0": {
"cache_creation_input_token_cost": 4.125e-06,
@@ -20085,7 +20088,8 @@
"supports_reasoning": true,
"supports_response_schema": true,
"supports_tool_choice": true,
- "supports_vision": true
+ "supports_vision": true,
+ "bedrock_converse_supports_strict_tools": false
},
"global.anthropic.claude-haiku-4-5-20251001-v1:0": {
"cache_creation_input_token_cost": 1.25e-06,
@@ -33169,7 +33173,8 @@
"supports_reasoning": true,
"supports_response_schema": true,
"supports_tool_choice": true,
- "supports_vision": true
+ "supports_vision": true,
+ "bedrock_converse_supports_strict_tools": false
},
"us.deepseek.r1-v1:0": {
"input_cost_per_token": 1.35e-06,
diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json
index 006c04f5ecb..851f41dd98e 100644
--- a/model_prices_and_context_window.json
+++ b/model_prices_and_context_window.json
@@ -2093,7 +2093,8 @@
"supports_reasoning": true,
"supports_response_schema": true,
"supports_tool_choice": true,
- "supports_vision": true
+ "supports_vision": true,
+ "bedrock_converse_supports_strict_tools": false
},
"anthropic.claude-sonnet-4-5-20250929-v1:0": {
"cache_creation_input_token_cost": 3.75e-06,
@@ -2420,7 +2421,8 @@
"supports_reasoning": true,
"supports_response_schema": true,
"supports_tool_choice": true,
- "supports_vision": true
+ "supports_vision": true,
+ "bedrock_converse_supports_strict_tools": false
},
"assemblyai/best": {
"input_cost_per_second": 3.333e-05,
@@ -14824,7 +14826,8 @@
"supports_reasoning": true,
"supports_response_schema": true,
"supports_tool_choice": true,
- "supports_vision": true
+ "supports_vision": true,
+ "bedrock_converse_supports_strict_tools": false
},
"eu.anthropic.claude-sonnet-4-5-20250929-v1:0": {
"cache_creation_input_token_cost": 4.125e-06,
@@ -20243,7 +20246,8 @@
"supports_reasoning": true,
"supports_response_schema": true,
"supports_tool_choice": true,
- "supports_vision": true
+ "supports_vision": true,
+ "bedrock_converse_supports_strict_tools": false
},
"global.anthropic.claude-haiku-4-5-20251001-v1:0": {
"cache_creation_input_token_cost": 1.25e-06,
@@ -33343,7 +33347,8 @@
"supports_reasoning": true,
"supports_response_schema": true,
"supports_tool_choice": true,
- "supports_vision": true
+ "supports_vision": true,
+ "bedrock_converse_supports_strict_tools": false
},
"us.deepseek.r1-v1:0": {
"input_cost_per_token": 1.35e-06,
diff --git a/tests/local_testing/test_embedding.py b/tests/local_testing/test_embedding.py
index 14626aa8e45..f4c61e99547 100644
--- a/tests/local_testing/test_embedding.py
+++ b/tests/local_testing/test_embedding.py
@@ -765,6 +765,10 @@ def test_fireworks_embeddings():
pass
except litellm.InternalServerError as e:
pass
+ except litellm.APIError as e:
+ if "suspended" in str(e):
+ pytest.skip(f"Fireworks account suspended: {e}")
+ pytest.fail(f"Error occurred: {e}")
except Exception as e:
pytest.fail(f"Error occurred: {e}")
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.py
index 26096c49468..791982fc3dc 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
@@ -1,8 +1,8 @@
"""Regression tests for Bedrock Converse ``toolSpec.strict`` forwarding.
-Bedrock Converse routes Claude Opus 4.7/4.8 through an Anthropic-compatible
-validator that rejects ``toolSpec.strict`` even though Anthropic's native API
-accepts ``strict`` as a top-level tool field for the same models. See
+Bedrock Converse routes Claude Opus 4.7/4.8 and Claude Sonnet 4 through an
+Anthropic-compatible validator that rejects ``toolSpec.strict`` even though
+Anthropic's native API accepts ``strict`` as a top-level tool field. See
BerriAI/litellm#31582.
"""
@@ -11,7 +11,6 @@ import pytest
from litellm.litellm_core_utils.prompt_templates.factory import _bedrock_tools_pt
from litellm.llms.bedrock.common_utils import bedrock_converse_supports_strict_tools
-
_STRICT_TOOL = [
{
"type": "function",
@@ -43,12 +42,26 @@ _STRICT_TOOL = [
"anthropic.claude-opus-4-7-v1:0",
"bedrock/eu.anthropic.claude-opus-4-8-v1:0",
"bedrock/global.anthropic.claude-opus-4-7",
+ # Sonnet 4 also rejects toolSpec.strict on Bedrock Converse
+ "anthropic.claude-sonnet-4-20250514-v1:0",
+ "bedrock/global.anthropic.claude-sonnet-4-20250514-v1:0",
+ "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",
],
)
-def test_bedrock_tools_pt_strict_dropped_for_opus_47_48(model_id: str) -> None:
- """Opus 4.7/4.8 on Bedrock Converse reject toolSpec.strict — must be dropped."""
+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."""
result = _bedrock_tools_pt(_STRICT_TOOL, model=model_id)
- assert "strict" not in result[0]["toolSpec"], f"strict leaked into toolSpec for {model_id}: {result[0]['toolSpec']}"
+ tool_spec = result[0]["toolSpec"]
+ assert (
+ "strict" not in tool_spec
+ ), f"strict leaked into toolSpec for {model_id}: {tool_spec}"
+ assert (
+ "additionalProperties" not in tool_spec["inputSchema"]["json"]
+ ), f"additionalProperties leaked into toolSpec for {model_id}: {tool_spec}"
@pytest.mark.parametrize(
@@ -63,7 +76,9 @@ def test_bedrock_tools_pt_strict_dropped_for_opus_47_48(model_id: str) -> None:
def test_bedrock_tools_pt_strict_kept_for_other_anthropic(model_id: str) -> None:
"""Sonnet 4.5/4.6 and Opus <=4.6 accept toolSpec.strict — keep forwarding it."""
result = _bedrock_tools_pt(_STRICT_TOOL, model=model_id)
- assert result[0]["toolSpec"]["strict"] is True, f"strict missing for {model_id}: {result[0]['toolSpec']}"
+ assert (
+ result[0]["toolSpec"]["strict"] is True
+ ), f"strict missing for {model_id}: {result[0]['toolSpec']}"
@pytest.mark.parametrize(
@@ -81,12 +96,39 @@ def test_bedrock_tools_pt_strict_dropped_for_non_anthropic(model_id: str) -> Non
def test_bedrock_converse_supports_strict_tools_helper() -> None:
"""Direct check for the gate helper used by factory.py."""
- assert bedrock_converse_supports_strict_tools("bedrock/us.anthropic.claude-opus-4-7") is False
- assert bedrock_converse_supports_strict_tools("bedrock/us.anthropic.claude-opus-4-8") is False
- assert bedrock_converse_supports_strict_tools("anthropic.claude-sonnet-4-5-20250929-v1:0") is True
- assert bedrock_converse_supports_strict_tools("bedrock/us.anthropic.claude-opus-4-6") is True
+ assert (
+ bedrock_converse_supports_strict_tools("bedrock/us.anthropic.claude-opus-4-7")
+ is False
+ )
+ assert (
+ bedrock_converse_supports_strict_tools("bedrock/us.anthropic.claude-opus-4-8")
+ is False
+ )
+ assert (
+ bedrock_converse_supports_strict_tools(
+ "anthropic.claude-sonnet-4-5-20250929-v1:0"
+ )
+ is True
+ )
+ assert (
+ bedrock_converse_supports_strict_tools("bedrock/us.anthropic.claude-opus-4-6")
+ is True
+ )
assert bedrock_converse_supports_strict_tools("us.amazon.nova-micro-v1:0") is False
assert bedrock_converse_supports_strict_tools("") is False
+ # Sonnet 4 also rejects strict on Bedrock Converse
+ assert (
+ bedrock_converse_supports_strict_tools(
+ "anthropic.claude-sonnet-4-20250514-v1:0"
+ )
+ is False
+ )
+ assert (
+ bedrock_converse_supports_strict_tools(
+ "bedrock/global.anthropic.claude-sonnet-4-20250514-v1:0"
+ )
+ is False
+ )
@pytest.mark.parametrize(
@@ -96,6 +138,11 @@ def test_bedrock_converse_supports_strict_tools_helper() -> None:
"us.anthropic.claude-opus-4-7",
"anthropic.claude-opus-4-8",
"us.anthropic.claude-opus-4-8",
+ "anthropic.claude-sonnet-4-20250514-v1:0",
+ "global.anthropic.claude-sonnet-4-20250514-v1:0",
+ "us.anthropic.claude-sonnet-4-20250514-v1:0",
+ "eu.anthropic.claude-sonnet-4-20250514-v1:0",
+ "apac.anthropic.claude-sonnet-4-20250514-v1:0",
],
)
def test_strict_tools_flag_set_in_model_cost_map(cost_map_key: str) -> None: