guidance

Constrain LLM outputs with regex and grammar for structured generation.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

It solves the problem of LLMs producing invalid or inconsistent output formats that break downstream systems, such as JSON/XML/code parsers and workflow steps.

Core Features & Use Cases

  • Constrained generation with regex: Force outputs to match patterns like emails, IDs, dates, or other validated strings.
  • Grammar-based structured generation: Constrain complex nested formats (including JSON-like structures) using grammars for reliable schema adherence.
  • Deterministic multi-step workflows: Build Pythonic, stateful generation pipelines that keep intermediate outputs valid while orchestrating multi-stage tasks.

Quick Start

Use guidance to generate strictly formatted JSON by constraining fields with regex patterns and/or a grammar, then pass the result directly into your application logic.

Frequently Asked Questions about guidance

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

FAQPage Schema
How do I guarantee valid JSON output from an LLM for downstream pipelines?

To guarantee valid JSON output, you can use grammar-based structured generation to constrain complex nested formats, ensuring reliable schema adherence for downstream parsers. This prevents LLMs from producing invalid formats that break application logic.

What is the best way to constrain LLM outputs to match specific regex patterns?

The best way to constrain LLM outputs with regex is to apply constrained generation frameworks that force the model to match patterns like emails, IDs, or validated strings. This ensures generated text strictly follows your required formats.

Can I build stateful, multi-step agent workflows with deterministic LLM outputs?

Yes, you can build deterministic multi-step workflows by orchestrating Pythonic, stateful generation pipelines that keep intermediate outputs valid. This enforces structured content generation across multi-stage tasks in production agent systems.

Does constrained generation work with the transformers library for text classification?

Yes, constrained generation works with the transformers library to enforce deterministic outputs for tasks like text classification and entity extraction. It uses backend model support to apply grammar constraints and optional token healing for correct boundaries.

Why do my LLM-generated XML and code formats break downstream parsers?

LLM-generated XML and code formats break parsers because models produce invalid or inconsistent output structures. Applying grammar-based structured generation constrains the model to valid nested formats, preventing parsing errors in workflow steps.