fix(anthropic): stop tool translation from mutating caller input_schema#34602
Conversation
|
|
Greptile SummaryFixes Anthropic tool translation so caller-owned input schemas remain unchanged.
Confidence Score: 5/5The PR appears safe to merge with no actionable defects identified. The copied value is a request JSON-schema dictionary, downstream mutations now apply only to the translated object, and the regression test directly covers both immutability and expected translated output.
|
| Filename | Overview |
|---|---|
| litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py | Deep-copies the caller-provided schema before downstream parameter mutation, preventing translation from corrupting reused request data. |
| tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py | Adds focused regression coverage demonstrating that translation preserves the source schema while retaining provider-specific fields in the translated result. |
Reviews (1): Last reviewed commit: "fix(anthropic): stop tool translation fr..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
TLDR
Problem this solves:
translate_anthropic_tools_to_openaiassigned the caller'sinput_schemadict to the translatedparametersby reference, then the "pass additional computer kwargs" loop merged extra top-level tool keys (e.g. acomputertool'sdisplay_width_px) into that shared dict in placeparametersJSON schema can reject the request. The corruption is silentHow it solves it:
input_schemabefore assigning it tofunction_chunk["parameters"], so translation is a pure read and later kwarg merges land only on the copytranslate_anthropic_output_format_to_openaiin the same file, which alreadycopy.deepcopys its schema for the same reason;copyis already importedRelevant issues
Fixes #34510
Linear ticket
Type
🐛 Bug Fix
Changes
litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py: deep-copyinput_schemabefore it becomes the translated OpenAIparametersAdded a regression test
test_translate_anthropic_tools_to_openai_does_not_mutate_caller_input_schemathat asserts the caller'sinput_schemais untouched after translation and that the vendor kwargs still reach the translatedparameters. It fails on the pre-fix code and passes afterQA runbook
Pure translation logic, so it reproduces with no provider credentials
Before this PR prints
mutated: True(the caller's schema now containsdisplay_width_px/display_height_px); after, it printsmutated: False