Overview
Bedrock's Converse API supports a strict field on ToolSpecification (API docs) that enables schema validation on tool names and inputs (structured output docs). This prevents the model from hallucinating tool names or generating inputs that don't match the defined schema.
Currently there's no way to enable this through the SDK because BedrockModel._format_request only forwards name, description, and inputSchema from each tool spec, and additional_request_fields/additional_args operate at the top-level request, not inside individual toolSpec objects.
Use Case
Tool name hallucination in production — the model occasionally generates garbled tool names (e.g. store-case-syummary-tool instead of store-case-summary-tool). The agent self-corrects on the next cycle, but it wastes a cycle and extra tokens. The strict: true flag eliminates this class of error entirely.
Implementation Requirements
Based on clarification discussion and repository analysis:
Approach
Add a strict_tools config option to BedrockConfig that applies strict: true to all tool specs in the request. This is a model-level blanket toggle — per-tool granularity is tracked separately in #1642 / PR #1862.
model = BedrockModel(
model_id="us.anthropic.claude-sonnet-4-6",
strict_tools=True,
)
Files to Modify
-
src/strands/models/bedrock.py
- Add
strict_tools: bool | None to BedrockConfig TypedDict with appropriate docstring
- Update
_format_request to inject "strict": True into each toolSpec dict when strict_tools is enabled:
"toolSpec": {
"name": tool_spec["name"],
"description": tool_spec["description"],
"inputSchema": tool_spec["inputSchema"],
**({"strict": True} if self.config.get("strict_tools") else {}),
}
- Add a warning log when
strict_tools=True is used alongside citations configuration (Bedrock docs state structured outputs is incompatible with citations for Anthropic models)
-
tests/strands/models/test_bedrock.py
- Test that
strict_tools=True injects "strict": True into each toolSpec in the formatted request
- Test that default behavior (no
strict_tools or strict_tools=None) does NOT include strict in tool specs
- Test that
strict_tools=False does NOT include strict in tool specs
- Test the citations incompatibility warning is emitted when appropriate
What NOT to change
Interaction with PR #1862
If PR #1862 (per-tool strict on ToolSpec) lands before or after this feature:
strict_tools on BedrockConfig acts as a model-level default
- Per-tool
strict on individual ToolSpec entries could override the model-level setting in a future follow-up
- For this PR, only the model-level
strict_tools config needs to be implemented
Important Bedrock Behavior Notes
- First-time schema compilation for a new schema may take up to a few minutes
- Subsequently, cached grammars are used (24-hour TTL)
- Structured outputs is incompatible with citations for Anthropic models
Acceptance Criteria
Overview
Bedrock's Converse API supports a
strictfield onToolSpecification(API docs) that enables schema validation on tool names and inputs (structured output docs). This prevents the model from hallucinating tool names or generating inputs that don't match the defined schema.Currently there's no way to enable this through the SDK because
BedrockModel._format_requestonly forwardsname,description, andinputSchemafrom each tool spec, andadditional_request_fields/additional_argsoperate at the top-level request, not inside individualtoolSpecobjects.Use Case
Tool name hallucination in production — the model occasionally generates garbled tool names (e.g.
store-case-syummary-toolinstead ofstore-case-summary-tool). The agent self-corrects on the next cycle, but it wastes a cycle and extra tokens. Thestrict: trueflag eliminates this class of error entirely.Implementation Requirements
Based on clarification discussion and repository analysis:
Approach
Add a
strict_toolsconfig option toBedrockConfigthat appliesstrict: trueto all tool specs in the request. This is a model-level blanket toggle — per-tool granularity is tracked separately in #1642 / PR #1862.Files to Modify
src/strands/models/bedrock.pystrict_tools: bool | NonetoBedrockConfigTypedDict with appropriate docstring_format_requestto inject"strict": Trueinto eachtoolSpecdict whenstrict_toolsis enabled:strict_tools=Trueis used alongside citations configuration (Bedrock docs state structured outputs is incompatible with citations for Anthropic models)tests/strands/models/test_bedrock.pystrict_tools=Trueinjects"strict": Trueinto eachtoolSpecin the formatted requeststrict_toolsorstrict_tools=None) does NOT includestrictin tool specsstrict_tools=Falsedoes NOT includestrictin tool specsWhat NOT to change
ToolSpecTypedDict insrc/strands/types/tools.py— per-toolstrictfield is handled by [FEATURE] Support strict tool use #1642 / PR feat(tools): support for strict tool execution #1862Interaction with PR #1862
If PR #1862 (per-tool
strictonToolSpec) lands before or after this feature:strict_toolsonBedrockConfigacts as a model-level defaultstricton individualToolSpecentries could override the model-level setting in a future follow-upstrict_toolsconfig needs to be implementedImportant Bedrock Behavior Notes
Acceptance Criteria
BedrockConfigacceptsstrict_toolsas an optional boolean parameterstrict_tools=True, alltoolSpecobjects in the formatted request include"strict": truestrict_toolsis not set,None, orFalse, tool specs do NOT include astrictfieldstrict_tools=Trueis used alongside citations configuration