guidance

Control LLM output with regex constraints, grammars, and token healing for structured generation.

Updated Apr 18, 2026
One-click install
npx skills add https://github.com/azaanaliraza/operarius --skill guidance-azaanaliraza
Or copy as Structured Prompt for Agentâ–¼
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/azaanaliraza/operarius/tree/main/src-tauri/bin/hermes/optional-skills/mlops/guidance
Command: npx skills add https://github.com/azaanaliraza/operarius --skill guidance-azaanaliraza

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires guidance, transformers, and includes references (resource) components.

What problem does it solve? LLMs frequently produce malformed JSON, invalid dates, or off-format text that breaks downstream parsing and forces retry loops. This Skill uses Microsoft Research's Guidance framework to constrain generation at the token level so outputs always match the required format. ## Core Features & Use Cases - Regex and Grammar Constraints: Enforce valid emails, dates, phone numbers, JSON, XML, and code syntax during generation so invalid tokens are never produced. - Token Healing: Automatically repairs tokenization boundaries between prompt and generation to eliminate spacing artifacts. - Multi-Step Workflows and Agents: Build ReAct agents, chain-of-thought reasoning, and classification pipelines with Pythonic control flow via the @guidance decorator. - Use Case: Extract structured entities (name, date, email) from unstructured customer messages and receive guaranteed-valid JSON that loads directly into your database without validation retries. ## Quick Start Ask the AI to generate a JSON user profile with name, age, and email fields using Guidance regex constraints so the output is guaranteed to be valid.

Frequently Asked Questions about guidance

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I guarantee valid JSON output from an LLM?â–¼

Use Guidance's gen function with regex constraints for each JSON field, or define a grammar-based template with the @guidance decorator. Invalid tokens are filtered during generation, so the output always parses correctly without retry loops.

What is token healing in Guidance?â–¼

Token healing backs up one token at the prompt-generation boundary and regenerates it together with the new output. This prevents artifacts like double spaces or broken words caused by tokenization boundaries, and it is enabled by default.

Guidance vs Instructor vs Outlines for structured output?â–¼

Guidance supports regex constraints, context-free grammars, and token healing with Pythonic syntax. Instructor is better for Pydantic validation with automatic retrying, while Outlines fits JSON schema validation workflows.

Does Guidance work with local models like llama.cpp?â–¼

Yes, Guidance supports local models through the Transformers and LlamaCpp backends, including GGUF quantized models with GPU offloading. It also works with Anthropic, OpenAI, and Azure OpenAI APIs.

Why is constrained generation slower than free generation?â–¼

Regex constraints add roughly 1.2-1.5x overhead and grammars about 2x because tokens must be filtered against the pattern. However, end-to-end latency is often lower since no validation retries are needed.

When should I use select() instead of gen()?â–¼

Use select() when the output must be one of a fixed set of categories, such as sentiment labels or status values. It is the fastest constraint type and eliminates any possibility of typos or invalid values.