guidance

Enforce regex and grammar constraints on LLM outputs for structured JSON and XML.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

Guidance helps you stop LLMs from producing malformed or unpredictable outputs by enforcing strict syntax and structure during generation, so downstream systems can safely consume the result.

Core Features & Use Cases

  • Regex and grammar-constrained generation to restrict outputs to a required pattern (e.g., emails, IDs, dates) and prevent invalid tokens.
  • Structured output guarantees for JSON/XML/code-like formats using grammar-based generation and selection constraints.
  • Multi-step workflow construction with Pythonic control flow and reusable Guidance functions to orchestrate structured reasoning and extraction.
  • Token healing to avoid boundary artifacts (like double spaces or broken identifiers) when concatenating prompt text with generated spans.

Quick Start

Ask the AI to generate a valid JSON object for a user profile where fields like email and age must match specific formats.

Frequently Asked Questions about guidance

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

FAQPage Schema
How do I constrain LLM output to valid JSON?

To constrain LLM output to valid JSON, you apply grammar-based constraints and selection rules during generation, forcing the model to produce syntactically valid structured outputs for safe downstream consumption.

How does grammar-based generation enforce regex validation for fields like emails and dates?

Grammar-based generation enforces regex validation by restricting token generation to match required patterns like emails, dates, and IDs, preventing invalid tokens from being produced during constrained generation.

Do I need a specific backend to use constrained generation for structured outputs?

Yes, constrained generation requires a compatible backend such as a guidance API or local transformers and llama.cpp, which support grammar-based generation, regex validation, and token healing.

What is token healing and when do I need it for multi-step workflows?

Token healing fixes boundary artifacts like double spaces or broken identifiers when concatenating prompt text with generated spans, ensuring well-formed structured outputs in multi-step workflows.

Can I use Pythonic control flow to orchestrate structured reasoning and extraction?

Yes, you can construct multi-step workflows with Pythonic control flow and reusable functions to orchestrate structured reasoning and extraction, ensuring reliable regex and grammar-based generation.