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 strict tool promotion.
- Assistant
Next I'll inspect Bedrock tool-definition handling and compare it with Anthropic's approach for
strict=None. - Assistant
rg is not available, let me use grep instead.
- Assistant
I'll open the Bedrock provider schema transformer and the Anthropic equivalent for comparison.
- Assistant
Let me read more of the transform method and also the anthropic one.
- Assistant
I'll review existing Bedrock strict-tool tests and how
_customize_tool_defusesis_strict_compatible. - Assistant
I need to check how native output interacts with
is_strict_compatible, since changing default strict promotion could affect it. - Assistant
I need to confirm when schema transformers run relative to Bedrock forcing
strict=Truefor native output. - Assistant
I'll read Bedrock's
prepare_requestto see whether it forces strict before or after schema customization. - Assistant
Let me also check the base class default and related tests naming to plan the code change carefully.
- Assistant
I'll check remaining strict-tool tests for assumptions about
strict=Noneauto-promotion. - Assistant
I'll update
BedrockJsonSchemaTransformersostrict=Noneis not auto-promoted, matching Anthropic. - Assistant
I'll write a temporary script to verify that
strict=Nonetools no longer get auto-promoted. - Assistant
I'll run the Bedrock unit tests that exercise the transformer and map definitions (no live API).
- Assistant
I'll check for docs or other code that still describes the old auto-promotion behavior.
- Assistant
There's also
test_strict_none_preserves_numeric_constraints- let me check that one. Looking at the failure: it seems the old snapshot still had additionalProperties: False when it said "no strippin... - Assistant
I'll confirm NativeOutput still forces
strict=Truebefore schema transformation so structured output keeps working. - Assistant
I'll review the final diff, then clean up the temporary scripts.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.