guidance

Control LLM generation with Pythonic syntax, regex, and context-free grammars.

11.5k|842|Updated Nov 3, 2025
One-click install
npx skills add https://github.com/Orchestra-Research/AI-Research-SKILLs --skill guidance-orchestra-research
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/Orchestra-Research/AI-Research-SKILLs/tree/main/16-prompt-engineering/guidance
Command: npx skills add https://github.com/Orchestra-Research/AI-Research-SKILLs --skill guidance-orchestra-research

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill allows you to precisely control the output of Large Language Models (LLMs) by enforcing specific formats, grammars, and constraints, ensuring reliable and structured generation.

Core Features & Use Cases

  • Constrained Generation: Guarantee outputs match regex patterns or defined grammars (e.g., valid JSON, XML, code).
  • Structured Data Output: Reliably generate data in specific formats, reducing errors and post-processing.
  • Multi-Step Workflows: Build complex conversational agents and reasoning chains with Pythonic control flow.
  • Use Case: Generate a JSON object representing a user profile, ensuring all fields (name, age, email) adhere to strict validation rules before the output is accepted.

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 guarantee LLM output matches a specific JSON schema?

To guarantee LLM output matches a specific JSON schema, constrained generation enforces regex patterns and context-free grammars during decoding, ensuring valid structured data and reducing post-processing errors.

Can I use constrained generation with local models via Transformers and llama.cpp?

Yes, constrained generation supports local models via Transformers and llama.cpp, alongside OpenAI and Anthropic backends, allowing fine-grained control over LLM output across various execution environments.

How do you control LLM generation using regular expressions and grammars?

You control LLM generation by applying Pythonic syntax, regular expressions, and context-free grammars to constrain the decoding process, forcing the model to produce outputs that strictly adhere to defined formats.

What is the best way to build multi-step conversational agents with structured outputs?

The best way to build multi-step conversational agents is using Pythonic control flow to manage complex reasoning chains, enforcing structured data output at each step for reliable agentic workflows.

Why does my LLM generate invalid JSON instead of the requested structured data?

LLMs generate invalid JSON when unconstrained, but applying context-free grammars during generation guarantees format compliance, ensuring outputs strictly match defined validation rules before being accepted.