guidance

Constrain LLM output with regex and grammars to generate valid JSON, XML, and structured formats.

Updated Jun 7, 2026
One-click install
npx skills add https://github.com/Chensihakniroth/ANAKOT-AGENT --skill guidance-chensihakniroth
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/Chensihakniroth/ANAKOT-AGENT/tree/main/optional-skills/mlops/guidance
Command: npx skills add https://github.com/Chensihakniroth/ANAKOT-AGENT --skill guidance-chensihakniroth

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 enforce output structure at the token level, so generated content always matches the required pattern. ## Core Features & Use Cases - Regex and Grammar Constraints: Guarantee valid emails, dates, phone numbers, JSON objects, and code identifiers by filtering invalid tokens during generation. - Token Healing: Automatically fixes unnatural token boundaries between prompts and generations, eliminating 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 (person, organization, date, location) from unstructured text with guaranteed format compliance, or generate schema-valid JSON for API payloads without post-validation. ## Quick Start Ask the agent to use the guidance skill to generate a JSON user profile with constrained name, age, and email fields using an Anthropic or local model backend.

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.

Guidance vs Instructor vs Outlines for structured output?▼

Guidance supports regex constraints, context-free grammars, and token healing with both API and local models. Instructor is better for Pydantic validation with automatic retrying, while Outlines fits JSON schema validation use cases.

Does Guidance work with local models like llama.cpp?▼

Yes, Guidance supports local inference through the Transformers backend for Hugging Face models and the LlamaCpp backend for GGUF quantized models. Both support GPU offloading, quantization, and full constrained generation features.

What is token healing in constrained generation?▼

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 unnatural tokenization boundaries, and it is enabled by default.

Why is regex-constrained generation slower than free generation?▼

Regex constraints add roughly 1.2x to 1.5x overhead because tokens are filtered against the pattern during inference. However, end-to-end latency is often lower since outputs are always valid and no validation-retry cycles are needed.