guidance

Enforce regex and grammar constraints for valid JSON, XML, and code outputs.

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

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 syntax constraints during generation.

Core Features & Use Cases

  • Constrained generation with regex and grammars to guarantee format correctness (e.g., valid emails, dates, IDs, or templated structures).
  • Structured output control for generating syntactically valid JSON, XML, or code-like text.
  • Multi-step workflow building using Guidance’s Pythonic control flow and reusable patterns (including @guidance functions).

Quick Start

Ask your AI to produce a valid JSON object with specific fields by using Guidance-style constrained generation so the output always matches your required schema.

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 instead of malformed text?

Constrained generation uses regex and grammar constraints to guarantee structured LLM outputs always match your specified JSON, XML, or code formats. This mechanism forces the model to select only tokens that comply with your defined syntactic rules during inference.

What is constrained generation and how does it guarantee structured outputs?

Constrained generation applies regex and grammar constraints to guarantee structured LLM outputs always match your specified JSON, XML, or code formats. This mechanism forces the model to select only tokens that comply with your defined syntactic rules during inference.

Can I use regex constraints to validate specific fields like emails or dates in LLM outputs?

Regex constraints enforce valid LLM outputs by applying pattern rules during generation to guarantee format correctness for specific fields like emails, dates, or IDs. This intercepts invalid tokens before they are generated, ensuring compliance without post-processing.

How do I build a multi-step workflow for generating structured data with LLMs?

Build multi-step workflows for structured data generation using Pythonic control flow and reusable guidance functions. This chains constrained generation steps together to produce complex, valid JSON or XML structures across sequential LLM calls.

Do I need the transformers library to apply grammar constraints for structured output?

Applying grammar constraints for structured output requires the guidance and transformers libraries as dependencies. These provide the necessary environment to enforce regex rules and constrained selection directly during the LLM generation process.

Why does my LLM produce invalid JSON even when I provide a schema in the prompt?

LLMs produce invalid JSON because standard generation lacks syntactic enforcement. Applying grammar constraints during constrained generation guarantees valid JSON by forcing token selection to match your schema, eliminating unpredictable formatting and malformed outputs.