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 trace Bedrock’s tool customization and compare it with the Anthropic provider, then identify focused existing tests that can reproduce the implicit strict promotion before making the smallest provider-specific change.
- Assistant
The strict inference is centralized in the base model customization path, so I’ll inspect that contract and each provider transformer’s strict-compatibility response to determine whether Bedrock should disable inference at the transformer level (as Anthropic does) while preserving explicit
strict=True. - Assistant
Bedrock already has a dedicated schema transformer, making it the appropriate provider boundary for this behavior. I’ll inspect its implementation and test coverage, especially assertions around omitted/false/true
toolSpec.strict, so the fix does not alter explicit strict tools or schema transformation semantics. - Assistant
The current Bedrock transformer explicitly implements the regression: for
strict=Noneit mutates schemas toward strict compatibility and advertises them as strict. Before changing it, I’ll read the exact unit tests for all three strict states and model request mapping; these reveal which expectations are regression-era and which transformations are required only for explicit strict mode. - Assistant
The tests confirm that auto-promotion and
additionalProperties: falseinjection forstrict=Nonewere intentionally added together. The correct non-opt-in behavior is to treatNonelike non-strict for tool schemas, while retaining explicitstrict=Truetransformations and native output’s forced strict mode. I’ll first run the focused “simplestrict=None” test as a concrete reproduction, then update the transformer and its documentation. - Assistant
The focused test reproduces the underlying faulty state (
is_strict_compatible=True). To mirror the reported 73-tool failure without making a network request, I’ll run the actual customization function over 73 default tool definitions and count how many become strict; this directly exercises the path that builds Bedrock requests. - Assistant
The reproduction exactly yields 73 strict tools. I’ll remove implicit strict preparation for
strict=Noneand explicitly report strict compatibility only when strict mode was requested. This follows Anthropic’s opt-in pattern, ensures default schemas are not unnecessarily tightened, and leavesstrict=Trueconstraint stripping and native-output forcing intact. - Assistant
Reviewing the diff, removing default schema normalization is broader than required to fix the provider limit. I’ll narrow the patch: preserve Bedrock’s existing schema transformation for compatibility, but override only the inferred strict flag after walking. This minimizes behavioral change while guaranteeing that only an explicit
strict=TruereachestoolSpec.strict. - Assistant
The actual 73-tool customization path now produces zero strict tools, while explicit
Falseremains false and explicitTrueremains true. Next I’ll run the full Bedrock provider tests to detect unintended schema regressions; I expect only the two old assertions that explicitly require the now-invalid auto-promotion behavior to fail. - Assistant
Results are as expected: all 122 Bedrock model tests pass, and 46/48 provider tests pass; the only failures are legacy tests asserting the behavior this issue requires removing. Since tests must not be edited, I’ll leave those outdated assertions unchanged and now run all remaining strict-transformer tests plus formatting/lint/type checks for the modified module.
- Assistant
The focused strict tests, linter, formatter, and type checker all pass. I’ll do a final diff/status review and verify the key edge case that native/explicit strict schemas still receive Bedrock’s required transformations while default tools remain non-strict.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.