guidance

Generate LLM outputs constrained by regex and grammar rules with Guidance.

Updated Jun 19, 2026
One-click install
npx skills add https://github.com/AnandaAnugrahHandyanto/savarez_agent --skill guidance-anandaanugrahhandyanto
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/AnandaAnugrahHandyanto/savarez_agent/tree/main/optional-skills/mlops/guidance
Command: npx skills add https://github.com/AnandaAnugrahHandyanto/savarez_agent --skill guidance-anandaanugrahhandyanto

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

Constrained generation and validation of LLM outputs to ensure predictable structure and compliance with data formats. It reduces generation errors by enforcing regex and grammar rules, making outputs like JSON, XML, or code reliably structured and verifiable.

Core Features & Use Cases

  • Regex and grammar constraints to enforce output formats (JSON, XML, code).
  • Token healing and grammar compilation for reliable, low-latency generations.
  • Multi-step workflows and Pythonic control flow to orchestrate complex tasks across local or API backends.
  • Automatic validation against schemas and format requirements, plus easy backend switching with Guidance.
  • Real-world use case: generate a user profile in JSON that matches a schema, then transform and store it.

Quick Start

Install Guidance and run a constrained-generation example that outputs a valid JSON object.

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 ensure valid JSON and XML generation?

You can constrain LLM outputs by applying regex and grammar rules to enforce predictable structures like JSON, XML, and code. This constrained generation ensures outputs reliably match your required data formats and schemas.

How do I validate LLM outputs against a specific JSON schema?

You validate LLM outputs against a JSON schema by applying grammar constraints and automatic validation during generation. This enforces schema compliance directly, ensuring the generated text matches your format requirements before completion.

Does Guidance work with local transformers models for constrained generation?

Yes, Guidance works with local transformers models for constrained generation. It supports multi-step workflows and Pythonic control flow to orchestrate complex tasks across local transformers or API backends.

What is the best way to enforce regex constraints during LLM text generation?

The best way to enforce regex constraints is using grammar compilation and token healing. This approach applies regex rules directly during the generation process to deliver reliable, low-latency, and verifiable text outputs.

Why do my LLM generated JSON objects contain syntax errors and how can I prevent them?

LLM generated JSON objects contain syntax errors due to unconstrained token prediction. You prevent them by using constrained generation with grammar rules, which restricts the LLM to only produce valid, verifiable JSON structures.

Can I use constrained generation for multi-step workflows across different API backends?

Yes, you can use constrained generation for multi-step workflows across API backends. Guidance allows easy backend switching while applying grammar compilation and Pythonic control flow to orchestrate complex tasks reliably.