Conversation
The Dart Picoschema converter treated `field(array)`, `field(object)` and `field(enum)` qualifiers as descriptions, so `tags(array): string` became a string schema. Some schemas also skipped conversion entirely because `isPicoschema` only recognized bare primitive values. The converter now follows the JS reference implementation: - `(array|object|enum[, description])` qualifiers, `(*)` wildcards and optional-is-nullable semantics match the spec. - Top-level JSON Schema (`type`, bare `properties`) is passed through. - Named schemas resolve via `schemas` and then `DotpromptOptions.schemaResolver` (new `Picoschema.parse`). - Invalid input throws `PicoschemaException` (free-text parentheses, `name(*)`, `string[]`, `a | b`, type aliases, unknown schema names). The spec runner now checks `output` and named `schemas`, so spec/picoschema.yaml is enforced (9 of 18 cases failed before). ISSUE: genkit-ai/genkit-dart#562 CHANGELOG: - [x] Fix Picoschema `(array)`, `(object)`, `(enum)` and `(*)` handling - [x] Add `Picoschema.parse` with async `schemaResolver` support - [x] Make Picoschema strict, matching other runtimes
huangjeff5
reviewed
Oct 3, 2026
Collaborator
|
This package is
I suggest |
huangjeff5
approved these changes
Oct 3, 2026
Collaborator
Author
Good catch, updated both the API docs and the README to |
Treat top-level anyOf/oneOf/allOf/enum lists, list-valued type, items and $defs as JSON Schema so they are not misparsed as Picoschema (e.g. via additionalMetadata). Keywords are matched by value shape so Picoschema fields named items/enum still parse.
Tighten JSON Schema detection so Picoschema fields that coincide with JSON
Schema keywords are converted instead of passed through raw:
- `items`/`$defs` with a map value no longer imply JSON Schema.
- A scalar `type` only implies JSON Schema when all siblings are JSON Schema
keywords whose values are not Picoschema type strings, so
`{type: string, payload: string}` is a Picoschema object.
- `properties` only implies JSON Schema when its values are JSON Schemas.
- Picoschema key syntax (`a?`, `a(array)`, `(*)`) always means Picoschema.
Also:
- `input: Name` / `output: Name` resolves the named schema instead of
producing a raw `{$ref: Name}`.
- Duplicate property names (`a` and `a?`) throw.
- `x?: null` yields `{type: null}` instead of `[null, null]`.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes genkit-ai/genkit-dart#562
The Dart Picoschema converter treated parenthesized qualifiers as descriptions, so
tags(array): stringproduced{type: string, description: "array"}. Some schemas also skipped conversion entirely (raw Picoschema was sent to the model) becauseisPicoschemaonly recognized bare primitive values. The spec runner never comparedoutput, sospec/picoschema.yamlreported "all pass" while 9 of its 18 cases were actually wrong.The converter now follows the JS reference implementation.
Changes
picoschema.dart: rewritten to mirrorjs/src/picoschema.ts:(array|object|enum[, description])qualifiers and(*)wildcards per spec; optional fields are nullable.type: ..., bareproperties) is passed through.Picoschema.parse(schema, {schemas, schemaResolver})resolves named schemas fromschemasfirst, then the async resolver.toJsonSchemastays sync.Dotprompt._resolveMetadataalways converts viaPicoschema.parse, soDotpromptOptions.schemaResolveris now used for named schemas (it was ignored before).spec_test.dartchecksoutputand passes the spec'sschemas:.picoschema_test.dart: ports the JS cases and adds a regression group for genkit-dart#562.age: integer?->age?: integer) and replacedgemini-proin examples.Behavior changes (strict, like other runtimes)
These now throw
PicoschemaException:Intentional deviations from JS (commented in code): a top-level
anyyields{}(JS yields the invalid{type: "any"}), andtoJsonSchema(null)still returns{type: object}.Testing
dart analyze: clean;dart test: 237 passing.packages/genkit/test/ai/prompt_test.dartpasses (141) against this branch via a local path override.Follow-up in genkit-dart after publishing: bump to
dotprompt: ^1.1.0, optionally usePicoschema.parsewith the registry resolver inprompt_loader_io.dart, and add an(array)output to thetestapps/promptssample.