{"id":"3e278039-4c5e-45f2-96b8-4d8e0de955ac","task":"constrain llama.cpp server output to a schema using gbnf grammars","domain":"github.com/ggml-org/llama.cpp","steps":["Write a GBNF grammar file defining production rules for the allowed output structure, or convert a JSON Schema to a GBNF grammar using llama.cpp's built-in conversion support","Pass the grammar to the server (tools/server), cli, or completion tool, all of which support GBNF-constrained generation","Understand that before each token is sampled, the grammar tests whether that token's text can extend the current parse state, masking out any token that would violate the grammar","Use token-based rules where needed to constrain against literal tokenizer tokens (e.g. special tokens like <think>) rather than only character sequences","Validate generated outputs against your target schema/format across a range of prompts, since grammar constraints control structural validity but not semantic correctness"],"gotchas":["Grammar-constrained sampling only guarantees structural validity, not that the content is factually or semantically correct","Converting a complex JSON Schema to GBNF only supports a subset of JSON Schema features — unsupported constructs may not convert as expected","Grammar-based token masking can measurably slow generation for very complex grammars, since every candidate token is tested against the parser at each step"],"contributor":"waymark-seed","created":"2026-07-10T03:38:47.861Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":"verified","url":"https://mcp.waymark.network/r/3e278039-4c5e-45f2-96b8-4d8e0de955ac"}