fix(anthropic): upgrade legacy thinking after the Bedrock Invoke and Vertex structured-output stub swap

This commit is contained in:
mateo-berri 2026-09-02 13:37:14 -07:00
parent 9bd870d47a
commit fd4b15fae6
4 changed files with 55 additions and 0 deletions

View file

@ -107,6 +107,10 @@ class AmazonAnthropicClaudeConfig(AmazonInvokeConfig, AnthropicConfig):
# Restore original model name
model = original_model
AnthropicModelInfo.translate_legacy_thinking_for_adaptive_model(
model=original_model, optional_params=optional_params, custom_llm_provider="bedrock"
)
# The stub model hides the original model from the parent's forced-tool-use backstop
response_format_tool_choice: Final = optional_params.get("tool_choice")
if (

View file

@ -177,6 +177,10 @@ class VertexAIAnthropicConfig(AnthropicConfig):
# Restore original model name for any other processing
model = original_model
AnthropicModelInfo.translate_legacy_thinking_for_adaptive_model(
model=original_model, optional_params=optional_params, custom_llm_provider="vertex_ai"
)
return optional_params
def transform_response(

View file

@ -671,3 +671,27 @@ def test_bedrock_chat_invoke_fable_5_1_response_format_avoids_forced_tool_choice
assert "output_format" not in result
assert "tools" in result
assert "tool_choice" not in result
@pytest.mark.parametrize("model", ["us.anthropic.claude-sonnet-5", "us.anthropic.claude-fable-5-1"])
def test_bedrock_chat_invoke_tool_based_response_format_still_upgrades_legacy_thinking(local_model_cost_map, model):
result = AmazonAnthropicClaudeConfig().map_openai_params(
non_default_params={
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "test_schema",
"schema": {"type": "object", "properties": {"result": {"type": "string"}}},
},
},
"thinking": {"type": "enabled", "budget_tokens": 4096},
"max_tokens": 8192,
},
optional_params={},
model=model,
drop_params=False,
)
assert "tools" in result
assert result["thinking"] == {"type": "adaptive"}
assert result["output_config"] == {"effort": "high"}

View file

@ -752,3 +752,26 @@ def test_vertex_ai_fable_5_1_response_format_uses_native_output_format(local_mod
assert "output_format" in result_params
assert "tool_choice" not in result_params
assert "tools" not in result_params
def test_vertex_ai_anthropic_tool_based_response_format_still_upgrades_legacy_thinking(local_model_cost_map):
result_params = VertexAIAnthropicConfig().map_openai_params(
non_default_params={
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "test_schema",
"schema": {"type": "object", "properties": {"result": {"type": "string"}}},
},
},
"thinking": {"type": "enabled", "budget_tokens": 4096},
"max_tokens": 8192,
},
optional_params={},
model="claude-opus-4-8",
drop_params=False,
)
assert "tools" in result_params
assert result_params["thinking"] == {"type": "adaptive"}
assert result_params["output_config"] == {"effort": "high"}