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 code and its tests, then reproduce the
strict=Nonepromotion at the unit level before making the smallest provider-specific change. Afterward I’ll run the affected test suite and inspect the final diff. - Assistant
rgis unavailable in this environment, so I’ll usegrepandfindto identify the relevant implementation and tests. - Assistant
The regression is clearly documented in
providers/bedrock.py: its schema transformer currently auto-promotesNone. I’ll read that transformer, compare Anthropic’s behavior, and locate all Bedrock-specific tests so the fix preserves explicitstrict=Trueschema cleanup and structured output behavior. - Assistant
Existing tests explicitly assert the old auto-promotion semantics, while the requested regression fix changes those semantics. Per the instruction not to modify tests, I’ll inspect the test expectations and the generic customization pipeline, then alter only production code. This will also clarify whether overriding
walk()(as Anthropic does) is safer than deleting compatibility logic fromtransform(). - Assistant
The generic pipeline replaces
ToolDefinition.strict=Nonewith the transformer’sis_strict_compatible. Therefore, the provider transformer should follow Anthropic’s pattern and force compatibility toFalseunless strict mode was explicitly requested. I’ll reproduce the current result through_customize_tool_defwith a simple schema, including the eventual Bedrock wire mapping, before editing. - Assistant
The source-level reproduction confirms the exact path, but importing the package failed because dependencies are not installed. I’ll inspect the project’s prescribed test runner and environment metadata, then use it to run the reproduction.
- Assistant
A locked
uvenvironment is available. I’ll run the focused reproduction underuv, then implement the Anthropic-style opt-in behavior. I’ll retain strict transformations only for explicitTrue; forNone, normal schemas should not be altered merely to qualify for strict mode. Titles are still removed by the provider’s general normalization, matchingstrict=False. - Assistant
The reproduction shows a default tool becoming
strict=Trueand gainingadditionalProperties: false. I’ll now changeBedrockJsonSchemaTransformerso only explicitstrict=Trueis considered strict-compatible, and remove thestrict=Noneschema mutations/compatibility inference. Explicit strict tools will continue to receive all Bedrock-required transformations and unsupported-constraint handling. - Assistant
The implementation now has clean opt-in semantics. I’ll verify three edge cases directly: 73 default tools all remain non-strict, an explicit strict tool remains strict and is transformed, and an explicit non-strict tool remains untouched. Then I’ll run the relevant provider tests to distinguish expected stale assertions from genuine regressions.
- Assistant
The focused reproduction passes. The provider suite has 44 passing tests and four assertions tied to prior
strict=Nonebehavior. Two failures only concern promotion (expected and obsolete), while two reveal that removingadditionalProperties: falseis an unnecessary schema-shape change. To minimize the regression fix, I’ll preserve the prior schema normalization forNonebut override the final compatibility result toFalse; this changes only whether Bedrock receivesstrict: true, exactly as requested. - Assistant
Now 46/48 provider tests pass; the only failures explicitly assert the behavior this issue asks to reverse (
strict=Nonebeing compatible/auto-promoted). I will not edit tests per the task constraints. Next I’ll run Bedrock model tests, especially strict tool calls, and static formatting/lint checks on the changed file. - Assistant
All 142 Bedrock model tests pass, including the existing contract “
strict=None→ no strict field,” explicit strict/non-strict tools, mixed toolsets, and native output. I’ll run Ruff formatting/lint and the repository’s type checker for the modified module, then inspect the diff for unintended changes. - Assistant
Static checks are clean. Reviewing the diff, the internal compatibility checks in
transform()can remain unchanged becausewalk()deliberately overrides the final result; restoring them makes the patch smaller and guarantees schema transformation behavior is byte-for-byte unchanged. I’ll simplify to that minimal change, rerun checks, and verify the 73-tool reproduction once more. - Assistant
The final patch is minimal: schema normalization is unchanged, while the post-walk compatibility flag now requires explicit
strict=True. The direct reproduction and static checks pass. I’ll run the complete affected provider/model tests while excluding only the two stale tests whose sole assertion is that defaults auto-promote—the exact behavior being fixed—then confirm repository status.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.