Skip to content

fix(bedrock): fall back to toolChoice.auto when model does not support toolChoice.any#2075

Open
Zelys-DFKH wants to merge 1 commit intostrands-agents:mainfrom
Zelys-DFKH:fix/bedrock-tool-choice-any-fallback
Open

fix(bedrock): fall back to toolChoice.auto when model does not support toolChoice.any#2075
Zelys-DFKH wants to merge 1 commit intostrands-agents:mainfrom
Zelys-DFKH:fix/bedrock-tool-choice-any-fallback

Conversation

@Zelys-DFKH
Copy link
Copy Markdown

Description

When the structured output context enters forced mode it sets tool_choice = {"any": {}} to
require the model to call the structured output tool. BedrockModel._format_request forwarded
this directly as toolConfig.toolChoice.any to the Bedrock Converse API.

The Bedrock Converse API only supports toolChoice.any for Anthropic Claude models. All other
model families — Meta Llama, Amazon Titan/Nova, Mistral, Cohere — reject it with a
ValidationException: This model doesn't support the toolConfig.toolChoice.any field.

The fix adds a _resolve_tool_choice helper to BedrockModel that detects whether the active
model supports toolChoice.any and falls back to toolChoice.auto when it does not. The model
list follows the existing _MODELS_INCLUDE_STATUS pattern already used in the file.

Related Issues

Fixes #1241

Documentation PR

N/A

Type of Change

Bug fix

Testing

How have you tested the change?

  • I ran hatch run prepare
  • Added test_format_request_tool_choice_any using a Claude model ID to verify toolChoice.any passes through unchanged
  • Added test_format_request_tool_choice_any_falls_back_for_unsupported_models using a non-Claude model ID to verify fallback to toolChoice.auto
  • All 2489 existing tests pass

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

…t toolChoice.any

The Bedrock Converse API only supports toolChoice.any for Anthropic Claude
models. Other families (Meta Llama, Amazon Titan/Nova, Mistral, Cohere)
reject it with ValidationException. When structured output enters forced
mode it sends toolChoice.any, causing crashes on non-Claude Bedrock models.

Add _resolve_tool_choice to BedrockModel that detects support via
_MODELS_SUPPORT_TOOL_CHOICE_ANY and falls back to toolChoice.auto with a
warning log for unsupported models. Follows the existing _MODELS_INCLUDE_STATUS
pattern in the file.

Fixes strands-agents#1241
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

1 participant