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.

Level: advancedTopic: Prompt context engineering

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

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.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.