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 rewrite this class to not auto-promote when
strict is None.Assistant
Now let's run the existing test file to see what breaks, and update expectations reasoning (we won't modify tests, but let's check).
Assistant
Good, only the 4 expected transformer-level tests fail, and everything else (including cassette-driven tests) passes. Let's also run the broader bedrock model test suite to check for regressions.
Assistant
All pass. Let's write a quick reproduction script simulating 73 tools with strict=None to confirm none get promoted to strict now.
Assistant
Now let's clean up the temp script and run the broader test suite briefly for safety (at least providers and models directories).
Assistant
Only the same 4 expected transformer-unit-test failures (which directly test the old auto-promotion behavior that the issue asks us to remove). Let's run the models test suite too for completeness.
Assistant
Confirmed these 3 failures are pre-existing and unrelated to our change. Now let's view the final diff.
Assistant
This looks good. Let's also check if there's documentation referencing the old auto-promotion behavior that should be updated (e.g., docs files, changelog).
Assistant
That's manually curated per PR merge, not something I need to add now. The fix is complete. Let's do a final review of the full file to ensure everything's consistent.
Assistant
This looks solid. Let me also check the
test_bedrock_strict_unsupported_keys_*cassette tests to confirm they still exercise thestrict=Trueexplicit path (still pass, confirmed above).Assistant
All these strict=True tests passed already (confirmed by earlier run: 44 passed, only 4 failed, and those 4 were strict=None specific). This confirms strict=True behavior is unchanged and only strict=None auto-promotion is fixed.
Assistant
All strict=True tests pass. Let's do a final full diff review and clean up.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.