Skip to content

feat(ai): Add responseJsonSchema#9693

Merged
DellaBitta merged 4 commits intomainfrom
ch-jsonschema
Mar 17, 2026
Merged

feat(ai): Add responseJsonSchema#9693
DellaBitta merged 4 commits intomainfrom
ch-jsonschema

Conversation

@hsubox76
Copy link
Copy Markdown
Contributor

@hsubox76 hsubox76 commented Mar 5, 2026

Adds responseJsonSchema field, which takes an object in JSON Schema format.

Gemini docs examples show how to use the zod library to easily generate this object (https://ai.google.dev/gemini-api/docs/structured-output?example=recipe), and we should follow this with an example of how to do the same, somewhere in the Firebase guides. Maybe this page? https://firebase.google.com/docs/ai-logic/generate-structured-output?api=dev

Tested manually with Developer API and Vertex and both work.

Doc changes: Added text for responseJsonSchema and used @remarks to remove bulk of text of both responseSchema and responseJsonSchema from table of contents (full text is still in the section below).

Fixes #9625

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 5, 2026

🦋 Changeset detected

Latest commit: f67f7f5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@firebase/ai Minor
firebase Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@gemini-code-assist
Copy link
Copy Markdown
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 introduces enhanced flexibility for defining structured output in AI model responses by adding support for standard JSON Schema. Users can now specify the expected format of generated content using the responseJsonSchema field, providing a powerful alternative to the existing responseSchema. This change aims to simplify the integration of AI-generated structured data into applications, aligning with common industry practices for data validation and serialization.

Highlights

  • New Feature: responseJsonSchema: Added a new responseJsonSchema field to the GenerationConfig interface, allowing users to define structured output using standard JSON Schema.
  • Mutual Exclusivity Validation: Implemented a validation check to ensure that responseJsonSchema and the existing responseSchema cannot be used simultaneously within the same GenerationConfig.
  • API Documentation and Types: Updated the API review file and the requests.ts type definitions to include the new responseJsonSchema field and its associated documentation.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • .changeset/sharp-kiwis-push.md
    • Added a new changeset entry for the responseJsonSchema feature.
  • common/api-review/ai.api.md
    • Included responseJsonSchema in the GenerationConfig interface definition.
  • packages/ai/src/models/generative-model.ts
    • Introduced a validation check to prevent simultaneous use of responseSchema and responseJsonSchema.
  • packages/ai/src/types/requests.ts
    • Defined the responseJsonSchema property within the GenerationConfig interface, including its documentation.
Activity
  • No human activity has occurred on this pull request yet.
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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 5, 2026

Vertex AI Mock Responses Check ⚠️

A newer major version of the mock responses for Vertex AI unit tests is available. update_vertexai_responses.sh should be updated to clone the latest version of the responses: v16.2

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 5, 2026

Changeset File Check ✅

  • No modified packages are missing from the changeset file.
  • No changeset formatting errors detected.

Copy link
Copy Markdown
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 the responseJsonSchema field to GenerationConfig as an alternative to responseSchema for specifying the output format using JSON Schema. The changes include updating the type definitions, API report, and adding validation to prevent simultaneous use of responseSchema and responseJsonSchema. My review includes a suggestion to add further validation to ensure that responseMimeType is correctly set when responseJsonSchema is used, as per the documentation.

@hsubox76 hsubox76 marked this pull request as ready for review March 10, 2026 18:05
@hsubox76 hsubox76 requested review from a team as code owners March 10, 2026 18:05
@hsubox76 hsubox76 requested a review from DellaBitta March 10, 2026 20:37
@DellaBitta DellaBitta merged commit 843a8d7 into main Mar 17, 2026
36 of 37 checks passed
@DellaBitta DellaBitta deleted the ch-jsonschema branch March 17, 2026 14:49
@google-oss-bot google-oss-bot mentioned this pull request Mar 17, 2026
@milo-
Copy link
Copy Markdown

milo- commented Mar 30, 2026

@rachelsaunders @DellaBitta @hsubox76 This PR introduces a critical bug which makes it impossible to use responseSchema:

    (generationConfig.responseSchema != null ||
      generationConfig.responseJsonSchema != null) &&
    generationConfig.responseMimeType
  ) {
    throw new AIError(
      AIErrorCode.UNSUPPORTED,
      `responseMimeType must be set if responseSchema or responseJsonSchema are set.`
    );
  }

This block should be checking generationConfig.responseMimeType !== "application/json". Additionally this error message should be explicit about the required value.

@hsubox76
Copy link
Copy Markdown
Contributor Author

Thanks, making a PR to fix. Our next planned release is Apr 9. In the short term, users experiencing this problem should roll back to the previous version (12.10.0), or use patch-package or a similar solution and make the code change in the comment above if you need features in 12.11.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FR: add responseJsonSchema to GenerationConfig type

4 participants