Repository navigation
fix: carry functionDeclaration parameters into google_genai tool translation - #35921
Aryan-Kochhar wants to merge 2 commits into
Conversation
…slation Google GenAI function declarations carry their argument schema in `parameters` (a Schema, whose type enums are uppercase) as well as in the newer `parametersJsonSchema`. The adapter only read `parametersJsonSchema`, so any tool declared with `parameters` reached the model with no argument schema at all and could not be called correctly Reading `parameters` as a fallback also makes the existing `normalize_tool_schema` call reachable for its intended input; it lowercases the uppercase Schema type enums, which is what that normalizer was written for
|
recheck |
Greptile SummaryThe PR preserves
Confidence Score: 5/5The PR appears safe to merge because no blocking functional failure remains greptile previously said the docstring concern was resolved, but the three newly introduced docstrings remain contrary to the repository guidance; this is convention cleanup rather than a merge-blocking failure
|
| Filename | Overview |
|---|---|
| litellm/google_genai/adapters/transformation.py | Adds the intended fallback from parametersJsonSchema to parameters without changing precedence |
| tests/test_litellm/google_genai/test_google_genai_adapter_fixes.py | Adds focused regression coverage for both schema representations and declarations without parameters |
Reviews (2): Last reviewed commit: "test: shorten the parameters schema test..." | Re-trigger Greptile
Matches the single line docstrings the other tests in this file already use
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Closing since #42067 landed this fix along with response_schema forwarding and regression tests. Thanks Aryan-Kochhar for surfacing the dropped parameters |
TLDR
Problem this solves:
parameterslose their argument schemanormalize_tool_schemanever receives the uppercase types it handlesHow it solves it:
parameterswhenparametersJsonSchemais absentnormalize_tool_schemathen lowercases the Schema type enumsparametersJsonSchemastill wins when both are presentRelevant issues
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
The adapter only runs when the backing provider has no native generateContent config, so the
config below points a Gemini model at Google's OpenAI compatible endpoint. That routes the request
through
GoogleGenAIAdapterrather than the native Gemini path, which is the code this PR changesThe tool below declares
zx_identandrev_noinparameters. Those names cannot be guessed, sowhether the schema survived translation is visible in the response
Before, at
4fcaf7d:{"candidates":[{"content":{"parts":[{"functionCall":{"name":"fetch_record","args":{"id":"ABC-123","revision":7}}}],"role":"model"},"finishReason":"STOP","index":0,"safetyRatings":[]}],"usageMetadata":{"promptTokenCount":30,"candidatesTokenCount":24,"totalTokenCount":421}}The model returned
idandrevision, which it invented, because it never saw the declared names.A caller dispatching on
zx_identandrev_nogets nothing it can useAfter, at
0c44266:{"candidates":[{"content":{"parts":[{"functionCall":{"name":"fetch_record","args":{"zx_ident":"ABC-123","rev_no":7}}}],"role":"model"},"finishReason":"STOP","index":0,"safetyRatings":[]}],"usageMetadata":{"promptTokenCount":88,"candidatesTokenCount":28,"totalTokenCount":209}}The argument names now match the declaration.
promptTokenCountgoing from 30 to 88 is the schemaitself reaching the model, and the uppercase
OBJECT,STRINGandINTEGERenums were lowercasedon the way through by the existing
normalize_tool_schemacallType
🐛 Bug Fix
Changes
Google GenAI function declarations carry their argument schema in
parameters, a Schema whose typeenums are uppercase, as well as in the newer
parametersJsonSchema._transform_google_genai_tools_to_openaionly read
parametersJsonSchema, so a tool declared withparameterswas translated into an OpenAItool carrying no
parameterskey at allThe same method already calls
normalize_tool_schema, whose job is lowercasing uppercase Schematype enums. Nothing on this path could produce uppercase types, since
parametersJsonSchemaisalready standard JSON Schema, so that normalizer was unreachable for the input it was written for.
Reading
parametersfixes the dropped schema and makes the existing normalization do its joblitellm/google_genai/adapters/transformation.pygains a two line fallback.parametersJsonSchemakeeps precedence when both fields are present, so existing behavior is unchanged
tests/test_litellm/google_genai/test_google_genai_adapter_fixes.pygains three tests covering theparameterspath including uppercase type normalization, the precedence rule, and a declarationcarrying no argument schema
Final Attestation