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
I'll start by exploring the repository structure and understanding the relevant files for this Bedrock strict tool issue.
Assistant
I'll explore the repository structure first.
Assistant
The file is large. Let me search for the relevant methods mentioned in the issue:
_customize_tool_defand_map_tool_definition.Assistant
The
_customize_tool_defisn't in bedrock.py directly. Let me search the broader codebase.Assistant
Now let me look at the Anthropic provider to understand how it handles
strict=None, as mentioned in the issue.Assistant
Now let me look at the Bedrock JSON schema transformer.
Assistant
Now let me look at the base
JsonSchemaTransformerclass to understandis_strict_compatible.Assistant
Let me look at the Bedrock tests to understand the expected behavior.
Assistant
Let me look at the
_map_tool_definitionmethod in detail.Assistant
Let me look at the provider tests for the Bedrock transformer.
Assistant
Let me look at the rest of the test file and search for strict=None tests with simple schemas.
Assistant
Let me reproduce the issue. First, let me check the version and write a reproduction script.
Assistant
Let me check if there's a virtual environment already set up.
Assistant
The venv has the package installed. Let me check if bedrock is available and write a reproduction script.
Assistant
I need to set a region. Let me update the script.
Assistant
I've reproduced the issue. Now let me look at the remaining strict=None tests to understand the full current behavior.
Assistant
Let me look at how the Anthropic transformer tests are structured, to mirror the expected behavior.
Assistant
This confirms the desired behavior. Now let me check the Bedrock test cassettes and how VCR matching works, since changing strict behavior could affect recorded cassettes.
Assistant
Let me check the default match_on for VCR. The
vcr_configdoesn't setmatch_on, so it uses the default which is['method', 'scheme', 'host', 'port', 'path', 'query']— it does NOT match on body by default. So request body changes won't cause cassette mismatches!Let me verify the default match_on. The default VCR match_on is
['method', 'scheme', 'host', 'port', 'path', 'query']. Body is not included by default. So if my fix changes the request body (e.g., removingstrict: true), VCR would still match the cassette based on method/host/path/query and replay the recorded response.But wait, there's a custom matchers registered: 'method', 'path', 'host'. Let me check what match_on is actually used. Let me look at the cassette_ctx and how matchers are configured.
Assistant
Let me check the cassette_utils to see if there's any body matching involved.
Assistant
Let me search for tests that verify
strictin the request body for Bedrock.Assistant
Now I understand the situation. VCR doesn't match on body by default, so cassette replay won't break. Let me view the exact current transformer code to make a precise edit.
Assistant
Now I'll make the fix. Let me open the file and edit the transformer.
Assistant
Now I'll make the edit to the transformer, following the Anthropic pattern:
Assistant
The edit looks good. Now let me run my reproduction script to confirm the fix works.
Assistant
The fix works—
strict=Nonetools are no longer auto-promoted. Now let me verify that explicitstrict=Truestill works, and test edge cases.Assistant
The behavior now mirrors Anthropic exactly. Let me run the existing Bedrock tests to see what breaks and confirm the breaks are expected (encoding old behavior).
Assistant
As expected, this test encodes the old auto-promotion behavior. Let me check all the strict_none tests and confirm they break for the expected reason, and verify no cassette-based test asserts on the request body's strict field.
Assistant
These 4 failures all encode the old auto-promotion behavior and need updating. Let me confirm the
strict=Trueandstrict=Falsetests still pass (those behaviors are unchanged).Assistant
All
strict=True/strict=Falsetests pass. Now let me run the cassette-based strict tool call tests.Assistant
All cassette tests pass. Now let me check the broader Bedrock model test suite for any tests that use default tools and might assert on the request body's strict field.
Assistant
Let me look at the native output test around line 356 to ensure it's not affected.
Assistant
Native output forces
strict=True, so it's unaffected. Let me run the native output and main bedrock model test suites.Assistant
All model tests pass. Let me run the full provider test file and the full bedrock model test directory to confirm only the expected 4 tests fail.
Assistant
Only the 4 expected
strict_nonetests fail—all encoding the old auto-promotion behavior. All other 64 tests pass. Let me check the docs and any other references to the Bedrock auto-promotion behavior.Assistant
Let me check whether any bedrock test asserts on request body contents (which could be affected by the strict change).
Assistant
Let me examine the git history of the Bedrock transformer to understand the design intent and look for hints about the intended fix.
Assistant
Let me find the Anthropic test that the Bedrock test claims to mirror, to understand the expected behavior.
Assistant
This is very illuminating. The Anthropic test
test_strict_tools_supported_model_auto_enabledshows that forstrict=None+ compatible schema, Anthropic sends no strict field, andadditionalProperties: Falsecomes from schema generation—not the transformer. This confirms my interpretation (A): the transformer should not modify the schema or promote forstrict=None, exactly mirroring Anthropic.Let me write a comprehensive edge-case verification script.
Assistant
All edge cases pass. Let me run the broader relevant test suites to confirm the overall state.
Assistant
The inconsistency argument is the key tiebreaker: after coalescing,
strict=Nonebecomesstrict=False, so they must behave identically. My fix achieves this (both skip schema transformation). Let me confirmstrict=Noneandstrict=Falsenow produce identical schemas.Assistant
strict=Noneandstrict=Falsenow produce identical schemas—confirming consistency. Let me run linting on the modified file to ensure code quality.Assistant
Ruff passes and formatting is good. Let me clean up temp scripts and do a final review of the change.
Assistant
The diff is clean. Let me view the final state of the transformer to confirm coherence.
Assistant
The transformer now mirrors Anthropic exactly. Let me do a final check to ensure no bedrock test asserts on request-body contents (cassettes don't match on body, but let me be thorough).
Assistant
No request-body assertions for tool strict (the
.bodyreferences are error-response bodies). Let me run the cassette-based tests one final time to confirm everything is green.Assistant
All 142 cassette/model tests pass. Let me confirm the provider tests pass except for the 4 known
strict_nonetests that encode the old behavior.Assistant
All tests pass except the 4
strict_nonetests that encode the old auto-promotion behavior (which the issue identifies as a bug and which need updating). Let me do a final search for any other references to the old Bedrock auto-promotion behavior in the codebase that might need updating.Assistant
Only my updated file references the (now-correct) behavior; the docs line is unrelated (server-side premium tier promotion). Let me confirm the final git status shows only the intended file change.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.