guidance

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

27|2|Updated Jan 15, 2024
One-click install
npx skills add https://github.com/erfanzar/Xerxes-Agents --skill guidance-erfanzar
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/erfanzar/Xerxes-Agents/tree/main/src/python/xerxes/skills/inference/guidance
Command: npx skills add https://github.com/erfanzar/Xerxes-Agents --skill guidance-erfanzar

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires guidance, transformers.

What problem does it solve?

Constrain LLM outputs and guarantee structured results (JSON/XML/code) using regex constraints and grammars, enabling reliable, auditable generations across complex workflows.

Core Features & Use Cases

  • Constrained generation with regex and grammar rules to enforce formats
  • Grammar-based generation for complex structures (JSON, XML, code)
  • Multi-step workflows and token-healing for coherent outputs
  • Reusable Pythonic guidance functions to compose advanced prompts

Quick Start

Create a guided JSON object with a validated email and constrained age field.

Frequently Asked Questions about guidance

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

FAQPage Schema
How do I constrain LLM outputs to generate valid JSON and XML?

Constrain LLM outputs to generate valid JSON and XML by applying regex constraints and grammar rules during generation. This enforces strict structural formats, ensuring the resulting text is immediately parseable without syntax errors.

What is grammar-based generation for structured output?

Grammar-based generation for structured output is a technique that forces a language model to produce text adhering to specific syntax rules. By defining grammars, you guarantee formats like JSON or code are followed exactly during the generation process.

Can I use regex to validate fields during LLM data extraction?

Yes, you can use regex to validate fields during LLM data extraction. By applying regex constraints, the model is restricted to generating only characters that match your defined pattern, ensuring fields like emails or ages meet exact specifications.

Do I need the transformers library to use guided generation workflows?

Yes, you need the transformers library along with the core guidance library to use guided generation workflows. These dependencies provide the necessary backend integration to enforce grammar rules and execute constrained multi-step generation.

What is token healing and how does it improve constrained generation?

Token healing is a feature that improves constrained generation by correcting boundary artifacts between forced tokens and model-generated tokens. It ensures coherent outputs by preventing awkward token merges when applying strict grammar or regex constraints.

How do I build multi-step workflows for template generation with LLMs?

You build multi-step workflows for template generation by using Pythonic guidance functions to compose advanced prompts. This allows you to chain constrained generation steps together, passing validated structured outputs between stages reliably.