guidance

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

1|Updated Mar 5, 2026
One-click install
npx skills add https://github.com/Clay-HHK/claude-skills --skill guidance-clay-hhk
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/Clay-HHK/claude-skills/tree/main/guidance
Command: npx skills add https://github.com/Clay-HHK/claude-skills --skill guidance-clay-hhk

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? LLMs frequently produce malformed JSON, invalid emails, or off-format outputs that break downstream parsing and require retry loops. This Skill uses Microsoft Research's Guidance framework to enforce regex and grammar constraints at the token level, so generated outputs always match the required structure. ## Core Features & Use Cases - Regex and Grammar Constraints: Force outputs to match patterns like emails, dates, phone numbers, UUIDs, or full JSON/XML grammars during generation. - Token Healing: Automatically fixes tokenization boundary issues so concatenated prompts and generations produce natural text without spacing artifacts. - Multi-Step Workflows and Agents: Build ReAct agents, chain-of-thought pipelines, and reusable @guidance functions with Pythonic control flow across Anthropic, OpenAI, Transformers, and llama.cpp backends. - Use Case: You need an extraction pipeline that pulls name, date, and email fields from unstructured text into guaranteed-valid JSON. Define regex constraints per field, run the generation once, and parse the result without validation retries. ## Quick Start Ask the AI to write a Guidance script that generates a JSON object with name, age, and email fields using regex constraints with the Anthropic 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 for the full structure. The framework filters invalid tokens during generation, so the output always matches the specified format without retry loops.

Guidance vs Instructor vs Outlines for structured output?▼

Guidance supports regex constraints, context-free grammars, and token healing with strong local model support. 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 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 token boundaries between a prompt and generated text by backing up one token and regenerating. It is enabled by default and prevents issues like double spaces or broken word fragments in completions.

How do I constrain LLM output to a fixed set of choices?▼

Use the select function with a list of allowed values, such as select(["positive", "negative", "neutral"]). The model can only produce one of the listed options, which is faster and more reliable than regex for small fixed sets.

When should I not use regex constraints in Guidance?▼

Avoid overly strict patterns that leave the model almost no valid paths, as they can fail or run slowly. Balance constraints with reasonable max_tokens limits, and prefer select for fixed categories and stop sequences for single-line outputs.