guidance

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

Updated Mar 22, 2026
One-click install
npx skills add https://github.com/ChimeraFoundationa/Agentx --skill guidance-chimerafoundationa
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/ChimeraFoundationa/Agentx/tree/main/skills/mlops/inference/guidance
Command: npx skills add https://github.com/ChimeraFoundationa/Agentx --skill guidance-chimerafoundationa

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires guidance, transformers.

What problem does it solve?

Guidance provides a structured generation framework that constrains LLM outputs using regex and CFGs, guaranteeing formatted results (JSON/XML/code) and reducing erroneous or inconsistent results.

Core Features & Use Cases

  • Regex and grammar-based constraints for deterministic outputs
  • Token healing, output validation, and multi-step workflows
  • Local and cloud-friendly backends with flexible model integration

Quick Start

Run a constrained generation example by combining Guidance with a model to produce structured, valid JSON data.

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 guarantee valid JSON and XML?

To constrain LLM outputs, you apply regex and context-free grammars to the generation process, guaranteeing valid JSON/XML/code. This structured generation framework enforces formatting rules during decoding to reduce erroneous outputs.

What is grammar-based constrained generation and when do I need it?

Grammar-based constrained generation uses context-free grammars to restrict LLM token selection. You need it when generating structured output like formatted code or data objects, ensuring deterministic results and preventing formatting inconsistencies.

Does guidance support multi-step workflows and local model backends?

Yes, it supports multi-step workflows alongside local and API model backends. This allows you to chain constrained generation tasks and validate structured outputs across flexible model integrations within your existing environment.

How do I use regex constraints for structured output validation?

You apply regex constraints during the generation process to enforce specific patterns for structured output validation. This ensures LLM responses match predefined rules, while token healing fixes tokenization artifacts to maintain pattern integrity.

What's the best way to fix tokenization errors during constrained generation?

The best way to fix tokenization errors is using token healing, which adjusts boundary tokens during constrained generation. This corrects mismatches between regex grammar rules and the LLM's token vocabulary, ensuring valid structured output.

Do I need the transformers library to use grammar-based generation?

You need the transformers and guidance libraries installed to use grammar-based generation. These dependencies provide the necessary environment for applying context-free grammars and regex constraints to local models.