guidance

Apply Guidance constraints to generate validated JSON, XML, or code.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Control LLM output with regex and grammars, guarantee valid JSON/XML/code generation, enforce structured formats, and build multi-step workflows with Guidance - Microsoft Research's constrained generation framework

Core Features & Use Cases

  • Regex and grammar constraints to enforce strict output formats (JSON, XML, code)
  • Token healing and validation to ensure reliable, structured results
  • Multi-step workflows and Pythonic guidance for end-to-end automation across local or API backends

Quick Start

Provide a constrained JSON object with fields name and id validated by regex rules.

Frequently Asked Questions about guidance

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

FAQPage Schema
How do I force an LLM to generate valid JSON output?

You can enforce valid JSON output by applying regex and grammar constraints to the generation process. This ensures structured results through token healing and validation, guaranteeing the model produces strictly formatted JSON objects.

Can I use constrained generation with OpenAI or Anthropic API backends?

Yes, constrained generation works with OpenAI and Anthropic API backends. It applies grammar-based constraints and token healing across both local Transformers models and remote API backends via a Python API.

What is token healing in structured LLM output generation?

Token healing is a validation mechanism that fixes partial token boundaries during generation. It ensures reliable, structured results by correcting incomplete tokens before they violate regex or grammar constraints.

How do I build multi-step workflows for constrained text generation?

You can build multi-step workflows using Pythonic guidance to chain constrained generation tasks. This allows end-to-end automation across local or API backends, applying regex and grammar constraints at each step.

Does regex constraint enforcement work for XML and code generation too?

Yes, regex and grammar constraints enforce strict output formats for JSON, XML, and code generation. The framework validates structured outputs across multiple formats to guarantee syntax compliance.

Why does my LLM output invalid JSON despite providing a schema?

Invalid JSON occurs when standard generation lacks token-level constraints. Applying grammar-based constraints and token healing forces the LLM to produce validated JSON that strictly matches your schema rules.