AI engineering glossary · Prompt context engineering
What is GBNF grammar?
GBNF grammar: A grammar format used by the llama.cpp inference project to describe allowed output patterns, based on Backus-Naur form. A model server reads it and only allows tokens that keep the text valid under the grammar, for example forcing JSON or a fixed list of answers.
GBNF grammar: an example
A GBNF rule 'root ::= "yes" | "no"' limits a local model's reply to one of two words.
Related terms
More Prompt context engineering terms
- Generated knowledge prompting
- Grammar-constrained decoding
- Grounding
- In-context learning
- Instruction following
- Instruction hierarchy
- Instructor library
- JSON mode
Where you learn it
GBNF grammar is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.