Bedrock: strict=None auto-promotes many tools to strict and hits provider limit Initial…
- User
Bedrock:
strict=Noneauto-promotes many tools to strict and hits provider limitInitial Checks
- I'm using the latest version of Pydantic AI
- I've searched for my issue in the issue tracker before opening this issue
Description
Summary
pydantic-ai-slim==1.101.0can now fail Bedrock Claude requests with many tools becauseToolDefinition.strict=Noneis inferred asstrict=Truefor simple schemas. Bedrock/Claude rejects requests with more than 20 strict tools (source):textValidationException: Too many strict tools (73). The maximum number of strict tools supported is 20.This is a behavior regression for callers that did not explicitly opt into strict tool definitions.
What happened
A production agent sends 73 function tools to Bedrock. Before 1.101.0 these tools were sent as normal, non-strict Bedrock tools.
After 1.101.0, these tool definitions have strict=None, and the Bedrock schema transformer infers many/all simple schemas as strict-compatible. _customize_tool_def() then replaces strict=None with strict=True, and BedrockConverseModel._map_tool_definition() sends toolSpec.strict = true. Bedrock rejects the request because it only supports 20 strict tools.
Disclosure: I authored #4237 ✋ . My tests and vcr cassettes didn't account for the >20-tool case.
Expected behavior
For Bedrock, strict=None should not silently turn large toolsets into strict toolsets that violate Bedrock limits.
Possible fixes:
Similar to Anthropic, do not auto-promote Bedrock tool definitions from strict=None to strict=True; only send toolSpec.strict = true when the user explicitly set strict=True.
Workaround
Callers can explicitly set strict=False on Bedrock tool definitions, but this requires every application with larger Bedrock toolsets to discover and patch the behavior.
- Assistant
Let me look at the existing tests and the base
customize_request_parametersflow. - Assistant
Now let me implement. First check imports in
models/bedrock.py: - Assistant
Now add the
customize_request_parametersoverride inBedrockConverseModel: - Assistant
Now update the transformer docstring in
providers/bedrock.py: - Assistant
Check
ModelRequestParametersfields for the tests: - Assistant
Now add tests. I'll insert them after the
_map_tool_definitionunit tests: - Assistant
All 11 pass. Now typecheck the changed files:
- Assistant
The new code paths (lines ~501-531) are fully covered — the missing-lines list jumps from 477-484 straight to 590-604. Final verification:
- Assistant
Done. The fix resolves the regression from strict tool auto-promotion while preserving its benefit for the common case.
Approach
Rather than removing auto-promotion entirely (the issue's suggested Anthropic-style fix, which would take away schema-adherence benefits from every Bedrock user with ≤20 tools), I applied the codebase's established pattern of "fail fast on explicit user config conflicts; gracefully fallback on internal/auto setting conflicts": auto-promotion is now capped at Bedrock's 20-strict-tool limit.
Changes
pydantic_ai_slim/pydantic_ai/models/bedrock.py- Added
_MAX_STRICT_TOOLS = 20with a comment citing Bedrock's and the documented limit.
- Added
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.