guidance

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

Updated Mar 18, 2026
One-click install
npx skills add https://github.com/tadod12/fraud-detection-research --skill guidance-tadod12
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/tadod12/fraud-detection-research/tree/main/.agent/skills/16-prompt-engineering/guidance
Command: npx skills add https://github.com/tadod12/fraud-detection-research --skill guidance-tadod12

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 grammars, ensuring predictable, verifiable results across complex tasks.

Core Features & Use Cases

  • Regex and grammar constraints to produce valid JSON, XML, or code with minimal post-processing.
  • Token healing and selection constraints to reduce invalid outputs and enforce structured formats.
  • Workflow orchestration for multi-step tasks (data extraction, JSON generation, and tool-augmented reasoning) with Pythonic control flow.

Quick Start

Generate a small JSON object that adheres to a predefined schema using regex and grammar constraints.

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 and XML?

You constrain LLM outputs to generate valid JSON and XML by applying regex and grammar-based constraints during generation. This enforces structured formats directly, ensuring predictable results with minimal post-processing.

What is token healing and how does it reduce invalid structured outputs?

Token healing is a constrained-generation technique that fixes boundary tokenization errors during LLM inference. It reduces invalid structured outputs by enforcing selection constraints and repairing token boundaries to maintain format integrity.

How do I build multi-step workflows for data extraction with constrained generation?

You build multi-step workflows for data extraction with constrained generation by orchestrating Pythonic control flows. This workflow chains data extraction, JSON generation, and tool-augmented reasoning steps while enforcing format constraints throughout.

Does constrained generation work with both local and API-backed models?

Yes, constrained generation works with both local and API-backed models. The framework enforces grammar and regex constraints across different model deployments to ensure data integrity and structured outputs.

Can I validate structured LLM outputs without leaking the original prompts?

You can validate structured LLM outputs without leaking prompts by loading constraints via frontmatter and enforcing structured formats separately. The validation process checks regex and grammar compliance while keeping the original prompts secure.

What is the best way to enforce a predefined schema when generating code from an LLM?

The best way to enforce a predefined schema when generating code from an LLM is using grammar-based constraints. Grammars restrict the generation space to valid syntax, ensuring the output code adheres to required structural definitions without relying on post-processing.