-
Notifications
You must be signed in to change notification settings - Fork 10.9k
feat(cli): add --schema-file flag for custom JSON schema output #18032
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @medic-code, 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 Gemini CLI's capabilities for automation and integration by introducing a mechanism to enforce structured JSON output based on a user-defined schema. This allows external systems to reliably parse and process responses, making the CLI more adaptable for pipelines and orchestration. The changes also refine how tools interact with structured output, providing control over their execution based on the desired response format. Highlights
Using Gemini Code AssistThe 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
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 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
|
|
Build failed: Build process failed (no specific link errors found). Check logs for details. |
There was a problem hiding this 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 introduces a valuable feature, --schema-file, for enforcing a custom JSON schema on the model's output. The implementation is thorough, with changes spanning configuration, client logic, and API requests, all supported by a comprehensive suite of tests and updated documentation. The code quality is high, and the feature is well-designed for automation and integration scenarios. I've identified one high-severity issue concerning the handling of the file path provided to --schema-file. The path is used directly without resolution, which is inconsistent with other parts of the application and could lead to unexpected behavior. Additionally, the current implementation uses synchronous file system operations, which can block the event loop. I've provided a suggestion to resolve the path and use asynchronous file system operations for better robustness, consistency, and performance.
bc5c2c1 to
000996d
Compare
|
Build failed: Build process failed (no specific link errors found). Check logs for details. |
000996d to
8806068
Compare
|
Build failed: Build process failed (no specific link errors found). Check logs for details. |
8806068 to
43a95f9
Compare
- Add jsonSchema and enableTools to Config class - Add CLI argument parsing with validation - Validate schema file (size, JSON syntax, has type/properties) - Error on conflicting flags (schema + text output, enable-tools without schema)
- Add 13 tests for schema-file parsing, validation, and error cases
- Add 3 tests for loadCliConfig integration with schema
- Add 3 tests for tools disabled/enabled behavior in client.test.ts
- Fix mock configs to include getJsonSchema and getEnableTools methods
- Improve help descriptions for --schema-file and --enable-tools
- Fix typo in error message ("must have name" -> "must have")
- Remove unreachable empty object check
- Add --schema-file and --enable-tools to configuration options table - Add "Custom JSON Schema Output" section with usage examples - Document schema requirements and behavior
43a95f9 to
562cf06
Compare
|
Build failed: Build process failed (no specific link errors found). Check logs for details. |
1 similar comment
|
Build failed: Build process failed (no specific link errors found). Check logs for details. |
|
i see the docs-pr-check is failing, but can't really see any more details on my side. Let me know how i can help. |
Summary
Adds
--schema-fileflag to enable custom JSON schema output for headless/non-interactive mode. This allows users to define their own response structure for automation, orchestration, and pipeline integration.Details
New flags:
--schema-file <path>- Path to a JSON schema file for structured output--enable-tools- Re-enable tools when using--schema-file(tools disabled by default)Behavior:
--schema-fileimplies--output-format jsonautomatically--enable-toolsto re-enable tool execution with structured outputValidation:
typeorpropertiesfield--output-format textor--output-format stream-jsonExample usage:
Summary of Changes
packages/cli/src/config/config.ts--schema-fileand--enable-toolsyargs options with coerce validation, conflict checks, implied json outputpackages/core/src/config/config.tsjsonSchemaandenableToolsfields to Config class with getterspackages/core/src/core/client.ts--enable-tools)packages/core/src/core/geminiChat.tsresponseJsonSchemaandresponseMimeTypeto API request when schema is setpackages/cli/src/config/config.test.tspackages/core/src/core/client.test.tspackages/core/src/core/geminiChat.test.tspackages/core/src/core/geminiChat_network_retry.test.tsdocs/cli/headless.mdRelated Issues
Fixes #13388
How to Validate
Basic schema output:
Verify: JSON output matching schema, no tool calls
With tools enabled:
gemini --schema-file /tmp/test.json --enable-tools -p "List files"Verify: Tool calls allowed, structured JSON output
Error cases:
Pre-Merge Checklist