guidance

Constrain LLM outputs with regex and grammars for structured JSON/XML generation.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/AVOI-CEO/avoi-agent --skill guidance-avoi-ceo
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/AVOI-CEO/avoi-agent/tree/main/optional-skills/mlops/guidance
Command: npx skills add https://github.com/AVOI-CEO/avoi-agent --skill guidance-avoi-ceo

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Regex and grammar constraints to control LLM outputs, guaranteeing structured formats like JSON/XML and preventing invalid or unsafe generations.

Core Features & Use Cases

  • Regex-based constraints enforce formats for emails, dates, IDs, and other fields.
  • Grammar-based generation enables CFG-driven structured outputs such as JSON, XML, and code.
  • Multi-step workflows orchestrate constrained prompts with token healing and validation for reliable pipelines.
  • Use Case: Build a validation layer that always returns a schema-compliant JSON document from user input.

Quick Start

Prompt an LLM to generate a JSON object that matches a given schema using regex and grammar constraints

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?

Constrain LLM outputs using grammar-based generation to enforce schema-compliant JSON. Apply CFG-driven constraints and built-in token healing to guarantee deterministic, structured results without invalid tokens.

What is regex-based constrained generation for language models?

Regex-based constrained generation applies pattern matching to enforce specific formats like emails, dates, and IDs during text generation. This ensures deterministic outputs that match predefined constraints.

Can I use grammar constraints to extract structured data from unstructured text?

Yes, grammar-based generation enables structured data extraction by applying CFG constraints to outputs. Built-in validation checks ensure extracted data matches required formats like JSON or XML.

How do I prevent invalid tokens when generating XML from an LLM?

Prevent invalid tokens using built-in token healing and grammar checks during generation. Apply grammar-based constraints to enforce XML schema compliance and automatically validate outputs.

Does constrained generation work with local and hosted models?

Constrained generation applies to both local and hosted models. Regex and grammar constraints enforce deterministic outputs across environments, ensuring structured results for multi-step workflows.

What is the best way to build a validation layer for LLM JSON output?

Build a validation layer using grammar-based constraints to enforce JSON schema compliance. Combine regex constraints with token healing and automatic validation to guarantee valid structured outputs from user input.