guidance

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

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

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 regex, grammar, or selection set. ## Core Features & Use Cases - Regex and Grammar Constraints: Enforce formats like emails, dates, phone numbers, UUIDs, and full JSON/XML structures during generation. - Token Healing: Automatically fixes tokenization boundaries between prompts and generated text for natural continuations. - Multi-Step Workflows: Build ReAct agents, chain-of-thought reasoning, and classification pipelines with Pythonic control flow and reusable @guidance functions. - 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 validation retries. ## Quick Start Use the guidance skill to generate a JSON user profile with constrained name, age, and email fields using Claude.

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 for the full structure. The framework filters invalid tokens during generation, so the output always parses correctly without retry loops.

Guidance vs Instructor vs Outlines for structured output?

Guidance offers regex constraints, grammar support, and token healing with strong local model support. Instructor adds Pydantic validation with automatic retrying, while Outlines provides JSON schema validation. Choose Guidance for complex workflows with Pythonic control flow.

Does Guidance work with local models like llama.cpp?

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

What is token healing in Guidance?

Token healing fixes unnatural tokenization boundaries between the prompt and generated text by backing up one token and regenerating. It prevents issues like double spaces or broken words, and is enabled by default.

Why is constrained generation slower than free generation?

Regex constraints add roughly 1.2-1.5x overhead and grammars about 2x, because tokens are filtered during inference. However, end-to-end latency is often lower since outputs are always valid and no retry loops are needed.