guidance

Constrain LLM outputs with regex and grammar rules for structured results.

2|Updated Apr 25, 2026
One-click install
npx skills add https://github.com/AlexiosBluffMara/mercury --skill guidance-alexiosbluffmara
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/AlexiosBluffMara/mercury/tree/main/optional-skills/mlops/guidance
Command: npx skills add https://github.com/AlexiosBluffMara/mercury --skill guidance-alexiosbluffmara

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This skill enables precise control over large language model outputs by applying regex constraints and formal grammars to ensure structured results such as JSON, XML, or code-like formats, reducing errors and post-processing.

Core Features & Use Cases

  • Constrained generation using regex constraints and CFG grammars
  • Structured outputs: JSON, XML, CSV, and code
  • Multi-step workflows and robust backends for local or API models

Quick Start

Install Guidance and define a small constrained generation workflow to produce valid JSON or XML outputs

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 follow regex and grammar rules?

Constraining LLM outputs with regex and grammar rules requires a Guidance runtime that applies token healing and context-free grammar constraints, enforcing valid structured outputs across JSON, XML, and code-like formats during generation.

What is constrained generation for structured LLM outputs?

Constrained generation is a decoding mechanism that applies regex constraints and context-free grammars to language models, preventing malformed JSON, XML, or CSV responses and eliminating the need for output parsing and validation.

Does constrained generation work with local and API model backends?

Constrained generation supports multiple LLM backends, including both local and API-based models, applying grammar constraints and robust validation uniformly across the Guidance runtime to ensure consistent structured outputs.

Can I use regex constraints for data extraction in multi-step workflows?

You can use regex constraints for data extraction in multi-step workflows by applying grammar rules that enforce structured results, enabling robust validation across sequential generation steps in software engineering contexts.

What's the best way to ensure valid JSON from an LLM without post-processing?

The best way to ensure valid JSON without post-processing is to apply context-free grammar constraints during generation, forcing the model to produce syntactically correct structured outputs directly at the token level.

Why does my LLM output malformed structured data despite prompt instructions?

LLMs output malformed structured data because prompt instructions lack hard constraints; applying regex and grammar rules during decoding enforces valid token sequences, preventing formatting errors in JSON, XML, and CSV outputs.