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 definitions.
- Assistant
I'll inspect how Anthropic avoids auto-promoting
strict=None, then compare that with the Bedrock tool-definition path. - Assistant
rg is not found, let me use grep instead.
- Assistant
I'll open both schema transformers next to compare how they treat
strict=None. - Assistant
Let me continue reading the rest of the transformer and also the Anthropic one.
- Assistant
Next I'll inspect
_customize_tool_defand the Bedrock strict-tool tests so the fix matches expected behavior. - Assistant
I need to check how Bedrock forces strict for native output so we don't break that path.
- Assistant
I'll check the base
JsonSchemaTransformerand Anthropic's tests to mirror the right pattern. - Assistant
I'll keep reading the remaining tool-definition tests for the
strict=Nonecase. - Assistant
I'll look for related GitHub issues and any earlier discussions about this regression.
- Assistant
I'll check the PR that introduced this behavior and the docs on Bedrock strict tooling.
- Assistant
I'll update
BedrockJsonSchemaTransformerto match Anthropic: only treatstrict=Trueas compatible, and avoid auto-promotingstrict=None. - Assistant
I'll write a small repro to confirm many
strict=Nonetools no longer get auto-promoted. - Assistant
I'll run the strict=True unit tests that shouldn't be affected by this change.
- Assistant
I'll also verify the full
prepare_requestpath leaves default tools non-strict. - Assistant
I'll simplify the end-to-end check to avoid the MagicMock issue.
- Assistant
I'll scan the docs for outdated notes about Bedrock auto-promoting
strict=None. - Assistant
I'll run the native-output unit tests that don't rely on VCR cassettes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.