guidance

Generate structured LLM output using regex and grammars in Python.

Updated Jan 30, 2026
One-click install
npx skills add https://github.com/gagan114662/content_books --skill guidance-gagan114662
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/gagan114662/content_books/tree/main/AI-research-SKILLs/16-prompt-engineering/guidance
Command: npx skills add https://github.com/gagan114662/content_books --skill guidance-gagan114662

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides a framework to precisely control and structure the output of Large Language Models (LLMs), ensuring generated text adheres to specific formats, grammars, and constraints, thereby reducing errors and improving reliability.

Core Features & Use Cases

  • Constrained Generation: Guarantee valid JSON, XML, or code output using regex and grammars.
  • Structured Data: Enforce specific formats for dates, emails, IDs, and other data types.
  • Workflow Automation: Build multi-step LLM interactions with Pythonic control flow.
  • Use Case: Generate a valid JSON object representing a user profile, ensuring all fields (name, age, email) conform to predefined formats and types.

Quick Start

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

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

Constrained generation enforces specific formats and grammars to guarantee deterministic LLM output, ensuring generated text adheres to valid JSON. This solves unreliable LLM output formats by using regex and token healing for precise control.

What is constrained generation for structured LLM output?

Constrained generation is a technique that forces LLMs to adhere to predefined formats and grammars, ensuring reliable structured output. It uses regex and token healing to enforce specific constraints, solving problems with data validation and unpredictable text generation.

Can I use Python to control multi-step LLM interactions?

Yes, you can use Python to control multi-step LLM interactions by leveraging Pythonic control flow to build complex multi-turn workflows. This allows you to automate structured generation steps and enforce formats across multiple generation stages.

Does this framework support local models and API backends for constrained generation?

Yes, it supports constrained generation across various backends including API and local models. You can apply regex, grammars, and token healing for precise output control across different model environments, ensuring deterministic structured text generation.

How do I enforce specific formats for emails and dates in LLM responses?

To enforce specific formats for emails and dates in LLM responses, use constrained generation with regex and grammars to validate structured data. This ensures generated text conforms to predefined formats and types, preventing malformed outputs and improving reliability.

Why does my LLM output fail data validation checks?

LLM output fails data validation because unconstrained generation produces unpredictable text formats. Applying constrained generation with regex and grammars enforces deterministic output, ensuring generated text strictly adheres to required data types and predefined validation rules.