Repository navigation
fix(gemini): detect Gemini 3+ by major version, not a gemini-3 substring - #37145
Closed
maya-lukas wants to merge 5 commits into
Closed
maya-lukas wants to merge 5 commits into
maya-lukas wants to merge 5 commits into
Conversation
`_is_gemini_3_or_newer` matched the substring "gemini-3", so Google's
rolling aliases (`gemini-flash-latest`, `gemini-flash-lite-latest` and
`gemini-pro-latest`) were not recognised even though they resolve to
Gemini 3.x. Every Gemini 3 behaviour keyed off that check was therefore
silently disabled for them, including the documented
`skip_thought_signature_validator` fallback.
The visible symptom is a multi-turn tool call failing with
`400 Function call is missing a thought_signature in functionCall parts`
whenever the assistant turn's tool call does not carry LiteLLM's
`__thought__`-encoded id, for example history replayed by a client that
uses its own tool-call ids.
Matching is by exact alias name rather than an `endswith("-latest")`
check, because versioned names such as
`gemini-2.5-flash-native-audio-latest` also end in `-latest` and are not
Gemini 3.
Contributor
Greptile SummaryThe PR replaces Gemini 3 substring detection with numeric major-version parsing while explicitly handling unversioned rolling aliases.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py | Introduces shared major-version and Flash-tier detection and applies it consistently to Gemini request transformation. |
| tests/test_litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py | Adds focused regression coverage for rolling aliases, later Gemini generations, thought-signature fallback, and thinking-level mapping. |
Reviews (3): Last reviewed commit: "fix(gemini): read the Flash tier off the..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Addresses review feedback: the module constant now carries the `Final` annotation required by LIT010, and the explanatory comments are folded into the existing docstring so the source keeps to the repository's comment convention.
The substring check would have reported Gemini 4 and later as pre-3, reintroducing the same class of bug the moment Google ships an explicitly versioned `gemini-4-*` model. Parsing the major version off the name and comparing against 3 makes every later release work without a code change, and it also excludes `gemini-2.5-flash-native-audio-latest` on version rather than by special-casing the name. The alias set now covers only names that carry no version at all.
-latest aliases as Gemini 3+gemini-3 substring
maya-lukas
force-pushed
the
fix/gemini-rolling-latest-alias-version-detection
branch
from
August 17, 2026 09:42
39cb416 to
a686f36
Compare
Author
1 task done
`_map_reasoning_effort_to_thinking_level` and `_map_thinking_param` each re-derived the Flash tier with the same substring the outer gate just stopped using, so a rolling alias reached the Gemini 3 branch and was then demoted inside it: `reasoning_effort="minimal"` on `gemini-flash-latest` returned `thinkingLevel="low"`, and `"none"` / `"disable"` likewise, so the caller silently got more thinking than it asked for. Closes BerriAI#18245. Both sites now share `_is_gemini_3_flash_or_newer`, which reuses the major version read and so covers Gemini 4 Flash without a code change. Flash-Lite counts; Pro does not, since MINIMAL is a Flash-tier level. Pro keeps "low" for minimal and "high" for medium, unchanged.
maya-lukas
force-pushed
the
fix/gemini-rolling-latest-alias-version-detection
branch
from
August 31, 2026 10:32
71ef3d6 to
a190e6b
Compare
Author
…t-alias-version-detection
devin-ai-integration
Bot
changed the base branch from
litellm_internal_staging
to
main
September 23, 2026 15:05
Contributor
|
Superseded by #42465, which already treats gemini-flash-latest, gemini-flash-lite-latest, and gemini-pro-latest as Gemini 3 or newer on main. Closing, thanks for the report |
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.
TLDR
Problem this solves:
gemini-flash-latest, which resolves to Gemini 3.xgemini-4-*once Google ships it400 missing a thought_signaturereasoning_effort="minimal"returnedthinkingLevel="low", and"none"/"disable"likewiseHow it solves it:
_is_gemini_3_flash_or_newerhelper for the Flash tier, built on that same version readUser Flow
Before: a developer whose agent calls a tool, then replays the result, gets a 400 on the follow-up turn, so the agent loop dies after its first tool call
POST http://localhost:4000/v1/chat/completionswith"model": "gemini/gemini-flash-latest", asearch_websitetool, and one user messagecall_abc123, and arole: "tool"result400, readingFunction call is missing a thought_signature in functionCall parts. This is required for tools to work correctly"model": "gemini/gemini-3.5-flash"returns200, so the failure looks specific to the aliasAfter: the same replay returns an answer, so the agent loop continues past its first tool call
POST http://localhost:4000/v1/chat/completionswith"model": "gemini/gemini-flash-latest", asearch_websitetool, and one user messagecall_abc123, and arole: "tool"result200, carrying the assistant's answer summarising the tool result"model": "gemini/gemini-3.5-flash"still returns200, exactly as it did beforeRelevant issues
Extends the fix for #18245 to the rolling aliases. That issue was closed by 9e3f946, which added the
reasoning_effort="minimal"→thinkingLevel="minimal"mapping for Gemini 3 Flash, but keyed the Flash tier on"gemini-3" in model, so it lands for versioned names and not forgemini-flash-latestorgemini-flash-lite-latest. The outer gate and the two Flash-tier checks are the same substring bug, so fixing one without the others moves a rolling alias from "wrong parameter entirely" to "right parameter, one level too high"Related to #25322, where the reported
400 ... missing a thought_signaturecomes from the same code path. This PR covers the case where the model's generation is not recognised from its name, and does not change signature propagation from thought partsLinear ticket
Pre-Submission checklist
@greptileaito re-request a review after pushing changes)Screenshots / Proof of Fix
Real calls to the Google AI Studio API through a live proxy, no mocks. Both runs use this setup unchanged:
The assistant tool call carries a plain client-side id with no
__thought__signature attached, which is what a client that stores tool calls under its own ids replays. The two explicitly versioned models act as the control: they are already detected correctly, so they must be unaffectedBefore (973329e)
the rolling alias
python litellm/proxy/proxy_cli.py --config config.yaml --port 4000curl -s -w "\nHTTP %{http_code}\n" -X POST http://localhost:4000/v1/chat/completions -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" -d @payload.jsonversioned models, for control
for M in gemini/gemini-3.5-flash gemini/gemini-3.7-flash; do sed "s#gemini/gemini-flash-latest#$M#" payload.json > pm.json; curl -s -o /dev/null -w "$M HTTP %{http_code}\n" -X POST http://localhost:4000/v1/chat/completions -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" -d @pm.json; doneAfter (a686f36)
the rolling alias
python litellm/proxy/proxy_cli.py --config config.yaml --port 4000curl -s -w "\nHTTP %{http_code}\n" -X POST http://localhost:4000/v1/chat/completions -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" -d @payload.jsonversioned models, for control
for M in gemini/gemini-3.5-flash gemini/gemini-3.7-flash; do sed "s#gemini/gemini-flash-latest#$M#" payload.json > pm.json; curl -s -o /dev/null -w "$M HTTP %{http_code}\n" -X POST http://localhost:4000/v1/chat/completions -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" -d @pm.json; donemake lintpasses at a686f36: circular imports, ruff format, ruff check, ruff strict gate, import safety, basedpyright on tests/e2e, the type-discipline gate and the basedpyright budget gate all report OK, with no budget ceiling needing an update. Lint and tests at the same two commits, for completeness.ruff checkon the two touched files reports 66 findings at 973329e and 65 at a686f36, all pre-existing, with none on the changed lines, andruff format --checkis unchanged.pytest tests/test_litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.pygoes from 2 failed, 144 passed to 146 passed, and the wider sweep overtests/test_litellm/llms/vertex_aiplustests/test_litellm/litellm_core_utils/prompt_templatesis 1527 passed, 3 skipped at both commitsFlash tier (a190e6b)
_map_reasoning_effort_to_thinking_leveland_map_thinking_parameach rebuilt the Flash tier with"gemini-3" in model.lower(), so the rolling aliases were demoted inside the branch the earlier commit had just let them into. Both now call_is_gemini_3_flash_or_newer, which reuses the major-version read and so covers Gemini 4 Flash unchanged. Flash-Lite counts, Pro does not, since MINIMAL is a Flash-tier level. Pro behaviour is untouched:minimalstays"low",mediumstays"high", andgemini-3.1-pro-previewkeeps itsmedium.thinkingLevelforreasoning_efforton the rolling alias, before and after:gemini-flash-latestbeforegemini-pro-latestminimallowminimallow, unchangednone/disablelowminimallow, unchangedmediumhighmediumhigh, unchangedlow/highVerification at a190e6b, pinned
ruff==0.15.3perpyproject.toml:pytest tests/test_litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.pyis 150 passed, up from 146 at a686f36, the four new tests being the added onespytest tests/test_litellm/llms/vertex_ai tests/test_litellm/google_genai/test_google_genai_transformation.pyis 41 failed, 1305 passed at a190e6b against 41 failed, 1301 passed at a686f36: the same 41 pre-existing environment failures either side, +4 from this commitruff format --checkandruff checkon the changed source file both report clean, matching a686f36 exactlyE712findings to the test file, the same rule and the same== Truestyle as the 28 already there, including the ones added earlier in this PRbasedpyrightreports 803 errors at a190e6b and 803 at a686f36 on the changed source file, so the budget ceiling does not moveThe live-API Before/After above was run at a686f36 and is not re-run for this commit: it exercises the thought-signature replay, which this commit does not touch. This commit changes only which
thinkingLevelis selected. The fullmake lintwas likewise not re-run here; the gates this commit could plausibly move areruff format,ruff checkand the basedpyright budget, all three reported above against the same baseline.The diff stays minimal on purpose: the local
is_gemini3flashname is left as it was at both call sites rather than renamed to match the helper, and the test file takes pure additions with no edits to existing tests.Type
🐛 Bug Fix
Caveats (if any)
idforwarding andv1alphafor these aliasesFinal Attestation