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
I’ll trace Bedrock’s tool customization and mapping paths, compare the provider-specific behavior with Anthropic, then make the smallest targeted change. I’ll inspect relevant tests and run focused tests (plus a temporary reproduction if needed), verify the diff, and only then submit.
- Assistant
rgis unavailable in the environment, so I’ll usegrep/findinstead and continue locating the implementation. - Assistant
The regression is in
BedrockJsonSchemaTransformer: the generic model layer convertsstrict=Noneto the transformer’sis_strict_compatible. Bedrock currently leaves that flag true for compatible schemas, unlike Anthropic. I’ll make Bedrock report strict compatibility only for explicitstrict=True; the existing mapper already emits the wirestrictfield only when the resulting definition is true. I’ll also update the transformer documentation to reflect the opt-in semantics, without changing explicit strict behavior. - Assistant
The temporary reproduction now shows
strict=Nonebecomesstrict=Falseand therefore cannot producetoolSpec.strict=true. The focused legacy provider tests fail only because they assert the old auto-promotion (is_strict_compatible is True), which directly conflicts with the requested behavior; I’ll still run the explicit strict and model mapping tests to ensure opt-in strict support is unchanged. - Assistant
Explicit
strict=Truetransformer tests (16) and Bedrock tool-definition mapping tests (3) pass, and the diff is whitespace-clean. The fix is limited to Bedrock’s compatibility inference and documentation; unsupported models and explicitstrict=Falsebehavior remain unchanged. I’m reviewing the final diff and submitting now.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.