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 inspect the Bedrock provider implementation and nearby tests, identify where
strict=Noneis promoted, then make the narrowest provider-specific change and run the relevant test suite. I’ll also verify the resulting diff and explicitly assess the requested checklist before submitting. - Assistant
The repository already contains a Bedrock strictness transformer that explicitly documents the problematic auto-promotion, so I’ll inspect its full implementation and tests to determine the intended change and whether this checkout includes partial prior work.
- Assistant
The root cause is confirmed:
_customize_tool_def()replacesstrict=Nonewithis_strict_compatible, and Bedrock currently reportsTruefor compatible schemas. The model mapper already emitsstrictonly for truthy values, so the provider fix should make Bedrock’s transformer behave like Anthropic: preserve schemas and report non-strict compatibility unless strict was explicitly requested, while retaining transformations for explicitstrict=Trueand forced native output. - Assistant
I’ll implement an explicit
walk()override onBedrockJsonSchemaTransformer. Forstrict=Trueit will use the existing Bedrock-compatible transformation; forstrict=FalseandNoneit will return the original schema unchanged and mark it non-strict-compatible, matching the provider’s non-auto-promoting contract. This also avoids silently injectingadditionalProperties: falseinto ordinary non-strict tools. - Assistant
The first edit command was rejected by shell quoting before it changed any file. I’ll rerun the same edit with simpler quoting, then execute the focused tests; any failures in legacy tests that assert the old auto-promotion will be distinguished from functional regressions.
- Assistant
The source change is applied. The initial test invocation failed due to the repository package not being on
PYTHONPATH, not due to the code. I’ll rerun with the slim package path, then use a direct reproduction to verify that a compatiblestrict=Nonetool becomes non-strict on the wire while explicitstrict=Trueremains strict. - Assistant
The focused run shows the wire-level regression test passes, but five provider tests fail because the existing Bedrock transformer intentionally strips titles and adds
additionalProperties: falseeven for non-strict modes. That schema behavior is unrelated to the provider-limit bug and should be preserved for compatibility. I’ll narrowwalk()to retain the existing transformation for all modes, then override only the inferred strictness toFalsewhen strict was not explicitlyTrue. - Assistant
The narrowed implementation now passes all affected tests except the two legacy assertions that explicitly require the old
is_strict_compatible=Trueauto-promotion. The important model-levelstrict=Nonemapping test passes, as does explicit strict mode and all other Bedrock transformer tests. I’ll run the full strict-tool test module, static formatting/checks, and inspect the final diff for correctness. - Assistant
Verification is complete: all seven Bedrock strict-tool tests pass, Ruff lint and formatting pass, and the diff is clean. The two failures in the broader provider test run are expected legacy assertions for the behavior this issue asks to remove (
strict=Nonebeing considered compatible); no other provider tests failed. I’ll do one final status/diff check and submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.