guidance

Constrain LLM outputs with regex and grammars for structured JSON, XML, and code generation.

Updated Mar 29, 2026
One-click install
npx skills add https://github.com/shuff57/agent-evo --skill guidance-shuff57
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/shuff57/agent-evo/tree/main/skills/.archive/topics-2026-05-10/mlops/inference/guidance
Command: npx skills add https://github.com/shuff57/agent-evo --skill guidance-shuff57

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill addresses the challenge of controlling and structuring LLM outputs, ensuring valid JSON/XML/code generation, and facilitating the construction of complex workflows with Pythonic control flow.

Core Features & Use Cases

  • Control LLM Output: Use regex and grammars to enforce structured formats and enforce structured formats.
  • Multi-Step Workflows: Build complex workflows with Pythonic control flow.
  • Use Case: Imagine you need to generate a structured JSON object from user input. This Skill allows you to define the structure and constraints of the output, ensuring accuracy and consistency.

Quick Start

To generate a valid JSON object with a name, age, and email, run the following command: python generate_person(lm)

Frequently Asked Questions about guidance

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enforce structured JSON output from an LLM?

You can enforce structured JSON output by applying regex constraints and grammar-based generation to ensure the response strictly matches your defined format. This prevents parsing errors and guarantees valid JSON, XML, or code generation.

Can I build multi-step LLM workflows with Pythonic control flow?

Yes, you can build multi-step LLM workflows using Pythonic control flow to orchestrate complex generation sequences. This allows you to chain language model calls and intermediate logic seamlessly within standard Python scripts.

Do I need the guidance library and Python to control LLM generation?

Yes, you need the guidance library and Python installed to run constrained generation capabilities for LLMs. This environment provides the necessary framework for applying grammar rules and regex patterns to model outputs.

Does constrained generation work with llama.cpp and transformers?

Constrained generation works with llama.cpp and transformers as underlying dependencies for executing grammar-based rules. This integration ensures that regex pattern matching and structural constraints apply directly across these model frameworks.

What is the best way to generate valid structured data formats from user input?

The best way to generate valid structured data formats from user input is to define the exact structure and constraints before generation. Grammar-based generation enforces these rules during decoding, ensuring accuracy and consistency in the output.