guidance

Constrain LLM generation to produce valid JSON, XML, or code.

1|Updated May 16, 2026
One-click install
npx skills add https://github.com/devMoez/titan --skill guidance-devmoez
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/devMoez/titan/tree/main/optional-skills/mlops/guidance
Command: npx skills add https://github.com/devMoez/titan --skill guidance-devmoez

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Guidance solves the problem of unreliable LLM outputs by enforcing constrained generation so results always match a required syntax such as valid JSON, XML, or code-like formats.

Core Features & Use Cases

  • Regex and Grammar-Constrained Generation: Force specific patterns (e.g., emails, dates, IDs) or full context-free grammars for nested structures.
  • Guaranteed Valid Structured Output: Produce syntactically valid JSON/XML/code without ad-hoc “retry until it parses” loops.
  • Multi-Step Workflows with Control Flow: Build reusable, stateful generation functions that implement multi-stage pipelines (including tool/agent-like loops) while keeping outputs well-formed.

Use Case: Generate an API payload where every field is syntactically valid (e.g., timestamps, numeric ranges, enumerated categories), then pass it directly into downstream systems without validation failures.

Quick Start

Ask an AI to generate a person object as valid JSON using Guidance while constraining the name with a regex and the email with an email-pattern grammar.

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

Constrained generation enforces specific syntax rules like valid JSON during decoding, ensuring LLM outputs always match required formats without retry loops. This eliminates parsing failures by guaranteeing structural validity at generation time.

Can I use regex patterns to constrain LLM text generation for specific fields?

Regex-constrained generation forces LLM outputs to match specific patterns like emails, dates, or IDs. This ensures individual fields in structured outputs adhere to exact formatting rules during decoding rather than relying on post-generation validation.

What is the best way to build multi-step agent workflows with reliable structured outputs?

Multi-step workflow orchestration combines stateful generation functions with constrained decoding to execute multi-stage pipelines while keeping outputs well-formed. This approach maintains format validity across complex agent loops and tool interactions.

How do I validate LLM outputs for fixed classification categories without parsing errors?

Constrained decoding with selectable enumerations restricts LLM generation to predefined categories, ensuring classification outputs always match fixed options. This removes validation failures by enforcing valid selections during generation itself.

Does constrained generation work with context-free grammars for nested structures?

Grammar-constrained generation supports full context-free grammars to enforce nested structure rules during LLM decoding. This guarantees syntactically valid complex outputs like nested JSON or XML without requiring post-hoc parsing checks.