guidance

Generate constrained LLM outputs conforming to JSON, XML, or code formats.

Updated Sep 1, 2021
One-click install
npx skills add https://github.com/unclehowell/unclehowell --skill guidance-unclehowell
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/unclehowell/unclehowell/tree/main/skills/mlops/inference/guidance
Command: npx skills add https://github.com/unclehowell/unclehowell --skill guidance-unclehowell

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Large language models often generate outputs that deviate from required formats, causing downstream parsing errors, security risks, and extra validation work.

Core Features & Use Cases

  • Regex & Grammar Constraints: Enforce exact patterns for JSON, XML, code, dates, emails, and more.
  • Token Healing: Seamlessly join prompts and generations to avoid spacing and token‑boundary issues.
  • Multi‑step Workflows: Build deterministic pipelines with Pythonic context managers and reusable @guidance functions.
  • Backend Flexibility: Works with OpenAI, Anthropic, Hugging Face Transformers, and local llama.cpp models.

Quick Start

Use Guidance to generate a JSON object containing a name and email that always conforms to proper formatting.

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 always generate valid JSON?

To constrain LLM output and generate valid JSON, you can enforce regex and grammar constraints during generation. This ensures the model adheres to exact syntactic formats, preventing parsing errors in API responses and data pipelines.

Can I use constrained generation with local llama.cpp models or OpenAI APIs?

Yes, constrained generation works with local llama.cpp models, OpenAI, Anthropic, and Hugging Face Transformers. This backend flexibility allows you to apply grammar constraints and token healing across different model environments.

What is token healing and how does it fix LLM prompt formatting issues?

Token healing seamlessly joins prompts and generations to avoid spacing and token-boundary issues. It fixes LLM prompt formatting by correcting tokenization mismatches at the boundary between the prompt and the newly generated text.

How do I build deterministic multi-step workflows for structured output?

You can build deterministic multi-step workflows for structured output using Pythonic context managers and reusable functions. This orchestrates pipelines to enforce regex and grammar constraints consistently across generation steps.

Why does my LLM generate invalid XML and code syntax in automated scripts?

LLMs generate invalid XML and code syntax in automated scripts because they often deviate from required formats. Applying grammar constraints enforces exact patterns, ensuring outputs conform to specified syntactic formats for automated scripting.