guidance

Constrain LLM output to match regex patterns or grammars.

Updated Apr 12, 2026
One-click install
npx skills add https://github.com/DaddyElonMusk69/motis-agent --skill guidance-daddyelonmusk69
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/DaddyElonMusk69/motis-agent/tree/main/skills/mlops/inference/guidance
Command: npx skills add https://github.com/DaddyElonMusk69/motis-agent --skill guidance-daddyelonmusk69

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

LLMs often generate outputs that deviate from required formats, causing downstream parsing errors and increased latency. This Skill enforces syntactic constraints such as regex or grammars to guarantee valid JSON, XML, code, or other structured data.

Core Features & Use Cases

  • Regex and Grammar Constraints: Define patterns that the model must follow, ensuring correct syntax.
  • Token Healing: Automatically fixes spacing issues at token boundaries for smoother text.
  • Multi‑step Workflows: Combine constrained generation with Pythonic control flow for complex pipelines.
  • Backend Flexibility: Works with OpenAI, Anthropic, HuggingFace Transformers, and llama.cpp models.

Quick Start

Generate a JSON user profile with name and age using the guidance skill.

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

To constrain LLM output with regex or grammars, you use the guidance package to enforce syntactic constraints during generation. This guarantees the model produces valid structured formats like JSON or XML without downstream parsing errors.

Does the guidance package work with OpenAI, Anthropic, and HuggingFace Transformers models?

Yes, the guidance package supports backend flexibility and works with OpenAI, Anthropic, HuggingFace Transformers, and llama.cpp models. This allows you to apply constrained generation across various compatible model backends.

Why does my LLM generate invalid JSON during multi-step workflows?

LLMs generate invalid JSON due to unconstrained token prediction. By enforcing grammar or regex constraints with the guidance package, you guarantee valid JSON, XML, or code output and eliminate downstream parsing errors.

How do I generate valid structured data using Pythonic control flow in multi-step pipelines?

You generate structured data in multi-step pipelines by combining constrained generation with Pythonic control flow using the guidance package. This approach enforces regex or grammar patterns while orchestrating complex generation workflows.

What is token healing and how does it fix spacing issues at token boundaries?

Token healing is a feature that automatically fixes spacing issues at token boundaries during constrained generation. It ensures smoother text output when LLMs are forced to match regex patterns or grammars.

What are the limitations of using regex and grammars for constrained generation?

Using regex and grammars for constrained generation requires the specific guidance Python package and compatible model backends like OpenAI, Anthropic, or Transformers. It is limited to environments where these dependencies are installed.