Skip to content

fix(cli): validate --model argument at startup#21393

Merged
Adib234 merged 6 commits intogoogle-gemini:mainfrom
JaisalJain:fix/validate-model-flag
Mar 12, 2026
Merged

fix(cli): validate --model argument at startup#21393
Adib234 merged 6 commits intogoogle-gemini:mainfrom
JaisalJain:fix/validate-model-flag

Conversation

@JaisalJain
Copy link
Contributor

@JaisalJain JaisalJain commented Mar 6, 2026

Summary

Validate the --model CLI argument during startup to prevent invalid model names from being accepted.

Previously the CLI would start normally even when an invalid model was provided (e.g. gemini --model gemini-4-pro). The error would only appear later when sending a request, which could confuse users.

This change validates the model name early and exits with a clear error message if the model is invalid.

Details

The validation checks the provided --model argument against the VALID_GEMINI_MODELS list and known aliases.

If the model name is invalid, the CLI exits early and prints a list of valid models and aliases to guide the user.

Related Issues

Fixes #21391

How to Validate

  1. Run the CLI with an invalid model
npm run start --workspace @google/gemini-cli -- --model gemini-4-pro

Expected result:

Invalid model: "gemini-4-pro"

  1. Run with a valid model
npm run start --workspace @google/gemini-cli -- --model gemini-3-pro-preview

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • [] npx
      • Docker

@JaisalJain JaisalJain requested a review from a team as a code owner March 6, 2026 12:42
@google-cla
Copy link

google-cla bot commented Mar 6, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the command-line interface's robustness and user experience by introducing early validation for the --model argument. Instead of allowing the CLI to start with an invalid model and fail later, it now proactively checks the model name at startup. This change provides immediate, actionable feedback to users, guiding them towards correct usage and preventing confusion caused by delayed errors.

Highlights

  • Early CLI Model Validation: The CLI now performs immediate validation of the --model argument during startup, ensuring that only valid model names or aliases are accepted before proceeding.
  • Enhanced User Feedback: Invalid model inputs are now caught at the earliest stage, providing users with a FatalConfigError that includes a clear message and a comprehensive list of valid models and aliases.
Changelog
  • packages/cli/src/config/config.ts
    • Imported isValidModelOrAlias and getValidModelsAndAliases from @google/generative-ai-core.
    • Implemented logic within loadCliConfig to validate the specifiedModel argument.
    • Introduced a FatalConfigError to be thrown if an invalid model is detected, providing a user-friendly error message with a list of valid options.
  • packages/core/src/config/models.ts
    • Added isValidModelOrAlias function to determine if a given string corresponds to a valid Gemini model, alias, or a non-Gemini custom model.
    • Added getValidModelsAndAliases function, which returns a sorted array of all recognized model names and aliases for display in error messages.
Activity
  • The pull request introduces early validation for the --model CLI argument.
  • It includes new utility functions for model validation and listing valid models/aliases.
  • The author has validated the changes on Linux using npm run.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds startup validation for the --model argument, which is a great improvement for user experience. My feedback focuses on a small refactoring opportunity in packages/core/src/config/models.ts to reduce code duplication and improve maintainability by defining the list of model aliases in a single place.

@JaisalJain
Copy link
Contributor Author

@google-cla please recheck

@gemini-cli gemini-cli bot added the area/core Issues related to User Interface, OS Support, Core Functionality label Mar 6, 2026
@JaisalJain
Copy link
Contributor Author

@gemini-code-assist Thanks for the suggestion! I've refactored the code to use a shared VALID_ALIASES constant and removed the duplicated alias list.

@gemini-code-assist
Copy link
Contributor

That's great to hear, JaisalJain! Centralizing the VALID_ALIASES constant is an excellent improvement for maintainability and consistency across the codebase. Thanks for implementing that!

@Adib234 Adib234 self-assigned this Mar 6, 2026
@Adib234
Copy link
Contributor

Adib234 commented Mar 6, 2026

This looks good! Can we add tests please

@JaisalJain
Copy link
Contributor Author

This looks good! Can we add tests please

Thanks for reviewing! I'll add tests for the validation behavior and update the PR shortly.

@JaisalJain
Copy link
Contributor Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses the issue of validating the --model argument at startup by introducing early validation. The implementation is clean, and the new error messages are user-friendly, listing all valid models and aliases. The addition of comprehensive unit tests for the new validation logic is also a great inclusion. I've identified one area for improvement to make the code more robust for the future.

@JaisalJain
Copy link
Contributor Author

@Adib234 I've added the tests. Could you please take another look?

@Adib234 Adib234 enabled auto-merge March 10, 2026 14:12
auto-merge was automatically disabled March 11, 2026 16:34

Head branch was pushed to by a user without write access

@JaisalJain JaisalJain requested review from a team as code owners March 11, 2026 16:34
@JaisalJain JaisalJain force-pushed the fix/validate-model-flag branch from 531662c to a04f5d2 Compare March 11, 2026 16:38
@JaisalJain JaisalJain requested a review from Adib234 March 11, 2026 16:39
@JaisalJain
Copy link
Contributor Author

JaisalJain commented Mar 11, 2026

@gemini-code-assist review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively adds startup validation for the --model argument, which is a great improvement for user experience. However, the PR includes an accidentally added file (treamq) and some problematic test snapshot updates that should be removed. Additionally, there's a small bug in the new getValidModelsAndAliases function that results in duplicate model names being listed in the error message. I've left comments with suggestions for these issues.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@JaisalJain
Copy link
Contributor Author

@gemini-code-assist review

@Adib234 Adib234 added this pull request to the merge queue Mar 12, 2026
Merged via the queue into google-gemini:main with commit 34709dc Mar 12, 2026
27 checks passed
liamhelmer pushed a commit to badal-io/gemini-cli that referenced this pull request Mar 12, 2026
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gemini-cli accepts invalid model names with --model flag

2 participants