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’s tool customization/mapping logic and the corresponding tests, then reproduce the inferred
strict=Truebehavior before making the smallest provider-specific change. - Assistant
rgis unavailable in this environment, so I’ll usegrepandfindto identify the same implementation and test coverage. - Assistant
The mapper already omits
strictwhen it receivesNone; therefore the regression occurs earlier when profile customization replacesNone. I’ll inspect the Bedrock transformer/profile construction and compare Anthropic’s explicit opt-in behavior. - Assistant
I found that Bedrock’s transformer documentation and
strict=Nonebranches intentionally implement auto-promotion, while Anthropic overrideswalk()to prevent it. I’ll inspect the generic customization contract and the complete Anthropic override to ensure the Bedrock fix preserves explicit strict schema transformation and native output. - Assistant
The generic helper infers strictness from
is_strict_compatible. To match the requested Anthropic semantics, Bedrock should mark compatibility true only for explicitstrict=True; additionally,strict=Noneshould follow the non-strict schema path rather than injecting strict-onlyadditionalProperties: false. Before editing, I’ll run a small local reproduction through the generic helper to confirm a default tool is currently promoted. - Assistant
The package is not installed into the bare interpreter. I’ll use the repository’s configured
uvenvironment (or set the slim source path if needed) to execute the reproduction. - Assistant
Dependencies exist in the repository virtual environment rather than the system Python, so I’ll rerun with
.venv/bin/python. - Assistant
The reproduction confirms
strict=NonebecomesTrue. I’ll make the narrowly scoped fix: retain Bedrock’s existing schema normalization/compatibility analysis, but override the final inferred compatibility for default tools so only explicitstrict=Truecan produce a strict tool definition. This avoids changing unrelated schema wire shapes. - Assistant
The change is in place. I’ll now rerun the minimal reproduction with 73 default tools and verify edge cases: explicit
Trueremains strict, explicitFalseremains non-strict, and the Bedrock mapper emitsstrictonly for opted-in definitions. - Assistant
The behavioral reproduction now shows zero strict tools for 73 defaults, and all seven model-level strict-tool tests pass. Two provider unit tests fail because they explicitly assert the superseded auto-promotion signal (
is_strict_compatible is Trueforstrict=None); their schema assertions still pass. Since repository instructions prohibit modifying tests and those assertions directly contradict the requested behavior, I’ll leave them unchanged. Next I’ll run formatting/lint/type checks relevant to the edited file and inspect whether broader profile tests reveal unintended native-output effects. - Assistant
Lint and formatting pass. I’ll run Bedrock native-output tests because native output intentionally forces
strict=Truebefore transformation, ensuring this default-tool change does not disable required structured-output behavior. I’ll also run Pyright on the package if its CLI supports the project configuration. - Assistant
Verification is complete: native-output tests pass, Pyright reports no errors, Ruff and diff checks pass. The only failures are the two stale assertions that require the exact auto-promotion signal this issue asks to remove; all associated schema snapshots pass, and no tests were modified.
Checklist:
- Reported error reproduced: Yes. The default simple tool was transformed from
strict=Nonetostrict=True; a 73-tool simulation counted 73 strict tools before the fix. - Fix confirmed: Yes. The same 73-tool simulation now counts 0 strict tools for defaults, while 73 explicitly strict tools remain strict.
- Edge cases considered: Yes. Explicit
strict=Trueandstrict=Falsewere verified, model support still gates wire emission, incompatible/default schemas remain non-strict, and forced strict native output was covered by 13 passing tests. - Affected existing tests run: Yes.
test_strict_tool_calls.pypassed 7/7 andtest_native_output.pypassed 13/13. Provider tests passed 46/48; the two failures assert that is auto-promotable and therefore intentionally conflict with the requested regression fix. Ruff, formatting, Pyright, and all passed.
- Reported error reproduced: Yes. The default simple tool was transformed from
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.