Guidance — Constrain LLM output with grammars; guarantee valid JSON
Guidance — Constrain LLM output with grammars; guarantee valid JSON
Start with meaning, then move to detail.
This lesson explains Guidance — Constrain LLM output with grammars; guarantee valid JSON as part of getting started with Hermes correctly. You will learn what it does, when it matters, and the smallest safe test that proves it works.
If you are new, do not memorize names. Focus on three questions: what problem does this solve, what access does it need, and how can you verify the result?
For practice, inspect the first example, identify its effects, run it on test data, and compare the result with the source claim.
For advanced readers, inspect Skill metadata, Reference: full SKILL.md, When to Use This Skill, then verify failure modes and version compatibility.
No prior experience is required; follow the steps on a safe test setup first.
A clear outcome before you read.
- Understand Guidance — Constrain LLM output with grammars; guarantee valid JSON without assumed prior knowledge.
- Separate the source description from what still needs testing in your environment.
- Read the first command and identify its inputs and outputs before copying it.
Short definitions before the details.
- Provider
- The service that runs or provides access and authentication to a model.
- Skill
- An instruction bundle that teaches Hermes a repeatable workflow without necessarily adding an external service.
Constrain LLM output with grammars; guarantee valid JSON
What does the source say, and in what order?
- 01Skill metadata
Start here to understand the core idea or structure.
- 02Reference: full SKILL.md
Read this after the foundation, then connect it to the previous step.
- 03When to Use This Skill
Read this after the foundation, then connect it to the previous step.
- 04Installation
Read this after the foundation, then connect it to the previous step.
- 05Quick Start
Read this after the foundation, then connect it to the previous step.
- 06Basic Example: Structured Generation
Read this after the foundation, then connect it to the previous step.
- 07Chat format with a local model
Read this after the foundation, then connect it to the previous step.
- 08Core Concepts
Read this after the foundation, then connect it to the previous step.
- 091. Context Managers
Read this after the foundation, then connect it to the previous step.
- 102. Constrained Generation
Finish here to verify the result and special cases.
Copy only after you understand the effect.
# Base installation
pip install guidance
# With specific backends
pip install guidance[transformers] # Hugging Face models
pip install guidance[llama_cpp] # llama.cpp models### Chat format with a local model
> **Constraint support requires local logit access.** Regex, `select()`, and
> grammar-based constrained generation only work with local backends
> (`Transformers`, `LlamaCpp`). Remote API backends (`OpenAI`, and Azure
> variants) support unconstrained `gen()` / chat only — they cannot enforce
> token-level constraints. guidance 0.3.x has no `models.Anthropic` class.## Core Concepts
### 1. Context Managers
Guidance uses Pythonic context managers for chat-style interactions.Read the first command and identify its inputs and outputs before copying it.
Match every command to your installed Hermes version, review the files and accounts it can reach, and use non-sensitive data for the first test. If this explanation differs from the source, the official source wins.