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 view the relevant strict=None tests fully, and the transform() function again to plan the edit.
Assistant
No override of
walk()currently. Let's now edit the transform method and add walk override, updating docstring.Assistant
Now let's run relevant tests to see what breaks and fix any that test old auto-promote behavior (allowed to leave failing per instructions, but let's check overall model behavior tests too).
Assistant
These 4 failing tests are exactly testing the old auto-promote behavior we intentionally removed - expected per issue. Let's view full test file diffs to confirm nothing else is affected, and check the model-level test file too.
Assistant
Good, these are all consistent with the expected fix. Now let's check test_bedrock.py model-level tests (in tests/models/test_bedrock.py) for anything referencing strict tool count/related cassettes.
Assistant
No strict-related tests there. Now let's run the full bedrock model test suite to make sure nothing else broke.
Assistant
All pass. Now let's write a quick reproduction script simulating 73 tools with strict=None to confirm none get promoted to strict now.
Assistant
Fix confirmed. Now let's run full test suite for providers directory and check anything else referencing bedrock transformer (e.g. in models/init.py tests, or docs).
Assistant
Only the same 4 expected failures (testing the old regression behavior). All others pass. Let's clean up temp files.
Assistant
Let's view the final diff for review.
Assistant
This looks clean and correctly resolves the issue.
Assistant
This confirms the bug reproduced (73/73 before fix, 0/73 after fix). Let's clean up temp file.
Assistant
Now let's run the broader test suite relevant to models to ensure nothing else broke (a broader sanity check).
Assistant
All expected. Now 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.