guidance

Control LLM output with regex and grammars for valid JSON, XML, or code.

1|Updated Feb 21, 2026
One-click install
npx skills add https://github.com/tianhao909/AI-Research-SKILLs-cn --skill guidance-tianhao909
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/tianhao909/AI-Research-SKILLs-cn/tree/main/16-prompt-engineering/guidance
Command: npx skills add https://github.com/tianhao909/AI-Research-SKILLs-cn --skill guidance-tianhao909

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill provides fine-grained control over Large Language Model (LLM) output, ensuring structured, valid, and predictable responses through the use of grammars and regular expressions.

Core Features & Use Cases

  • Constrained Generation: Guarantee outputs adhere to specific formats like JSON, XML, or custom grammars.
  • Format Enforcement: Ensure generated data (e.g., dates, emails, numbers) meets strict validation rules.
  • Multi-Step Workflows: Build complex conversational agents and data processing pipelines with Pythonic control flow.
  • Use Case: Generate a valid JSON object representing a user profile, ensuring the email field is correctly formatted and the age is a valid integer, preventing downstream parsing errors.

Quick Start

Use the guidance skill to generate a JSON object for a user with name and age.

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 a valid JSON format?

Constrained generation controls LLM output with regex and grammars to guarantee valid JSON, XML, or code. It enforces structured formats and builds multi-step workflows using Pythonic control flow.

What is the best way to ensure generated data meets strict validation rules?

The best way to ensure generated data meets strict validation rules is to apply grammar and regex constraints directly during generation, enforcing formats like valid email addresses or integers before output is finalized.

Does this constrained generation approach work with local Transformers models?

Yes, this constrained generation approach works with local Transformers and llama.cpp models, as well as various backends including OpenAI and Anthropic, providing flexible backend support for LLM execution.

How do I build multi-step conversational agents with predictable LLM responses?

You build multi-step conversational agents with predictable LLM responses by using Pythonic control flow to orchestrate complex data processing pipelines and enforce structured formats at each generation step.

Why do I get downstream parsing errors when generating XML from LLMs?

Downstream parsing errors occur when generating XML from LLMs because models produce unpredictable text; applying constrained generation with custom grammars guarantees the output adheres strictly to the required XML structure.

Do I need the Guidance framework to enforce structured LLM output?

You need the Guidance framework to enforce structured LLM output because it provides the underlying mechanism to control generation with regex and grammars, ensuring valid JSON, XML, or code across various model backends.