Master Guidance with our step-by-step tutorial, detailed feature walkthrough, and expert tips.
Install Guidance via pip install guidance and set up your preferred model backend (Transformers for local models, OpenAI API key for GPT
4, or Anthropic API key for Claude) Start with the basic tutorial: create a simple template using gen() for text generation and select() for constrained choices, then run it in a Jupyter notebook to see the interactive visualization Practice with JSON schema generation by defining a Pydantic model and using guidance.json() to generate structured data that validates against your schema Explore the examples repository on GitHub for real
world use cases like HTML generation, structured interviews, and multi
step reasoning pipelines to understand advanced patterns
💡 Quick Start: Follow these 4 steps in order to get up and running with Guidance quickly.
Explore the key features that make Guidance powerful for ai agent builders workflows.
Define templates that mix fixed text with generation slots. The model generates only in specified locations, with template text serving as guaranteed context that cannot be modified. Variables capture generated values for downstream use in multi-step workflows.
Implement any context-free grammar for output control. Use regex patterns, selection from predefined lists, or complex nested structures. Works with both local models (logit masking) and API models (optimized prompting).
Automatically corrects tokenization artifacts that occur when template text ends mid-token. Prevents garbled output when template text ends mid-token, a common issue with standard LLM approaches.
Generate structured JSON with guaranteed schema compliance using Pydantic models. Supports complex schemas with oneOf, allOf, required properties, min/max constraints, and format validation for production data extraction.
State-of-the-art performance for constraint processing using the llguidance Rust library. Delivers significant speed improvements and fixes subtle bugs from the earlier Python implementation.
Implement conditional generation with if/else blocks and iterative generation with loops. The model can generate variable-length lists, make programmatic branching decisions, and handle complex multi-step logic.
Unified interface for local models (Transformers, llama.cpp with true constrained generation) and API models (OpenAI GPT-4, Anthropic Claude, Azure OpenAI with optimized prompting strategies).
Rich notebook visualization showing token probabilities, backtracking support, generation metrics, real-time model behavior, and dark mode support for interactive development workflows.
Grammar constraints often make some tokens predictable in advance. Guidance automatically inserts these tokens without model forward passes, reducing GPU usage and generation latency significantly.
Create reusable @guidance decorated functions that can be composed into complex grammars. Build libraries of generation patterns for specific domains like HTML generation, form filling, or structured interviews.
Now that you know how to use Guidance, it's time to put this knowledge into practice.
Sign up and follow the tutorial steps
Check pros, cons, and user feedback
See how it stacks against alternatives
Follow our tutorial and master this powerful ai agent builders tool in minutes.
Tutorial updated March 2026