guidance

Enforce token-level regex and grammar constraints for structured LLM outputs.

2|Updated Apr 12, 2026
One-click install
npx skills add https://github.com/Clay-HHK/claude-config --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-config/tree/main/skills/AI-research-SKILLs/16-prompt-engineering/guidance
Command: npx skills add https://github.com/Clay-HHK/claude-config --skill guidance-clay-hhk

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Guidance eliminates unreliable free-form LLM outputs by enforcing syntactic and structural constraints so models produce valid JSON, XML, code, and other structured formats without expensive retry loops.

Core Features & Use Cases

  • Regex and Grammar Constraints: Enforce token-level patterns and context-free grammars to guarantee format correctness (emails, dates, UUIDs, JSON fields).
  • Token Healing & Selection: Avoid token-boundary artifacts and provide deterministic choice selections for classification or fixed-category fields.
  • Multi-step Workflows & Agents: Build Pythonic, stateful or stateless generation functions and ReAct-style agents that call tools and validate inputs.
  • Use Case: Generate validated API responses, extract structured entities from text, or create production-grade data pipelines that require strict output formats.

Quick Start

Use Guidance to generate a valid JSON user object with fields name, age, and email that each match specified regex constraints.

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 without retry loops?

To guarantee valid JSON output from an LLM without retry loops, apply constrained generation to enforce token-level regex and grammar constraints. This ensures models produce valid structured formats like JSON, XML, and code deterministically.

Can I enforce regex patterns for specific fields during structured data extraction?

Yes, you can enforce regex patterns for specific fields during structured data extraction. By applying context-free grammars and token-level constraints, the model generates values that match specific formats like emails, dates, and UUIDs.

Does constrained generation work with local models and API backends?

Constrained generation works with both local models and API backends. It is compatible with Anthropic, OpenAI, Transformers, and llama.cpp, allowing you to enforce output syntax across different platforms.

What is token healing and when do I need it for structured outputs?

Token healing is a technique that avoids token-boundary artifacts during generation. You need it when enforcing structured outputs to ensure deterministic choice selections and prevent formatting errors caused by tokenization mismatches.

How do I build a multi-step ReAct agent with validated tool inputs?

Build multi-step ReAct agents with validated tool inputs by creating Pythonic, stateful or stateless generation functions. Constrained generation ensures the agent produces valid syntax for tool calls and API response formatting.

What is the best way to format API responses from LLMs deterministically?

The best way to format API responses deterministically is to apply constrained generation using grammar constraints and selection choices. This eliminates unreliable free-form outputs and enforces strict structural formats without expensive retries.