guidance

Constrain language model outputs with regex, grammars, and token healing.

Updated Jun 9, 2026
One-click install
npx skills add https://github.com/zhouboyu-xreal/Hermes-Memory --skill guidance-zhouboyu-xreal
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/zhouboyu-xreal/Hermes-Memory/tree/main/optional-skills/mlops/guidance
Command: npx skills add https://github.com/zhouboyu-xreal/Hermes-Memory --skill guidance-zhouboyu-xreal

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill helps you ensure that LLM output is structured, valid, and adheres to specific requirements, making it ideal for automated generation of JSON, XML, code, and other structured formats.

Core Features & Use Cases

  • Regex Constraints: Control LLM output syntax using regular expressions.
  • Grammar-Based Generation: Generate complex structures using context-free grammars.
  • Token Healing: Ensure natural text boundaries without awkward spacing.
  • Multi-Step Workflows: Build multi-step workflows with Pythonic control flow.
  • Use Case: Generate valid JSON or XML data from user input, or ensure code generation follows specific syntax rules.

Quick Start

Use the guidance skill to generate a JSON object with a name, age, and email.

Frequently Asked Questions about guidance

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

FAQPage Schema
How do I ensure LLM output is valid JSON using regex constraints?

You can ensure valid JSON output by applying regex constraints to restrict LLM token generation to specific syntax patterns. This approach guarantees structured, valid responses without malformed formatting or syntax errors.

What is grammar-based structured generation for language models?

Grammar-based structured generation uses context-free grammars to control LLM output, enabling the generation of complex hierarchical structures. This mechanism guides the model to produce text strictly adhering to defined grammatical rules and syntax.

Can I use Python control flow to build multi-step LLM workflows?

Yes, you can build multi-step LLM workflows using Pythonic control flow to orchestrate complex generation sequences. This approach combines multiple prompts and logic steps to automate structured content creation seamlessly.

Does token healing fix awkward spacing in generated text boundaries?

Token healing fixes awkward spacing by ensuring natural text boundaries during generation. It corrects tokenization artifacts that occur when constraining LLM output, maintaining readable and properly formatted structured content.

Do I need the transformers library for context-free grammar generation?

Yes, the transformers library is required alongside the guidance package for context-free grammar generation. You also need models from guidance-ai/guidance and relevant backend configurations to execute structured generation properly.