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 look at the relevant provider files - specifically for Anthropic and Bedrock.
Assistant
Now let me look at the Bedrock provider:
Assistant
Let me find the
_customize_tool_defand_map_tool_definitionmethods mentioned in the issue:Assistant
Let me look at the BedrockConverseModel._map_tool_definition:
Assistant
Now let me understand the issue better. Let me see the tests:
Assistant
Let me also look at the providers test for Bedrock:
Assistant
Now let me check more ofthe test_bedrock.py file:
Assistant
Let me look at the test for the related test (test_bedrock_strict_tool_definition_none):
Assistant
Let me look at the JsonSchemaTransformer base class:
Assistant
Let me look at the related Bedrock PR (#4237) by looking at git history:
Assistant
Now I have a clear picture. Let me reproduce the issue first:
Assistant
I've confirmed the issue. Now let me look at the tests that may need to be considered:
Assistant
Now let me also check the tests/models/bedrock/test_strict_tool_calls.py fortests that may be affected:
Assistant
Let me look at the
_customize_output_objectfunction to understand it fully:Assistant
Now let me look at the relevant code one more time:
Assistant
Now let me also check if there are docs that need to be updated:
Assistant
Let me search the docs for relevant content about strict tools:
Assistant
Let me look at how the
walk()method is structured in the base class:Assistant
Now let me check what happens with
_handleandtransform:Assistant
Now let me look at related tests in the bedrock models folder:
Assistant
Now I have a clear understanding. Let me implement the fix:
Assistant
Let me verify the change was applied:
Assistant
Now let me verify the issue is fixed by re-running the reproduction script:
Assistant
Now let me also test that explicit
strict=Truestill works:Assistant
Now let me run the existing tests to see which ones break and verify our fix doesn't break anything unrelated:
Assistant
Let me run all tests to see all failures:
Assistant
These 4 tests test the old behavior that the fix is changing. Per the instructions, I can ignore these. Let me run the model tests for Bedrock to make sure no other tests break:
Assistant
All Bedrock model tests pass. Let me also run the anthropic tests to make sure I haven't broken anything:
Assistant
Let me also run a broader test to check that nothing else is broken:
Assistant
Now let me also run the model test for native output:
Assistant
Let me also check the
_customize_output_objectto ensure my fix also works correctly for output objects:Assistant
Let me look at the native output tests to verify they still work with my fix:
Assistant
Let me look at the current state of the change:
Assistant
Let me check the actual issue number:
Assistant
Let me remove the speculative issue number reference and use a more general description:
Assistant
Let me remove the speculative issue number reference:
Assistant
Let me make sure all related tests still pass:
Assistant
Only the 4 expected tests fail - they test the OLD auto-promotion behavior that the fix changes. Let me verify the final diff:
Assistant
Let me clean up my temporary scripts:
Assistant
Let me create one final verification script to confirm the fix:
Assistant
All checks pass. Let me clean up the verification script and check that everything is in order:
Assistant
Let me run a broader set of related tests to make sure I haven't broken anything:
Assistant
Only 4 expected tests fail (testing the old auto-promotion behavior). Let me also check the models tests directory:
Assistant
Let me investigate the errors that are showing up in the modeltests:
Assistant
The errors are unrelated to my changes (they're in test_outlines.py). Let me confirm by checking the git diff:
Assistant
The errors are pre-existing and unrelated to my changes. Let me verify one more time that the original issue scenario works correctly:
Assistant
The issue is fixed. Let me do a final verification of the diff:
Assistant
Now let me verify the changes are complete and submit:
Assistant
Let me verify the final state of the file:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.