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):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 start by exploring the repository structure to understand the codebase.
Assistant
Let me explore the structure related to Bedrock and the issue:
Assistant
Let me find the
_map_tool_definitionmethod and_customize_tool_defto understand the issue:Assistant
Now let me look at how
_map_tool_definitionis implemented inbedrock.py:Assistant
Now let me search for
_customize_tool_defmentioned in the issue:Assistant
Now let me look at the Anthropic provider's approach for comparison:
Assistant
Let me look at the JsonSchemaTransformer base class:
Assistant
Let me look at the OpenAI provider:
Assistant
Now I understand the issue clearly. Let me look at the existing tests for the Bedrock strict tool behavior:
Assistant
Let me check the relevant PR and changes to understand the flow:
Assistant
Let me look at the existing tests to understand the full flow:
Assistant
Let me check the existing tests for the BedrockJsonSchemaTransformer:
Assistant
Let me look at the Anthropic transform method:
Assistant
Now let me write a reproduce script to confirm the issue:
Assistant
I've confirmed the issue. Now let me also reproduce the exact flow through the model:
Assistant
Let me also check what Anthropic does for comparison:
Assistant
Now I have a clear understanding. Let me implement the fix to make Bedrock behave like Anthropic:
Assistant
Now let me implement the fix:
Assistant
The file content shown might be slightly different. Let me check the exact content.
Assistant
Let me try a different approach - using sed to do the replacement:
Assistant
Now let me run the reproduce script to confirm the fix:
Assistant
Let me write more comprehensive tests to verify edge cases:
Assistant
The fix is working -
strict=Noneis now not auto-promoted. The output isFalse(notNone) because_customize_tool_defsetsstrict=is_strict_compatiblewhen input isNone. This is the correct behavior. Let me update my test:Assistant
All tests pass. Now let me also test the integration with the actual Bedrock model to make sure the wire format is correct:
Assistant
Now let me run the existing Bedrock tests to see which ones are affected:
Assistant
The existing test was added by the author of the regression PR and tests the wrong behavior. According to the instructions, I can ignore this test failure. Let me continue running to see all the affected tests:
Assistant
Let me also run the Bedrock model tests:
Assistant
All Bedrock model tests pass. Let me also check if there are any other tests that might be affected:
Assistant
Only 4 tests fail, all of them testing the old (regression) behavior. These tests need to be updated to reflect the new (correct) behavior. According to the instructions, I can ignore these test failures.
Let me also run the Anthropic tests to make sure my fix doesn't affect them:
Assistant
Let me also run a broader test suite to make sure nothing else is affected:
Assistant
Let me check if these failures are related to my changes:
Assistant
Let me verify these failures are unrelated to my changes by checking the main branch:
Assistant
The 3 failures are pre-existing and unrelated to my changes. Let me also check the diff:
Assistant
Let me also check that the
prepare_requestmethod still works correctly for output objects:Assistant
Let me also test the integration with NativeOutput:
Assistant
Let me also test a mix of strict=True and strict=None tools:
Assistant
Let me also check if there are any other places that might reference the old behavior:
Assistant
Let me also check the existing tests for the strict unsupported keys:
Assistant
All
strict=Truetests pass. Let me also run thestrict_falsetests:Assistant
All
strict=Falsetests pass. Let me also verify the specific tests that were failing are testing the old (regression) behavior:Assistant
Let me also check the
test_strict_none_with_additional_properties_truetest specifically:Assistant
Let me look at the test that's failing to understand it better:
Assistant
Let me also check for any other uses of
BedrockJsonSchemaTransformer:Assistant
Let me also check the documentation:
Assistant
No documentation about strict in the Bedrock docs. Let me also check the CHANGELOG or release notes:
Assistant
Let me also check the
walkmethod in the base class to make sure my override is correct:Assistant
Let me also run the original reproduce script one more time to confirm:
Assistant
The fix is working correctly. Let me also clean up the temp files:
Assistant
Let me review the final diff:
Assistant
Let me also run a broader test to make sure I haven't broken anything else:
Assistant
Let me also run the tool choice unit tests:
Assistant
Let me also check the Anthropic tests:
Assistant
All Anthropic tests pass. Let me do a final sanity check:
Assistant
The fix is working correctly. Let me provide a summary of what was done:
Summary
Issue
In
pydantic-ai-slim==1.101.0, theBedrockJsonSchemaTransformerwas auto-promoting tools withstrict=None(the default) tostrict=Truefor simple schemas. This caused 73 tools to be sent as strict, exceeding Bedrock's 20-strict-tool limit and causingValidationException: Too many strict tools (73).
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.