ISSUE DESCRIPTION Bedrock: strict=None auto-promotes many tools to strict and hits…
- User
ISSUE DESCRIPTION
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):ValidationException: 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
Now let's check existing tests to understand what behavior is expected/tested, particularly around
is_strict_compatibleand auto-promotion.Assistant
Now let's implement the fix, mirroring Anthropic's approach.
Assistant
Now let's verify the diff and check the models/bedrock.py usage for
bedrock_supports_strict_tool_definitionandf.strict, to confirm behavior with explicit strict=True still works.Assistant
Now let's write a quick reproduction script to validate the fix resolves the issue.
Assistant
This confirms the fix:
strict=Noneno longer auto-promotes to strict-compatible. Now let's run the full test suite for bedrock provider/model to see impacts.Assistant
All model tests pass. Let's also check for VCR cassette tests referencing bedrock strict tools (integration tests) that might be affected.
Assistant
Now let's run the full test suite for bedrock related pieces once more, and also check ruff/pyright for lint issues.
Assistant
Now let's write a quick reproduction of the exact issue scenario with 73 tools to ensure the fix resolves it end-to-end at the
_customize_tool_deflevel.Assistant
This confirms the fix resolves the exact issue scenario. Let's also verify explicit
strict=Truestill works, and NativeOutput forced strict still works.Assistant
All expected behaviors work correctly. Let's run the broader test suite once more to check nothing else broke (models bedrock tests, providers tests, and a general sanity check).
Assistant
No documentation changes needed there (unrelated). Let's check the changelog / release notes convention to see if we should add an entry.
Assistant
That's auto-generated from PR links, not something I need to edit manually. Now let's review final diff and run broader test suite for safety.
Assistant
This is a clean, minimal, and correct fix mirroring the Anthropic approach. Now let's run the broader test suite quickly to ensure nothing else in the repo references this transformer's old behavior (e.g., integration/vcr tests).
Assistant
Let's run this specific test file with vcr cassettes to make sure nothing breaks (these directly call
_map_tool_definitionat model level, usingToolDefinitiondirectly, not through agent-level_customize_tool_def, so should be unaffected).Assistant
All 20 pass. Now let's check
Agent-level integration tests that useagent.tool_plainwithout explicit strict (i.e., real reproduction of the issue at agent level with actualcustomize_request_parameters).Assistant
Only those 4 known tests (encoding old buggy behavior) fail; 387 pass. This confirms the fix is solid and doesn't break other functionality.
Assistant
Checklist review
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.