guidance

Constrain LLM outputs using regex and grammar rules.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Guidance provides a robust framework to constrain LLM outputs using regex and grammar rules, reducing hallucinations and ensuring deterministic, structured results across diverse tasks.

Core Features & Use Cases

  • Regex-based constraints for validation of emails, dates, IDs, and other formats.
  • Grammar-based generation for JSON, XML, and domain-specific languages to guarantee valid structures.
  • Token healing and multi-step workflows to improve coherence and reliability in complex prompts.
  • Reusable guidance functions and patterns to accelerate development and maintain consistency.
  • Real-world uses include data extraction, safe tool-use agents, and production-grade prompt templates.

Quick Start

Generate a constrained JSON object using Guidance by supplying a schema and allowed patterns.

Frequently Asked Questions about guidance

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

FAQPage Schema
How do I constrain LLM outputs to generate valid JSON structures?

To constrain LLM outputs for valid JSON, you apply grammar-based generation rules that enforce specific schemas and structures. This ensures the model produces syntactically correct JSON, reducing hallucinations and guaranteeing deterministic results for data extraction workflows.

What is token healing and how does it improve constrained generation?

Token healing fixes tokenization artifacts at prompt boundaries during constrained generation. It improves coherence and reliability in complex multi-step workflows by ensuring smooth transitions between prompt segments and structured outputs.

Can I use regex patterns to validate extracted data formats like emails and dates?

Yes, you can use regex-based constraints to validate specific data formats like emails, dates, and IDs during generation. This forces the model to produce text strictly matching your defined regular expressions, ensuring format compliance.

Does constrained generation work with local and API model backends?

Constrained generation via grammar and regex rules supports both local and API backends. This allows you to enforce structured formats and reusable primitives across diverse software engineering and data analytics environments without provider lock-in.

When should I use grammar constraints instead of standard prompt engineering?

Use grammar constraints instead of standard prompt engineering when you need guaranteed valid structures like XML or domain-specific languages. Grammar constraints enforce deterministic formatting at the generation level, whereas prompt engineering relies on probabilistic compliance.