Skip to content

feat(ai): honor responseJsonSchema in chrome adapter#9900

Draft
ryanwilson wants to merge 1 commit intomainfrom
feature/chrome-adapter-schema
Draft

feat(ai): honor responseJsonSchema in chrome adapter#9900
ryanwilson wants to merge 1 commit intomainfrom
feature/chrome-adapter-schema

Conversation

@ryanwilson
Copy link
Copy Markdown
Member

This PR adds support for structured JSON output in the Chrome on-device adapter by honoring the responseJsonSchema configuration.

Changes:

  • Updated ChromeAdapterImpl in packages/ai/src/methods/chrome-adapter.ts to map request.generationConfig.responseJsonSchema to the responseConstraint option when calling the Chrome Prompt API (prompt and promptStreaming).
  • Added unit tests in chrome-adapter-browser.test.ts to verify that the schema is correctly passed through to the underlying browser API.
  • Tested in a sample app update in feat: Add hybrid inference and structured output support to sample app quickstart-js#998

@ryanwilson ryanwilson requested a review from a team as a code owner April 28, 2026 13:29
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 28, 2026

⚠️ No Changeset found

Latest commit: 65c9574

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

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 introduces support for responseJsonSchema in the ChromeAdapterImpl by mapping it to the responseConstraint parameter for both standard and streaming content generation. It also includes unit tests to verify that the configuration is correctly passed to the underlying language model. Feedback suggests refactoring the duplicated mapping logic into a private helper method and extending support to the responseSchema field for better parity with cloud backends.

Comment on lines +159 to +162
const promptOptions = { ...this.onDeviceParams.promptOptions };
if (request.generationConfig?.responseJsonSchema) {
promptOptions.responseConstraint = request.generationConfig.responseJsonSchema;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The logic for merging generationConfig.responseJsonSchema into promptOptions is duplicated in both generateContent and generateContentStream (lines 183-186). This logic should be refactored into a private helper method to improve maintainability and ensure consistency as more configuration fields are mapped in the future.

Comment on lines +160 to +162
if (request.generationConfig?.responseJsonSchema) {
promptOptions.responseConstraint = request.generationConfig.responseJsonSchema;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

While this PR correctly adds support for responseJsonSchema, the adapter currently ignores responseSchema from generationConfig. For better parity with the cloud backend and to support users using the Schema builder, consider also mapping responseSchema to responseConstraint if it is a plain object (i.e., SchemaRequest).

@ryanwilson ryanwilson marked this pull request as draft April 28, 2026 13:59
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.

1 participant