Schema-Driven Hierarchical Decoding¶
Constrained generative decoding method — instantiates Grammar-Guided Structure Recovery
Generates hierarchical structure with a model while a schema masks every ill-formed continuation at decode time, so the output is well-formed by construction rather than validated after the fact.
Schema-Driven Hierarchical Decoding is the generative member of the family. Instead of recovering structure from a fixed input by search, it produces structure with a model — a sequence model or LLM — while a schema or grammar constrains generation token by token, so the decoder can only emit continuations that keep the output well-formed. The idea that sets it apart from its parser siblings is where the grammar bites: well-formedness is enforced inline, as a hard constraint during generation — every candidate next-token that would violate the schema is masked out before the model chooses — rather than checked after the fact. It is the archetype's disciplined answer to "ungoverned model inference": the model supplies content, the schema supplies shape, and the two are fused at each step so malformed output is not rejected but is impossible to emit.
Example¶
A back-office tool turns a free-text shipping note — "2 pallets of size-9 boots, deliver to Dock C by Fri" — into a record matching a fixed JSON Schema, { items: [{ qty, sku }], dock, due }. The decoder generates the JSON one token at a time, but at each step a mask compiled from the schema admits only tokens that keep the partial output valid: after {"items":[{"qty": only a number may follow; after a complete item object, only , or ]. The model contributes the values (2, the boot SKU, "Dock C", a resolved date); the schema guarantees the frame. The result parses against the schema by construction — the whole failure class of "the model returned broken JSON" simply cannot occur — and a field the model was unsure of, like an ambiguous SKU, carries a low per-token decode confidence that flags it for review rather than passing silently.
How it works¶
What distinguishes schema-driven decoding is that validity is built in, not checked afterward:
- A generative model proposes; a schema disposes. At each step the model yields a distribution over next tokens, and a grammar/schema compiled into a mask zeroes out every continuation that would break well-formedness.
- Structure is produced, not searched. There is no fixed input string to recover a tree from — the hierarchy is emitted directly under constraint, often from unstructured or semi-structured source material.
- Validity by construction. Because illegal continuations are unreachable, the output conforms to the schema without a post-hoc parse or repair step.
- Confidence comes free. The model's per-token probabilities give a decode confidence for each emitted node, marking shaky fields.
Tuning parameters¶
- Constraint tightness — how much of the schema is enforced as a hard mask versus left soft for the model to satisfy. Tighter guarantees validity but can force the model into an awkward or wrong-but-valid output.
- Schema expressiveness — a flat field schema vs. a rich recursive grammar. Richer captures more structure but is costlier to compile into masks and can over-constrain generation.
- Sampling temperature — how freely the model explores within the allowed set — lower is safer and more deterministic; higher may fill ambiguous slots more naturally.
- Review threshold — the per-field decode confidence below which a value is flagged rather than trusted.
- No-valid-token fallback — what to do when no acceptable high-probability token exists under the mask: relax the constraint, backtrack, or emit an explicit null/unknown.
When it helps, and when it misleads¶
Its strength is eliminating an entire failure class: output is well-formed by construction, so there is never a "model emitted invalid structure" error to catch downstream, and unstructured input becomes schema-valid structure in a single governed step. Decode confidence surfaces the fields that deserve a second look.
It misleads because a hard constraint guarantees well-formed, not correct. The model can emit a perfectly schema-valid but factually wrong record, and — more insidiously — if the schema is too rigid the mask can remove the truthful token from the allowed set, forcing a confident wrong answer into the permitted shape.[1] The characteristic misuse is treating schema-validity as if it were semantic correctness — shipping the output because it parsed. The discipline is to pair the inline constraint with independent semantic validation and to treat low decode confidence as a review trigger, not noise.
How it implements the components¶
Schema-Driven Hierarchical Decoding fills the constrained-generation slice of the archetype's machinery:
composition_rule_grammar— it operates a schema/grammar as the generation constraint; the schema's composition rules define exactly which structures the decoder is permitted to produce.validation_rule— the schema's well-formedness rules are compiled into an inline decoding mask, so validation happens during generation rather than as a separate downstream check.confidence_score— the model's per-token probabilities yield a decode confidence for each emitted node, flagging low-confidence structure for review.
It does not recover structure from a fixed input by search — that is the parsers (Recursive-Descent Parsing, Shift-Reduce Parsing, Chart Parsing); it does not perform the independent, post-hoc semantic checking that catches valid-but-wrong output (Semantic Schema Validation); and it does not author or version the schema itself (Grammar Rule Set).
Related¶
- Instantiates: Grammar-Guided Structure Recovery — it produces structure under grammar constraint instead of recovering it from a fixed input.
- Consumes: Grammar Rule Set supplies the schema/grammar compiled into the decoding constraint.
- Sibling mechanisms: Semantic Schema Validation · Chart Parsing · Probabilistic Grammar Parsing · Recursive-Descent Parsing · Shift-Reduce Parsing · Error-Tolerant Parsing · Lexical Scanning and Tokenization · Round-Trip Parse–Serialize Testing · Grammar Rule Set · Ambiguity Register · Controlled Disambiguation Test · Interpretation Walkthrough · Invalid Combination Linter · Linting or Validation Rule
References¶
[1] Grammar-constrained (constrained) decoding restricts a generative model's next-token choices to those permitted by a formal grammar or schema, guaranteeing well-formed output. The guarantee is structural only: constraining the shape does nothing to ensure the content is true, and an over-tight grammar can exclude the correct token from the permitted set. ↩