← [ ABORT TO HUD ]
SEQ. 1
GBNF, Outlines, and Logit Masking
Zero-Shot Guaranteed Syntactic Validity
Prompt engineering alone cannot guarantee that an LLM will return valid JSON. If an agent outputs a trailing comma, missing quotation mark, or unescaped newline, the downstream parser crashes.
Grammar-Constrained Decoding solves this problem at the tokenizer level:
- A formal grammar (such as GBNF or a JSON Schema parsed into a Context-Free Grammar) is compiled into a Deterministic Finite Automaton (DFA).
- At each token step, before the model samples its next token, the harness evaluates which token IDs would violate the grammar.
- Invalid token logits are masked to (-infty). The model is physically incapable of emitting a syntax error.
⌨ HANDS-ON LABCompile JSON Schema into GBNF Grammar
⭐ +200 XPConvert a JSON Schema into a bitmask automaton and verify zero-syntax-error generation.
1Compile target JSON Schema into a grammar DFA bitmask.
2Execute constrained generation and check token validation.
OBJECTIVE 1 / 2 — type "hint" if stuck
SYNAPSE VERIFICATION
QUERY 1 // 1
At what point in the generation pipeline does grammar-constrained decoding enforce validity?
After the entire response is finished by re-prompting on failure
During model pre-training
At every generation step by setting the logits of invalid tokens to -infinity before sampling
In the database storage layer