guidance

Constrain LLM outputs with regex and grammar rules for structured formats.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you make LLMs produce reliable, structured outputs instead of free-form text that can break downstream systems, waste retries, or fail validation.

Core Features & Use Cases

  • Constrained generation: Use regex and grammar rules to guarantee valid JSON, XML, code, IDs, emails, dates, and other structured fields.
  • Workflow building: Compose multi-step prompts, reusable generation functions, classification flows, extraction pipelines, and agent loops in Pythonic control flow.
  • Backend flexibility: Apply the same patterns across Anthropic, OpenAI, Transformers, and llama.cpp setups for both API and local-model usage.
  • Use case: A product team can extract entities from customer emails, classify the message intent, and emit clean JSON for routing without manual cleanup.

Quick Start

Ask this skill to create a constrained Guidance workflow for your chosen model, output format, and validation rules.

Frequently Asked Questions about guidance

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

FAQPage Schema
How do I force an LLM to generate valid JSON and regex-constrained structured output?

To force valid structured output, apply grammar and regex constraints during constrained generation. This guarantees the LLM emits valid JSON, XML, or specific formats without breaking downstream systems or failing validation.

Can I use constrained generation workflows across both API and local model backends?

Yes, constrained generation workflows apply across API and local model backends. You can use the same regex and grammar constraints across Anthropic, OpenAI, Transformers, and llama.cpp setups for consistent structured output.

What is token healing and how does it fix unconstrained LLM generation?

Token healing fixes unconstrained LLM generation by correcting token boundaries during inference. It prevents format-breaking artifacts, ensuring generated text aligns with required grammar, regex, and structured output constraints.

How do I build a multi-step extraction and classification pipeline with LLM workflows?

Build multi-step LLM workflows by composing reusable Pythonic generation functions for extraction and classification. This routes inputs like customer emails into clean JSON entities without manual cleanup or wasted retries.

Does constrained generation work with selection-based branching for agent loops?

Yes, constrained generation supports selection-based branching for agent loops. You can enforce grammar constraints on dynamic choices, allowing reliable multi-step prompt execution and structured control flow within LLM agents.

Why does my LLM output break required formats and fail JSON validation?

LLM output breaks required formats due to unconstrained generation producing free-form text. Applying hard constraints via regex and grammar rules forces the model to satisfy validation rules, preventing downstream system failures.