guidance

Constrain LLM generation with regex and grammar rules for valid JSON, XML, or code.

Updated Mar 25, 2026
One-click install
npx skills add https://github.com/afel6/scal-ai-pipeline --skill guidance-afel6
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/afel6/scal-ai-pipeline/tree/main/hermes_skills_library/mlops/inference/guidance
Command: npx skills add https://github.com/afel6/scal-ai-pipeline --skill guidance-afel6

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Guidance eliminates unpredictable or malformed LLM outputs by constraining generation so that results conform to required syntaxes and structured formats, removing the need for retry loops and ad-hoc post-validation.

Core Features & Use Cases

  • Constrained generation using regex and grammar rules to guarantee valid JSON, XML, CSV, or programming language snippets.
  • Token healing to avoid tokenization boundary errors and ensure natural continuations.
  • Selection constraints and multi-step, stateful workflows for ReAct-style agents, data extraction, classification, and planning.
  • Backend-agnostic support for Anthropic, OpenAI, Transformers, and llama.cpp enabling both cloud and local deployments.
  • Use Case: Produce production-ready JSON payloads for downstream services, extract structured entities from documents, or build agents that call validated tools without generating invalid arguments.

Quick Start

Generate a validated JSON user object from a natural-language prompt using Guidance with regex/grammar constraints and your chosen LLM backend.

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?

Constrained generation applies regex and grammar rules during LLM inference to guarantee valid JSON output. This enforces syntactic validity directly, eliminating retry loops and ad-hoc post-validation for production-ready payloads.

What is token healing and how does it fix LLM output formatting?

Token healing is a constraint mechanism that fixes LLM output formatting by correcting tokenization boundary errors. It ensures natural text continuations and prevents malformed syntax when generating structured data or code snippets.

Can I use constrained generation with local models and OpenAI APIs?

Yes, constrained generation supports backend-agnostic deployment for both local models and OpenAI APIs. It works across Anthropic, OpenAI, Transformers, and llama.cpp backends, enabling consistent grammar constraints for cloud and local deployments.

What's the best way to extract structured entities from text using LLMs?

The best way to extract structured entities from text using LLMs is applying selection constraints and multi-step stateful workflows. This enforces valid structured outputs for classification and data extraction without generating invalid arguments.

Does constrained generation work for building ReAct-style agent workflows?

Constrained generation works for ReAct-style agent workflows by applying multi-step, stateful workflows and selection constraints. This ensures agents call validated tools with correctly formatted arguments, preventing malformed function calls.