feat(tools): include structured output in exported .prompt files#5506
feat(tools): include structured output in exported .prompt files#5506chrisraygill wants to merge 3 commits into
Conversation
The Dev UI prompt export dropped the generation's output config, so a flow that used structured output lost its schema when exported. createPrompt now carries the output config through and writes it to the frontmatter, converting the JSON Schema to Picoschema. - Accept output in CreatePromptRequestSchema. - Map the output config onto the frontmatter, reading the schema from jsonSchema (generate action) or schema (model request), and mapping the JSON-producing formats onto json. - Add jsonSchemaToPicoschema to convert an object JSON Schema into the compact Picoschema form (required/optional, descriptions, enums, scalar and object arrays, nested objects, additionalProperties wildcards). Non-object top-level schemas pass through as raw JSON Schema, which Dotprompt also accepts. Server-side counterpart to the editable output config in the model runner: genkit-ai/genkit-ui#1919
There was a problem hiding this comment.
Code Review
This pull request adds support for mapping a generate request's output configuration onto .prompt frontmatter, converting JSON Schema to Picoschema. This includes schema updates, router integration, and helper functions to handle the conversion. Feedback on the changes suggests making the scalarType helper function more robust by safely handling null or undefined schemas to prevent potential runtime crashes.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Safely access the type in scalarType so a null or malformed property schema in `properties` falls back to `any` instead of throwing. Adds a regression test. Addresses review feedback on the picoschema converter.
MichaelDoyle
left a comment
There was a problem hiding this comment.
This is really cool.
Is the conversion code useful for other applications, besides dev ui generating dotprompts? I wonder if that code should live somewhere else. e.g. in the dotprompt library, and we just depend on it here.
| /** | ||
| * Maps a generate request's output config onto `.prompt` frontmatter, converting | ||
| * the JSON Schema to Picoschema. The frontmatter format is limited to | ||
| * json/text/media, so the JSON-producing formats (json, jsonl, array, enum) map |
There was a problem hiding this comment.
This is interesting -- so there is a mismatch between what can be done in code, and what dotprompt supports?
If so, whenever we do such a conversion, let's leave a comment in the produced dotprompt that explains.
e.g.) # converted from <type>
There was a problem hiding this comment.
JSON Schema to Picoschema conversion is lossy... Picoschema has a very limited subset of features.
There was a problem hiding this comment.
So, how do we think output format set to jsonl should work when converted to picoschema? What if the JSON schema includes unsupported features in picoschema?
Address review feedback: break the combined encode test into per-feature tests (enum, array of scalars, array of objects, nested object), split the text/media format test in two, and rename the null-property test to describe what it returns.
Summary
This is the server-side counterpart to the editable output config added to the model runner in genkit-ai/genkit-ui#1919. That PR lets you set structured output in the Dev UI model runner; this PR makes the Export to
.promptaction actually include it.Previously
createPromptdropped the generation'soutputconfig entirely, so a flow that used structured output lost its schema when exported. The exported front matter now includes the output, with the JSON Schema written as Picoschema.Before
After
What changed
CreatePromptRequestSchemanow acceptsoutput(it was being stripped by tRPC input validation before reaching the frontmatter).createPromptmaps the output config onto the frontmatter, reading the schema fromjsonSchema(generate action shape) orschema(model request shape), and mapping the JSON-producing formats (json,jsonl,array,enum) ontojson.jsonSchemaToPicoschemaconverts an object JSON Schema into the compact Picoschema form: required/optional (?), descriptions, enums, scalar and object arrays, nested objects, andadditionalPropertieswildcards. Non-object top-level schemas (a bare array or scalar) pass through as raw JSON Schema, which Dotprompt also accepts.Testing
genkit-tools/common/tests/utils/prompt_test.tscover the converter and the frontmatter mapping (15 cases).outputblock above.Notes
formatfield is limited tojson/text/media, sojsonl/array/enumexport asformat: jsonwith the schema preserved. Exact format fidelity could be a follow-up.Checklist