From 26f1a3bc7d21c1da93a23cd10514f3c1c9c22503 Mon Sep 17 00:00:00 2001 From: le-shi <13051960278@163.com> Date: Thu, 6 Aug 2026 21:42:11 +0800 Subject: [PATCH] fix(anthropic): use native structured output for Sonnet 5 --- ...odel_prices_and_context_window_backup.json | 1 + model_prices_and_context_window.json | 1 + .../test_anthropic_chat_transformation.py | 25 +++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json index d954e33da9c..8858bdc9166 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -11680,6 +11680,7 @@ "supports_prompt_caching": true, "supports_reasoning": true, "supports_response_schema": true, + "supports_native_structured_output": true, "supports_sampling_params": false, "supports_tool_choice": true, "supports_vision": true, diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json index 8982b4f2565..443328c6f62 100644 --- a/model_prices_and_context_window.json +++ b/model_prices_and_context_window.json @@ -11680,6 +11680,7 @@ "supports_prompt_caching": true, "supports_reasoning": true, "supports_response_schema": true, + "supports_native_structured_output": true, "supports_sampling_params": false, "supports_tool_choice": true, "supports_vision": true, diff --git a/tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py b/tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py index 231d3b48754..e5970ca4ac0 100644 --- a/tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py +++ b/tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py @@ -1042,6 +1042,31 @@ def test_native_structured_output_uses_bundled_capability_when_remote_map_lags( assert "tools" not in optional_params +def test_claude_sonnet_5_uses_native_structured_output() -> None: + optional_params = AnthropicConfig().map_openai_params( + non_default_params={ + "response_format": { + "type": "json_schema", + "json_schema": { + "name": "answer", + "schema": { + "type": "object", + "properties": {"answer": {"type": "string"}}, + "required": ["answer"], + }, + }, + } + }, + optional_params={}, + model="claude-sonnet-5", + drop_params=False, + ) + + assert "output_format" in optional_params + assert "tools" not in optional_params + assert "tool_choice" not in optional_params + + def test_non_structured_output_model_uses_tool_workaround(): """ Test that models NOT in the native structured output list still use the