guidance

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

14|5|Updated Apr 9, 2026
One-click install
npx skills add https://github.com/MLT-OSS/hermes-agent-go --skill guidance-mlt-oss
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/MLT-OSS/hermes-agent-go/tree/main/skills/mlops/inference/guidance
Command: npx skills add https://github.com/MLT-OSS/hermes-agent-go --skill guidance-mlt-oss

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 output always matches the required structure. ## 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 repairs token boundaries between prompt and generation to avoid spacing artifacts and improve output quality. - Multi-Step Workflows and Agents: Build ReAct agents, chain-of-thought reasoning, and stateful generation functions with the @guidance decorator. - Use Case: Extract structured entities (person, organization, date, location) from unstructured text with guaranteed date formats and valid field values, ready for direct database insertion. ## Quick Start Ask the agent to use the Guidance library to generate a JSON user profile with constrained name, age, and email fields using an Anthropic or OpenAI model.

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. The library filters invalid tokens during generation, so the model can only produce output matching your specified structure.

Guidance vs Instructor vs Outlines for structured output?

Guidance supports regex constraints, context-free grammars, and token healing with a 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 Transformers and LlamaCpp backends, including quantized GGUF models with GPU offloading. It also works with Anthropic, OpenAI, and Azure OpenAI APIs.

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 and helps the model produce natural continuations such as camelCase identifiers.

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 you avoid validation failures and retry loops.