guidance

Constrain LLM outputs with regex and grammars for valid JSON, XML, and code.

1|Updated Apr 18, 2026
One-click install
npx skills add https://github.com/rnben/hermes-skills --skill guidance-rnben
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/rnben/hermes-skills/tree/main/plugins/mlops-skills/skills/guidance
Command: npx skills add https://github.com/rnben/hermes-skills --skill guidance-rnben

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Guidance provides robust mechanisms to control and constrain LLM outputs, ensuring structured and valid results across formats like JSON, XML, and code, reducing hallucinations and post-processing.

Core Features & Use Cases

  • Constrained generation with regex and grammars to enforce syntactic validity.
  • Context-manager-like workflows and Pythonic guidance functions for reusable patterns.
  • Local and hosted backends support for OpenAI, Anthropic, and transformers-based models in multi-step tasks.

Quick Start

Install the Guidance package and begin creating constrained generations with regex and grammars.

Frequently Asked Questions about guidance

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I constrain LLM output to guarantee valid JSON and XML generation?

You can constrain LLM output using regex and grammars to enforce syntactic validity, guaranteeing valid JSON and XML generation. This approach applies constrained generation across structured data tasks to reduce hallucinations and eliminate post-processing.

Does constrained generation work with both local transformers and hosted model backends?

Yes, constrained generation supports local and hosted backends including OpenAI, Anthropic, and transformers-based models. You can apply grammar-based generation and JSON/XML validation across both local and hosted model environments in multi-step tasks.

What is token healing and how does it fix structured output syntax errors?

Token healing is a constrained generation mechanism that fixes structured output syntax errors during LLM generation. It works alongside regex and grammar enforcement to maintain syntactic validity and prevent malformed JSON, XML, or code generation.

How do I create reusable guidance functions for multi-step structured data workflows?

You can create reusable guidance functions using context-manager-like workflows and Pythonic patterns for multi-step structured data tasks. These functions apply regex and grammar constraints across JSON and XML validation steps in both local and hosted model environments.

Why does my LLM produce invalid JSON and how do I enforce syntax during generation?

LLMs produce invalid JSON when generation is unconstrained, but you can enforce syntax during generation using regex and grammars. This constrained generation approach guarantees valid JSON, XML, and code output by applying syntax enforcement directly in the model backend.

What are the limitations of using regex for constrained generation in LLMs?

Regex constrained generation requires precise pattern formulation and may not cover all complex grammar rules for structured output. Grammar-based generation and token healing provide broader syntax enforcement for JSON, XML, and code validation across OpenAI, Anthropic, and local transformers backends.