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 first locate the Bedrock provider/model customization and its tests, then reproduce the
Nonepromotion behavior with the narrowest existing test path before changing it. I’ll compare Anthropic’s handling to preserve explicitstrict=Truewhile preventing implicit promotion. - Assistant
rgis unavailable in this environment, so I’ll usegrep/findto identify the implementation and relevant tests. - Assistant
The mapper already omits a literal
None; the regression occurs earlier when the Bedrock transformer marks a default tool as strict-compatible and generic customization replacesNonewithTrue. I’ll inspect that transformer, generic customization, and the Bedrock strict test module to determine the smallest provider-specific correction and whether existing expectations encode the regression. - Assistant
The provider tests explicitly document auto-promotion, confirming the regression is implemented in
BedrockJsonSchemaTransformer. The robust fix is to make its compatibility result opt-in (self.strict is True), as Anthropic does. I’ll inspect exact generic behavior and all transformer assertions before editing, becausestrict=Nonecurrently also injectsadditionalProperties: false; if non-strict tools should remain normal, that mutation should likely be removed rather than merely suppressing the wire flag. - Assistant
The issue asks specifically to stop implicit strictness, not to alter Bedrock’s schema normalization. I’ll therefore mirror Anthropic narrowly: after walking the schema, force
is_strict_compatibleto true only for explicitstrict=True. This preserves existing schema transformations and explicit strict behavior while ensuring generic customization resolves defaultNoneto non-strict. Before editing, I’ll reproduce the promotion directly through_customize_tool_def. - Assistant
The reproduction confirms a default simple tool becomes
strict=True. I’ll add the opt-in compatibility override and update the transformer documentation so future maintainers do not reintroduce inference. Explicitstrict=Truewill still perform all strict transformations;FalseandNonewill both report non-strict compatibility. - Assistant
The change is intentionally provider-wide (all models routed through Bedrock), while native output remains safe because
BedrockConverseModel.prepare_request()explicitly forces native output tostrict=True. I’ll now verify default, explicit false, and explicit true customization—including a 73-tool simulation—and then run focused unit tests for mapping and strict schema transformation. - Assistant
The reproduction now shows zero strict tools among 73 defaults, while explicit true remains true. The focused pytest invocation aborted because one guessed test name does not exist, so no selected tests ran; I’ll list the exact provider test names and rerun valid selectors.
- Assistant
The exact strict-true test is
test_strict_true_simple_schema; I’ll rerun with that valid selector. - Assistant
The focused unaffected tests pass. Two existing direct-transformer tests assert the now-invalid auto-promotion behavior (
is_strict_compatible is Trueforstrict=None), so they necessarily conflict with the requested regression fix; per the instruction not to modify tests, I’ll leave them unchanged. I’ll run formatting/linting and a broader Bedrock strict test subset that excludes live/VCR API calls, then inspect the final diff. - Assistant
The implementation is formatted and lint-clean; 19 relevant Bedrock transformer tests pass. I’ll do one final review of the exact patch and verify native output still explicitly opts into strict mode, ensuring the override does not disable Bedrock structured output.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.