feat(bedrock): forward strict and additionalProperties to Converse toolSpec - #29813
Closed
mateo-berri wants to merge 1 commit into
Closed
feat(bedrock): forward strict and additionalProperties to Converse toolSpec#29813mateo-berri wants to merge 1 commit into
mateo-berri wants to merge 1 commit into
Conversation
…olSpec Bedrock Converse supports strict in toolSpec since 2026-02, but _bedrock_tools_pt only whitelisted type/properties/required/name/description, so strict: true was silently dropped and Claude-on-Bedrock ignored enum constraints that GPT and direct-Anthropic honored. Forward strict from the OpenAI function and additionalProperties from the schema (Bedrock requires the latter alongside strict), passing each only when present. https://claude.ai/code/session_01WQjWd8NfUB3vxERwudbHkv
Contributor
Author
|
Closing in favor of #29814, which carries the identical change on a properly named branch. Continuing review there |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relevant issues
A customer reported that
strict: trueon tools is silently ignored for Claude on Bedrock: give a tool an enum and ask for a value outside it, and GPT and direct-Anthropic stay inside the enum while Claude-on-Bedrock returns the out-of-enum value. This re-applies the fix from #25209, which was correct and approved (Greptile 5/5) but went stale with merge conflicts since April after unrelated refactors landed in_bedrock_tools_pt. The hunks no longer applied, but the change itself was still valid, so this is a clean rebase onto current staging rather than a rewrite. Related: #10062, #16725, #6136Linear ticket
Pre-Submission checklist
make test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewCI (LiteLLM team)
Link:
Link:
Links:
Screenshots / Proof of Fix
Reproduce against a live proxy hitting real Bedrock (Claude). Define a tool whose only enum value is
celsiusand ask for Fahrenheit; before this change the call comes back withadditionalProperties/strictdropped and the model free to pick an out-of-enum value, after it the schema reaches Bedrock intact.With the fix the returned
unitstays"celsius"(the only enum member) instead of"fahrenheit".Type
🐛 Bug Fix
Changes
litellm/types/llms/bedrock.py: addadditionalProperties: booltoToolJsonSchemaBlockandstrict: booltoToolSpecBlock(bothtotal=False, so the keys stay optional).litellm/litellm_core_utils/prompt_templates/factory.py: in_bedrock_tools_pt, forwardstrictfrom the OpenAIfunctionandadditionalPropertiesfrom the schema, each only when present. Bedrock requiresadditionalProperties: falsealongsidestrict: trueor it rejects the request, so both have to travel together.tests/llm_translation/test_bedrock_completion.py: addtest_bedrock_tools_pt_strict_parametercovering both the pass-through and the absent-by-default cases. It fails (KeyError onstrict) without the factory change and passes with it.