fix: warn on deprecated Gemini model alias
Summary
- warn when
LLMRegistry.new_llm()sees the deprecatedgemini-flash-latestalias - keep behavior unchanged: the configured model string is still passed through as-is
- add regression coverage for both plain and
gemini:-prefixed alias usage
Fixes #6010.
To verify
PYTHONPATH=src python -m pytest tests\unittests\models\test_models.py -qpython -m pyink --check src\google\adk\models\registry.py tests\unittests\models\test_models.pygit diff --check
Response from ADK Triaging Agent
Hello @he-yufeng, thank you for creating this PR!
We noticed a couple of items from our contribution guidelines that could be added to help the review process:
- Summary of Passed Pytest Results: Please include the console output or a summary showing that the tests passed successfully when running
pytest. - Logs or Screenshots: For bug fixes or features, please provide logs or a screenshot of the fix in action (for example, showing the deprecation warning being logged when the deprecated alias is used).
This additional context will help the reviewers understand and verify the fix more efficiently. Thank you!
🔍 ADK Pull Request Analysis: PR #6011
Title: fix: warn on deprecated Gemini model alias
Author: @he-yufeng
Status: open
Impact: 35 additions, 0 deletions across 2 files
Executive Summary
- Core Objective: Warn users early when LLMRegistry.new_llm() is called with a deprecated Gemini alias (specifically
'gemini-flash-latest'), advising them to transition to versioned models (like'gemini-2.5-flash') before experiencing runtime crashes. - Justification & Value:
Justified Fix- Startup validation warnings prevent downstream404 NOT_FOUNDclient crashes during agent execution, heavily improving debugging/logging clarity on platform deployments like Cloud Run. - Alignment with Principles:
Pass- Features clean, private encapsulation boundaries, lazy key-evaluation logs, strict typing, and comprehensive behavior-focused parametrized unit tests. - Recommendation:
Approve(Zero changes or pushback needed).
Detailed Findings & Analysis
1. Objectives & Impact ("What does it do?")
- Context & Background: Resolves Issue #6010. When older apps or tutorials make use of the
gemini-flash-latestalias, the underlying backend (which maps it togemini-2.0-flash) has been deprecated by Google. This surfaces as a silent404 NOT_FOUNDerror far down the agent invocation chain, confounding developers because the error message mentionsgemini-2.0-flashwhich they did not explicitly configure. - Implementation Mechanism:
- Defines the map
_deprecated_model_aliasesmapping'gemini-flash-latest'to'gemini-2.5-flash'. - Implements the private helper method _warn_if_deprecated_alias that checks if the resolved model matches any entry in
_deprecated_model_aliasesand emits a warning on a match. - Plugs _warn_if_deprecated_alias into LLMRegistry.new_llm() immediately after model-parsing.
- Defines the map
- Affected Surface: No public namespace changes or API stability concerns; purely logs warnings.
2. Justification & Value ("Is it a valid and useful change?")
- Workspace Verification:
- Investigated registry.py in the active workspace.
- Confirmed that baseline lacks explicit alias validation or deprecation warning checks when resolving or instantiating aliases like
gemini-flash-latest.
- Value Assessment: Highly valuable. Early reporting at creation/configuration time greatly simplifies troubleshooting configuration bugs.
- Alternative Approaches:
- Silently upgrading the string mapping internally: Decided against because versioned Gemini engines might exhibit minor quality differences; forcing auto-replacement can cause unwanted behavioral shifts. Emitting a warning leaves the control safely with the developer.
- Scope & Depth:
Systematic Fix/Root Cause- Resolves the systemic feedback problem for deprecated aliases by establishing an extensible_deprecated_model_aliasesdictionary pattern for simple future updates.
3. Principle & Style Alignment Checklist ("Does it follow rules?")
- Public API & Visibility Boundaries:
- Status:
Pass - Analysis: Keeps both
_deprecated_model_aliasesand_warn_if_deprecated_aliasprivate to registry.py ensuring no public-facing changes to existing interfaces.
- Status:
- Code Quality, Typing & Conventions:
- Status:
Pass - Analysis: Consistently imports futurized annotations via
from __future__ import annotationsand type-hints parameters correctly. Strictly relies on lazy-evaluated logging templates (uses%format specifiers rather than eagerf-stringsinlogger.warning).
- Status:
- Robustness & Edge Cases:
- Status:
Pass - Analysis: Properly processes plain aliases as well as those containing prefixed tags (like
gemini:gemini-flash-latest) through the parser prior to execution.
- Status:
- Test Integrity & Quality:
- Status:
Pass - Analysis: Introduces test_new_llm_warns_for_deprecated_model_alias which parameterizes test cases, intercepts log entries with
caplog, verifies type correctness toGemini, and checks message contents under the Arrange-Act-Assert format.
- Status:
Hit this exact issue while building a multi-agent app for the ADK Hackathon — gemini-flash-latest silently mapping to a deprecated model caused confusing 404s on Cloud Run that were hard to trace back to the alias.
The startup warning in LLMRegistry.new_llm() is exactly the right fix — catches it early, no behavior change. Clean and minimal. Hope this gets merged soon!
Hi @he-yufeng , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Your PR has been received by the team and is currently under review. We will provide feedback as soon as we have an update to share.
Rebased this on current main and re-ran the focused local checks:
PYTHONPATH=src python -m pytest tests\unittests\models\test_models.py -q --basetemp .tmp\pytest-6011 -p no:cacheprovider-> 28 passedpython -m py_compileon the touched filespython -m pyink --checkon the touched filesgit diff --check origin/main..HEAD
All passed locally.
Thanks for tackling #6010! We're going to pass on this one. We'd rather not maintain a static alias list, and the dynamic models.list() approach doesn't work as a signal (it only returns fully-versioned IDs, so it false-flags valid aliases like gemini-2.0-flash and *-latest, and varies by backend/region). We'll rely on the backend 404, which already reports the model as unavailable.