guidance

Enforce regex and grammar constraints for structured LLM outputs in Python.

Updated May 5, 2026
One-click install
npx skills add https://github.com/Z43L/zeus-agent --skill guidance-z43l
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/Z43L/zeus-agent/tree/main/optional-skills/mlops/guidance
Command: npx skills add https://github.com/Z43L/zeus-agent --skill guidance-z43l

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

Guidance prevents large-language models from producing malformed or ill-formed outputs by enforcing regex and grammar constraints during generation, so you can reliably get structured results instead of relying on fragile “prompt + guess” formatting.

Core Features & Use Cases

  • Regex-constrained generation to ensure fields match required patterns like emails, IDs, dates, or numeric formats.
  • Grammar-based constrained generation for nested structures and full documents such as JSON objects and XML.
  • Structured workflows with token healing to maintain correct syntax boundaries and reduce failures from tokenization artifacts.

Quick Start

Ask an AI to generate a valid JSON object by specifying a grammar or regex constraints for each required field, ensuring the response is syntactically correct and immediately parseable.

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?

You can enforce grammar-based constraints during LLM generation to guarantee valid JSON outputs. This applies structural syntax rules directly to the generation process, ensuring the model produces syntactically correct and immediately parseable JSON objects instead of malformed text.

What is regex-constrained generation for large language models?

Regex-constrained generation restricts LLM outputs to match specific regular expression patterns. It ensures generated fields match required formats like emails, IDs, dates, or numeric values, preventing malformed data and guaranteeing the response fits your exact validation rules.

How do I extract structured fields from unstructured text using LLMs?

Extract structured fields by applying regex or grammar constraints to LLM generation. This forces the model to output data matching your exact field patterns, ensuring reliable extraction of specific formats like emails or IDs from unstructured text.

Does token healing help with LLM tokenization boundary errors?

Yes, token healing corrects tokenization boundary errors during constrained LLM generation. It maintains correct syntax boundaries and reduces failures from tokenization artifacts, ensuring generated structured outputs remain valid across token splits.

Can I build multi-step agent workflows with constrained LLM generation in Python?

Yes, you can build multi-step agent workflows in Python using constrained generation primitives. By applying regex and CFG grammars to generation steps, you ensure each workflow phase produces syntactically valid structured outputs for reliable downstream processing.

Why does my LLM output invalid JSON despite prompt instructions?

LLMs output invalid JSON despite prompt instructions because standard generation lacks structural enforcement. Applying grammar-based constraints during generation forces the model to follow strict syntax rules, guaranteeing valid JSON instead of relying on fragile prompt formatting.