guidance

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

Updated Aug 22, 2026
One-click install
npx skills add https://github.com/vivekgoquest/hermes-agent-stable --skill guidance-vivekgoquest
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/vivekgoquest/hermes-agent-stable/tree/main/optional-skills/mlops/guidance
Command: npx skills add https://github.com/vivekgoquest/hermes-agent-stable --skill guidance-vivekgoquest

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? LLMs often produce malformed JSON, invalid dates, or off-format text that breaks downstream parsing. This Skill uses the Guidance library to enforce token-level constraints so model outputs always match the required regex, grammar, or selection set. ## Core Features & Use Cases - Regex and Grammar Constraints: Force outputs to match patterns like emails, dates, phone numbers, or full JSON schemas compiled from Pydantic models. - Token Healing: Automatically repairs token boundaries between prompt and generation to avoid spacing artifacts. - Reusable Workflows: Build multi-step reasoning chains, ReAct agents, and data extraction pipelines with the @guidance decorator and Pythonic control flow. - Use Case: Extract structured entities (names, dates, emails) from unstructured text with guaranteed-valid formats, or generate schema-conformant JSON for API payloads without retry loops. ## Quick Start Use the guidance skill to generate a JSON user profile with name, age, and email fields constrained to valid formats using a local Transformers 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 the guidance library's gen() function with regex constraints for each field, or pass a Pydantic schema to guidance.json() which compiles it into a grammar. The model can only produce tokens matching the pattern, so output is always valid.

Guidance vs Instructor vs Outlines for structured output?▼

Guidance supports regex constraints, context-free grammars, and token healing with Pythonic syntax. Instructor adds Pydantic validation with automatic retrying, while Outlines offers JSON schema validation. Choose Guidance for complex workflows with control flow on local models.

Does Guidance constrained generation work with OpenAI API?▼

No. Regex, select(), and grammar-based constraints require local logit access and only work with local backends like Transformers and LlamaCpp. Remote API backends such as OpenAI and Azure support only unconstrained gen() and chat.

What is token healing in Guidance?▼

Token healing backs up one token at the prompt-generation boundary and regenerates it together with the output. This prevents artifacts like double spaces or broken words caused by unnatural tokenization boundaries, and it is enabled by default.

Why is my regex-constrained generation slow?▼

Complex regex patterns run about 1.5x slower than free generation, and grammar-based generation about 2x slower. Use specific patterns, set max_tokens limits, prefer stop sequences, and reuse @guidance functions so compiled grammars are cached.