What is GBNF and how to use it
mainGBNF (GGML BNF) is a format used to constrain model outputs in llama.cpp by defining formal grammars. It allows you to force models to follow specific structures, such as valid JSON, specific notation (like chess moves), or restricted character sets (like emojis).
GBNF grammars can be applied via:
llama-cliandllama-completionusing the--grammaror--grammar-fileflags.llama-servercompletion endpoints by passing agrammarfield in the request body.
To test a grammar file with the CLI, use:
./llama-cli -m <model> --grammar-file grammars/some-grammar.gbnf -p 'Some prompt'