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
Let me start by exploring the repository structure to understand the codebase
Assistant
Let me find
_customize_tool_def():Assistant
let me check the Anthropic provider code to see how it handles this:
Assistant
me find the base JsonSchemaTransformer:
Assistant
Let me search for the Bedrock transformer:
Assistant
check the existing tests for Bedrock:
Assistant
Let me check the existing test cases that will need to change:
Assistant
check the git log to see the history of these tests:
Assistant
Let me look at the full BedrockJsonSchemaTransformer code:
Assistant
me look at the existing tests that test
is_strict_compatibleforstrict=None:Assistant
Let me check the git history of bedrock.py:
Assistant
Let me look at the bedrock.py file before PR #4237 was applied:
Assistant
Let me now create a reproduction script first to confirm the bug:
Assistant
Now let me implement the fix:
Assistant
let me implement the fix:
Assistant
have a duplicate. Let me fix this:
Assistant
revert and re-apply:
Assistant
Now let me carefully apply the fix step by step. First, update the docstring:
Assistant
Now let me update the
transform()method to remove the now-redundantstrict is Nonecases and add awalk()override:Assistant
let me verify the fix works:
Assistant
Let me update the reproduction script:
Assistant
Let me test more edge cases:
Assistant
All edge cases pass. Now let me also test that the model still works correctly with multiple tools:
Assistant
Let me check how the profile is merged:
Assistant
OK, so
bedrock_supports_strict_tool_definitionis set by the bedrock provider. Let me update my test to use the bedrock provider:Assistant
The fix works perfectly. Let me also verify that explicitly setting
strict=Truestill works:Assistant
Now let me run the existing tests to see what fails:
Assistant
Let me look at the failing tests:
Assistant
Let me look at the test at line 861:
Assistant
4 failing tests are all testing the OLD buggy behavior (auto-promotion). Per the instructions, I should ignore these. Let me also run the model tests:
Assistant
All 20 model tests pass. Let me also run the strict tool calls tests:
Assistant
Let me also verify which tests are failing and confirm they're testing buggy behavior:
Assistant
me run the reproduction script again with my fix:
Assistant
Let me check for other tests that might be affected:
Assistant
Let me verify these failures are pre-existing (not caused by my fix):
Assistant
Yes, these failures are pre-existing and not caused by my fix. Let me restore my changes:
Assistant
Let me run the broader test suite to make sure I haven't broken anything:
Assistant
Only the 4 tests that test the buggy behavior fail. All other tests pass.
Let me also check the unit tests:
Assistant
Let me check the cassettes:
Assistant
Let me look at the final state of the bedrock.py file:
Assistant
Let me run the comprehensive edge case tests:
Assistant
Let me clean up the temporary scripts:
Assistant
Let me run all bedrock-related tests one more time to verify everything works:
Assistant
Let me also write a final reproduction script to confirm the issue is fixed:
Assistant
All three test cases pass. Let me clean up:
Assistant
Let me also check the Anthropic tests still pass to make sure I haven't impacted anything else:
Assistant
Let me do a final review of my changes:
Assistant
Let me also do a final sanity check to ensure the bedrock.py fix is complete:
Assistant
All sanity checks pass. Let me also verify the test suite once more:
Assistant
All 20 model tests pass. The fix is complete.
Let me also check that no other tests are affected by running the broader test suite:
Assistant
Let me verify the pre-existing failures were already failing before my fix:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.