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-definition customization and mapping, compare it with the provider behavior mentioned in the issue, then make the smallest targeted change. I’ll inspect existing tests and run the relevant test suite (without modifying tests), using a temporary reproduction if needed.
- Assistant
The relevant code is present in both the Bedrock provider transformer and model mapper. The provider explicitly documents auto-promotion for
strict=None, while the mapper only emits the field for truthy strict values. I’ll inspect the complete implementation and its tests/history to determine whether the intended fix is provider-specific and how strict output handling should remain unaffected. - Assistant
The inference occurs in the shared
_customize_tool_def: when the transformer reports compatibility,strict=Nonebecomesstrict=True. The Bedrock transformer currently leaves compatibility true for simple schemas. I’ll make Bedrock mirror Anthropic’s policy by reporting strict compatibility only whenstrict is True; this preserves explicitstrict=Truetransformation and keepsstrict=False/Nonefrom producingtoolSpec.strict. I’ll update the Bedrock transformer documentation accordingly, without changing the shared behavior used by other providers. - Assistant
The first edit command was rejected by a shell-quoting error before it changed anything. I’ll rerun the same intended edit with corrected command quoting, then execute the provider tests.
- Assistant
The source change is applied. The test command could not import the local package because this checkout requires its configured environment/PYTHONPATH; pytest failed during warning-filter initialization, not from a test failure. I’ll locate the repository’s test runner configuration, run through it, and also directly exercise the customization and Bedrock mapping with the local source path.
- Assistant
The direct reproduction now confirms the fix: a simple Bedrock schema with
strict=Noneyieldsis_strict_compatible=False, and_customize_tool_defyieldsToolDefinition.strict=False, so the Bedrock mapper omitstoolSpec.strict. The provider suite has 46 passing tests; only two existing tests assert the old auto-promotion behavior, which is exactly the behavior this issue requires changing. I’ll run formatting/lint checks and a focused Bedrock model test, then inspect the final diff.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.