guidance

Enforces regex- and grammar-based output constraints for LLMs using Python and Guidance.

Updated Jan 24, 2026
One-click install
npx skills add https://github.com/kylezhao1026/hard_baby --skill guidance-kylezhao1026
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/kylezhao1026/hard_baby/tree/main/guidance
Command: npx skills add https://github.com/kylezhao1026/hard_baby --skill guidance-kylezhao1026

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps developers ensure that large language model outputs conform to strict formats by applying regex checks and formal grammars, preventing malformed or ambiguous results from entering downstream systems.

Core Features & Use Cases

  • Regex-based constraints: enforce specific formats (emails, dates, IDs) on generated text.
  • Grammar-based generation: produce structured outputs like JSON, XML, or code snippets that strictly follow a predefined grammar.
  • Token healing and validation: automatically correct token boundaries and validate outputs before use in workflows.
  • Multi-step workflows: build complex pipelines with Pythonic control flow to produce deterministic results.
  • Use cases include generating validated API payloads, extracting structured data from unstructured text, and ensuring reports adhere to a strict schema.

Quick Start

Install the Guidance package, define a constraint (regex or grammar), and generate a constrained output with a single prompt. Example commands:

  • pip install guidance
  • from guidance import models, gen
  • lm = models.OpenAI("gpt-4o")
  • lm += "User data: " + gen("name", regex=r'"[A-Za-z ]+"')
  • print(lm)

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 match a specific regex pattern?

To constrain LLM outputs with regex, you can define a pattern like an email or date format and apply it during generation. This Skill enforces regex constraints to ensure the generated text strictly matches your predefined pattern.

How do I force an LLM to generate valid JSON for API payloads?

You can force an LLM to generate valid JSON by applying grammar-based constraints. This Skill uses formal grammars to produce structured outputs like JSON or XML, ensuring deterministic results for API payloads and data pipelines.

Does constrained generation work with OpenAI and Anthropic API backends?

Yes, constrained generation works with OpenAI and Anthropic API backends. This Skill supports applying regex and grammar constraints to models accessed via these APIs, as well as local model transforms.

What is token healing and how does it validate structured LLM outputs?

Token healing automatically corrects token boundaries during generation to prevent malformed text. This Skill performs token healing and validates outputs against strict formats before emitting them for downstream workflows.

How do I extract structured data from unstructured text using LLMs?

To extract structured data from unstructured text, you apply grammar or regex constraints to the generation process. This Skill enforces strict output formats, allowing you to reliably extract data that adheres to a predefined schema.

Can I build multi-step LLM workflows with deterministic output formats?

Yes, you can build multi-step workflows with deterministic output formats using Pythonic control flow. This Skill allows you to construct complex pipelines that validate formats and emit strictly formatted outputs at each step.