Repository navigation
Conversation
…tool choice Claude Opus 5.5 and Sonnet 5.5 reject tool_choice any/tool, so the forced structured output retry failed with a raw ValidationException. BedrockModel and AnthropicModel now detect that rejection, resend the request once with auto tool choice, and remember the model so later requests send auto up front. If the model still skips the tool, the existing check raises StructuredOutputException. Fixes strands-agents#5156 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human Overview
Description
Claude Opus 5.5 and Sonnet 5.5 reject forced tool choice (
tool_choiceany/tool), so when one of them answers in prose instead of calling the structured output tool, the forced retry fails with a rawValidationExceptionrather than producing structured output orStructuredOutputException. The deprecatedagent.structured_output()path fails the same way.BedrockModelandAnthropicModelnow recognize that specific rejection, resend the request once withautoinside the same model call, and remember the model for the process so later requests sendautoup front. Capability is learned from the provider's error rather than a model list, following the existing CountTokens cache. Models that accept forced tool choice are unaffected, and if the model still skips the tool, the existing check raisesStructuredOutputException.This is an interim fix:
automakes the tool call likely, not guaranteed. A follow-up uses native structured output on these models to restore the guarantee.Related Issues
Fixes #5156
Documentation PR
No docs change needed for this behavior fix.
Type of Change
Bug fix
Testing
Ran the models, event loop, structured output and agent unit suites. Live on Bedrock: Opus 5.5, Sonnet 5.5 and Haiku 5.5 through both
BedrockModelandAnthropicModel(viaAsyncAnthropicBedrock), with an extra tool in the agent; all produced structured output, and debug logs confirmed the fallback ran only on the 5.5 models and only on the first call. The deprecated path succeeded on all three, and a prompt telling the model never to call tools ended inStructuredOutputException. Not verified: Fable 5.1 and a direct Anthropic API key.hatch run prepareAdditional Details
Extended context (optional)
Raw Converse probe of
tool_choiceper model:autoany/tooltool_choice: type "tool" and "any" are not supported for this model.The rejected request fails in validation (~250 ms, no token usage), so the fallback costs one fast request per model per process.
Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
🤖 Generated with Claude Code