guidance

Constrain LLM generation with regex and grammar for valid JSON, XML, or code.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

Guidance helps you prevent malformed model outputs by constraining generation to regex patterns, grammars, and selectable options, so downstream systems can reliably consume JSON, XML, and code-like structures.

Core Features & Use Cases

  • Constrained generation with regex: Force fields to match required formats such as emails, dates, IDs, and numeric patterns.
  • Grammar-based structured output: Use context-free grammars to generate nested JSON/XML/code with guaranteed structural validity.
  • Multi-step workflow building: Compose deterministic, multi-round pipelines using Guidance’s Pythonic control flow and reusable functions.
  • Token healing: Automatically fix awkward token-boundary artifacts to improve correctness for structured continuations (e.g., spacing and identifiers).
  • Selection constraints: Restrict outputs to a fixed set of categories for classification and routing.

Quick Start

Ask your AI to generate a valid JSON object containing fields that must follow a specified regex and grammar, such as a user profile with name, age, and email, using Guidance constraints to ensure the output is always parseable.

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 generation from LLMs?

You can guarantee valid JSON generation by constraining LLM outputs using context-free grammars and regex patterns. This enforces structured continuations during generation, ensuring downstream systems reliably consume JSON, XML, or code-like structures without parsing errors.

What is token healing for structured LLM outputs?

Token healing is a mechanism that automatically fixes awkward token-boundary artifacts during generation. It improves correctness for structured continuations by ensuring proper spacing and identifiers, preventing malformed model outputs in constrained workflows.

How do I force LLM outputs to match a specific regex pattern?

You can force LLM outputs to match a specific regex pattern by applying constrained generation. This restricts fields to required formats such as emails, dates, IDs, and numeric patterns, preventing invalid text from breaking structured data extraction pipelines.

Can I restrict LLM classification outputs to a fixed set of categories?

Yes, you can restrict LLM classification outputs using selection constraints. This limits generation to a fixed set of categories for classification and routing, ensuring the model only returns valid selectable options for multi-step workflows.

Does Guidance work with transformers for multi-step workflow pipelines?

Guidance works with transformers to build multi-step workflow pipelines using Pythonic control flow and reusable functions. This dependency integration allows you to compose deterministic, multi-round pipelines that maintain guaranteed structural validity across varied inputs.

What is the best way to prevent malformed model outputs in data extraction?

The best way to prevent malformed model outputs in data extraction is applying grammar-based structured generation. Using context-free grammars guarantees structural validity for nested JSON, XML, or code, ensuring formats remain reliable across varied inputs.