guidance

Enforce regex and grammar constraints on LLM token generation for structured outputs.

4|Updated May 18, 2026
One-click install
npx skills add https://github.com/ZardLi1115/zedclaw --skill guidance-zardli1115
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/ZardLi1115/zedclaw/tree/main/optional-skills/mlops/guidance
Command: npx skills add https://github.com/ZardLi1115/zedclaw --skill guidance-zardli1115

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires guidance, transformers, and includes references (resource) components.

What problem does it solve?

Guidance helps you stop LLM responses from producing malformed or unpredictable outputs by enforcing syntax, structure, and allowed tokens during generation.

Core Features & Use Cases

  • Regex-based constrained generation: force fields like emails, IDs, dates, phone numbers, and numeric ranges to match required patterns.
  • Grammar-constrained outputs: generate complex structured data (including nested JSON/XML-like formats) that obey a specified grammar.
  • Multi-step workflows with deterministic structure: build repeatable pipelines that generate intermediate steps, actions, and final results without breaking formatting.
  • Token healing for clean concatenation: reduce spacing and boundary issues when combining prompt text with constrained generations.
  • Backend-flexible execution: run with OpenAI/Anthropic, Transformers, or llama.cpp backends as needed.

Quick Start

Use the guidance skill to generate a valid JSON object by specifying a grammar that constrains each field (e.g., name, age, email) and then read the parsed fields directly from the result.

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 valid JSON and structured data?

You can constrain LLM output to valid JSON by applying regex patterns or grammar constraints during generation, restricting allowed tokens to guarantee structural conformance and prevent malformed syntax.

What is the best way to generate structured data like XML and code from LLMs?

Generating structured data like XML and code requires grammar-constrained generation, which enforces specific syntax rules and allowed tokens at generation time to ensure complex nested outputs remain perfectly valid.

Does constrained generation work with OpenAI, Anthropic, and Transformers backends?

Yes, constrained generation supports backend-flexible execution, allowing you to run regex and grammar constraints across OpenAI, Anthropic, Transformers, and llama.cpp backends within multi-step agent workflows.

How do I validate specific LLM output fields like emails and phone numbers?

You validate specific LLM output fields like emails and phone numbers using regex-based constrained generation, which forces the model to match required patterns and formatting during the generation process.

What is token healing and when do I need it for LLM generation?

Token healing fixes spacing and boundary issues when combining prompt text with constrained generations, ensuring clean concatenation for structured outputs and multi-step agent workflows without breaking formatting.

Why does my LLM produce unpredictable outputs in multi-step agent workflows?

LLMs produce unpredictable outputs in multi-step agent workflows because unconstrained generation allows arbitrary tokens; applying grammar constraints restricts allowed tokens to guarantee deterministic structure and valid syntax.