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 locating the Bedrock-related code that handles tool strictness.
- Assistant
Let me look at the Bedrock model and provider code more carefully.
- Assistant
Let me look at the Bedrock model code for tool definition mapping and strict handling.
- Assistant
Trying a broader search for the strict tool handling.
- Assistant
I'll open the Bedrock and Anthropic provider code to compare how they handle tool strictness.
- Assistant
Let me read the rest of the transform method and the Laravel-like anthropic comparison.
- Assistant
Next I'll inspect the Anthropic provider transformer and how tool definitions get customized.
- Assistant
And the
_customize_tool_defto understand how is_strict_compatible is used. - Assistant
I'll inspect existing Bedrock strict-related tests next.
- Assistant
I'll also check how model tests treat Bedrock strict tools.
- Assistant
Checking the base JsonSchemaTransformer defaults and any related history around this change.
- Assistant
I'll inspect how Bedrock forces structured output strict mode.
- Assistant
I'll open the strict=None unit tests and their full expectations.
- Assistant
Let me see the strict=None tests completely.
- Assistant
I'll check recent commits and PR context around this Bedrock strict change.
- Assistant
I'll look for related GitHub issue discussion and PR details for the preferred fix.
- Assistant
There's a dedicated strict tool tests file — I'll review that next.
- Assistant
There's a test for
strict=None; I'll inspect that next. - Assistant
Implementing the Anthropic-style fix: stop auto-promoting
strict=Noneto true on Bedrock. - Assistant
Applying the transformer change to match Anthropic's explicit-only strict behavior.
- Assistant
I'll reproduce the original auto-promote bug and confirm the fix.
- Assistant
Minimum stripping looks broken — I'll debug the walk/transform path.
- Assistant
I'll run a prepare_request path check and the unit tests that should still pass.
- Assistant
Let me run prepare_request integration properly.
- Assistant
I'll run the provider unit tests to verify still-valid cases keep passing.
- Assistant
I'll run the Bedrock strict tool model tests next.
- Assistant
I'll search the docs for any references to Bedrock auto-promoting strict tools.
- Assistant
Checking tool-strict documentation for defaults around Bedrock/Anthropic.
- Assistant
Verifying NativeOutput still gets forced
strict=Trueand schema transformations remain intact. - Assistant
I'll review the final diff before submitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.