guidance

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

Updated Jul 13, 2026
One-click install
npx skills add https://github.com/zeronx798/demo-hermes-agent --skill guidance-zeronx798
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/zeronx798/demo-hermes-agent/tree/main/optional-skills/mlops/guidance
Command: npx skills add https://github.com/zeronx798/demo-hermes-agent --skill guidance-zeronx798

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill solves the challenge of unpredictable LLM output by enforcing strict syntax, structure, and format constraints, ensuring the model generates valid JSON, XML, or code every time.

Core Features & Use Cases

  • Constrained Generation: Use regex and context-free grammars to force the model to follow specific output patterns.
  • Token Healing: Automatically fixes unnatural token boundaries between prompts and generated text to prevent spacing errors.
  • Multi-Step Workflows: Build complex, stateful agentic workflows with Pythonic control flow and tool integration.
  • Use Case: If you need to generate a JSON object representing a user profile, this Skill guarantees the output will be perfectly formatted JSON, eliminating the need for complex post-generation parsing or retry loops.

Quick Start

Use the guidance skill to generate a valid JSON object containing a name and age field for a person.

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 every time?

You can guarantee valid JSON output by applying context-free grammars and regex constraints to enforce strict structural rules during generation. This eliminates post-generation parsing failures and retry loops.

What is constrained generation and how does it work for LLMs?

Constrained generation enforces strict syntactic and structural constraints using regex and context-free grammars, ensuring deterministic model responses. It limits the LLM's token choices to guarantee valid JSON, XML, or code structures.

Can I use guidance with llama.cpp and major API providers?

Yes, constrained generation integrates with multiple backends including llama.cpp, Transformers, and major API providers. This ensures deterministic and reliable structured outputs across different execution environments.

How do I prevent spacing errors caused by token boundaries in LLM prompts?

You can prevent unnatural token boundary spacing errors using token healing. This mechanism automatically fixes token boundaries between prompts and generated text to ensure seamless output formatting.

Does constrained generation support building multi-step agentic workflows?

Yes, constrained generation facilitates building complex, stateful agentic workflows. It uses Pythonic control flow and tool integration to manage multi-step generation processes with strict structural constraints.

Why does my LLM output invalid JSON even when I provide a schema?

LLMs output invalid JSON because standard generation lacks structural awareness. Enforcing context-free grammars during generation restricts token selection, guaranteeing perfectly formatted JSON that matches your required schema.