Documentation
¶
Overview ¶
Recipe 06: Structured JSON Output
Use grammar-guided decoding to guarantee the model outputs valid JSON that conforms to a schema. This eliminates the need for fragile regex parsing or retry loops when you need structured data from a language model.
Two approaches are shown:
- High-level: zerfoo.WithSchema (recommended for most use cases)
- Low-level: grammar.Convert + inference.WithGrammar (for custom pipelines)
Usage:
go run ./docs/cookbook/06-structured-json-output/ --model path/to/model.gguf go run ./docs/cookbook/06-structured-json-output/ --model path/to/model.gguf --low-level
Click to show internal directories.
Click to hide internal directories.