guidance

Constrain LLM output to regex patterns and grammars using the guidance Python library.

Updated Apr 10, 2026
One-click install
npx skills add https://github.com/VYRE-Studios/Windows-Agentic-Framework --skill guidance-vyre-studios
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/VYRE-Studios/Windows-Agentic-Framework/tree/main/skills/mlops/inference/guidance
Command: npx skills add https://github.com/VYRE-Studios/Windows-Agentic-Framework --skill guidance-vyre-studios

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

Guidance addresses the difficulty of getting large language models to produce output that conforms to required formats such as valid JSON, XML, or specific patterns, eliminating costly post‑processing and retries.

Core Features & Use Cases

  • Regex and grammar constraints: Define patterns so the model can only generate matching tokens, guaranteeing syntactically correct results.
  • Token healing: Automatic fixing of token boundary issues for smoother text generation.
  • Multi‑step workflows: Combine constrained generation with Pythonic control flow to build complex agents and data‑extraction pipelines.
  • Broad back‑end support: Works with Anthropic, OpenAI, HuggingFace Transformers, and local llama.cpp models.

Quick Start

Ask Guidance to generate a valid JSON object with a name and email field.

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 output valid JSON?

You can force valid JSON generation by applying regex constraints and grammars during text generation, ensuring the model only produces matching tokens and eliminating the need for costly post-processing or retries.

What is constrained generation in prompt engineering?

Constrained generation is a prompt-engineering technique that restricts large language model outputs to match specified regex patterns or grammars, ensuring format compliance for structured data like JSON and XML.

Does constrained generation work with local llama.cpp and OpenAI models?

Yes, constrained generation works with local llama.cpp and OpenAI models, alongside Anthropic and HuggingFace Transformers back-ends, ensuring token healing and format validation across various supported environments.

How do I use regex patterns to control LLM text generation?

You control LLM text generation with regex patterns by defining the desired pattern so the model is restricted to generating only matching tokens, which guarantees syntactically correct results for your specified format.

Why does my LLM output invalid JSON despite prompt instructions?

LLM output may contain invalid JSON despite prompt instructions due to token boundary issues, which can be fixed using automatic token healing and regex constraints to guarantee syntactically correct results.

Can I build multi-step data extraction pipelines with constrained generation?

Yes, you can build multi-step data extraction pipelines by combining constrained generation with Pythonic control flow, allowing you to create complex agents that validate formats across various model back-ends.