[FEATURE] Support `strict: true` on tool definitions in BedrockModel
TS version of https://github.com/strands-agents/sdk-python/issues/2210
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 | NonetoBedrockConfigTypedDict with appropriate docstring - Update
_format_requestto inject"strict": Trueinto eachtoolSpecdict whenstrict_toolsis 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=Trueis used alongside citations configuration (Bedrock docs state structured outputs is incompatible with citations for Anthropic models)
- Add
-
tests/strands/models/test_bedrock.py- Test that
strict_tools=Trueinjects"strict": Trueinto eachtoolSpecin the formatted request - Test that default behavior (no
strict_toolsorstrict_tools=None) does NOT includestrictin tool specs - Test that
strict_tools=Falsedoes NOT includestrictin tool specs - Test the citations incompatibility warning is emitted when appropriate
- Test that
What NOT to change
- Do NOT modify
ToolSpecTypedDict insrc/strands/types/tools.py— per-toolstrictfield is handled by #1642 / PR #1862 - No GitHub workflow changes needed
- No changes to other model providers — this is Bedrock-specific
Interaction with PR #1862
If PR #1862 (per-tool strict on ToolSpec) lands before or after this feature:
strict_toolsonBedrockConfigacts as a model-level default- Per-tool
stricton individualToolSpecentries could override the model-level setting in a future follow-up - For this PR, only the model-level
strict_toolsconfig 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
- [ ]
BedrockConfigacceptsstrict_toolsas an optional boolean parameter - [ ] When
strict_tools=True, alltoolSpecobjects in the formatted request include"strict": true - [ ] When
strict_toolsis not set,None, orFalse, tool specs do NOT include astrictfield - [ ] A warning is logged when
strict_tools=Trueis used alongside citations configuration - [ ] Unit tests cover all scenarios (enabled, disabled, default, citations warning)
- [ ] Existing tests continue to pass
- [ ] Code follows repository conventions (type annotations, Google-style docstrings, structured logging)