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 locate the Bedrock provider/model customization and its focused tests, then reproduce the
strict=Nonepromotion through an existing or temporary test path before making the smallest provider-specific change. - Assistant
There is already a direct mapping test asserting that
strict=Noneis omitted, so the regression likely occurs earlier during provider profile schema transformation. I’ll inspect that flow and the Bedrock/Anthropic profile definitions to identify where auto-promotion is enabled. - Assistant
The shared customization intentionally infers strictness, while Anthropic avoids promotion by making its transformer report non-strict unless strict was explicitly requested. Bedrock should mirror that behavior without affecting native output (which
prepare_requestexplicitly forces tostrict=True). I’ll compare both transformer implementations and inspect focused unit coverage around request preparation. - Assistant
Existing provider tests explicitly encode the now-reported auto-promotion behavior, so they may fail after the behavioral correction (and must not be edited per instructions). Before changing code, I’ll run a small temporary script through
_customize_tool_defto reproduce the actual promotion, and review those expectations to ensure explicitTrue, explicitFalse, incompatible schemas, and native output remain correct. - Assistant
The reproduction script was blocked because bare Python lacks project dependencies. I’ll use the repository’s configured
uvenvironment. The likely correction is awalk()override that only changes the inferred compatibility result forstrict=None, preserving all schema transformation semantics and explicit strict behavior. - Assistant
The issue is reproduced: a default tool becomes
strict=True. I’ll now implement Bedrock’s opt-in rule at the transformer boundary, documenting thatstrict=Noneremains non-strict whilestrict=Truestill performs Bedrock’s required schema cleanup. This also naturally applies to all Bedrock model profiles using this transformer. - Assistant
The fix is in place. I’ll verify the reported default case, a 73-tool request-parameter case, explicit
strict=True/False, and native-output forcing via a temporary inline script, then run the focused Bedrock test modules to detect unintended regressions. - Assistant
The model-level strict and native-output suites pass, including confirmation that native output remains strict. The 73-tool reproduction now yields no strict tools. I’ll run the provider transformer suite; two legacy assertions are expected to conflict because they explicitly demand the reported auto-promotion, but all explicit strict and schema transformation cases should remain green.
- Assistant
As anticipated, 46 provider tests pass and only the two assertions that explicitly require
strict=Noneauto-promotion fail; these are stale relative to the requested behavior and cannot be edited. I’ll inspect base preparation ordering one final time and run static/lint checks on the changed file, ensuring native output is forced before transformation and the implementation meets project style/type rules. - Assistant
Preparation ordering confirms Bedrock sets native output to
strict=Truebefore the base transformer runs. Ruff and Pyright both pass. I’ll review the final diff and repository status, then submit with the required checklist assessment; the only failing tests are the two pre-existing assertions whose expected auto-promotion is exactly what this issue removes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.