Expand description
JSON Schema emitter for submilli:llm typed output.
llm.call<T>() sends a JSON Schema for T to the provider so the model is
constrained to the shape the program asked for. The schema is advisory —
every response is still verified by our own structural check — so the job
here is to describe T in the narrow dialect every provider agrees on, and
to refuse at compile time anything that dialect cannot carry.
Every definition is inlined; $ref/$defs are never emitted. Google’s
provider strips $ref, silently degrading the referenced subschema to “any”
— the response then validates against nothing. A recursive type has no
finite inlining, so it is a compile error here rather than a ref.
The emitter carries its own gate rather than deferring to
unsupported_cast_target_reason. The two agree on most variants but differ
where it matters: the cast gate accepts Unknown (the runtime widen is a
no-op), while a schema for unknown could only be {} — the same silent
degeneration to “any” that $ref is rejected for. See SchemaReject.
Structs§
- Schema
Reject - A type that has no JSON Schema in the safe subset.
Functions§
- json_
schema - Emit an inlined JSON Schema for
ty, or name the first field that has none. - json_
schema_ with - Like
json_schemabut resolves recursion back-edges (Type::AliasRef) one level throughexpand. A back-edge that expands to a type already open on the walk is a genuine cycle and is rejected.
Type Aliases§
- Alias
Expander - One-level expander for recursion back-edges, mirroring
json_strategy::AliasExpander. Given aType::AliasRefit returns the alias body (args substituted); for any other type it returnsty.peel()cloned. Lets the emitter resolve a named alias without owning the type namespace.