guidance

Constrain LLM outputs with regex and grammars for valid JSON and XML.

1|Updated Jan 31, 2026
One-click install
npx skills add https://github.com/Monjyu1101/AiDiy2026 --skill guidance-monjyu1101
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/Monjyu1101/AiDiy2026/tree/main/backend_hermes/optional-skills/mlops/guidance
Command: npx skills add https://github.com/Monjyu1101/AiDiy2026 --skill guidance-monjyu1101

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Automates the production of structured and validated outputs from LLMs by applying regex constraints, grammars, and multi-step workflows.

Core Features & Use Cases

  • Regex-guided generation for valid formats (emails, dates, IDs) and data extraction.
  • Grammar-based generation for complex structures (JSON/XML) with token healing.
  • Multi-step workflows with Pythonic control flow to orchestrate tools and validations.

Quick Start

Generate a small JSON object with fields name, email, and age that conform to regex patterns and return valid JSON.

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 guarantee valid JSON generation?

You can constrain LLM outputs to guarantee valid JSON generation by applying regex constraints and grammars during the generation process. This ensures the model produces structured data that strictly conforms to your required JSON schemas and API payloads.

Can I use regex patterns to extract specific data formats like emails and dates from LLM outputs?

Yes, you can use regex-guided generation to extract specific data formats like emails, dates, and IDs from LLM outputs. This approach forces the model to produce text that exactly matches your defined regex patterns for reliable data extraction.

How does grammar-based generation work for complex structures like XML?

Grammar-based generation works for complex structures like XML by defining structural rules that the LLM must follow during text generation. This approach also utilizes token healing to repair partial tokens, ensuring the final output forms valid and complete hierarchical structures.

Do I need a Python environment to use grammars for constrained generation?

Yes, you need a Python environment along with the Guidance library to use grammars for constrained generation. You can also configure optional local backends or transformers if you require offline usage for your workflows.

What's the best way to orchestrate multi-step workflows with LLM validations?

The best way to orchestrate multi-step workflows with LLM validations is using Pythonic control flow to sequence tool calls and checks. This allows you to automate the production of structured outputs while applying regex and grammar rules at each step.

Why does my LLM output fail to conform to my JSON schema during generation?

LLM outputs fail to conform to JSON schemas when generation is unconstrained, allowing random token sequences. Applying grammar-based generation with token healing forces the model to strictly follow your schema rules, guaranteeing valid JSON and XML formatting.