guidance

Generate valid JSON, XML, and code using regex and grammatical constraints.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill provides precise control over Large Language Model (LLM) outputs by utilizing regex constraints and grammars, allowing users to generate valid JSON, XML, code, and structured data with ease.

Core Features & Use Cases

  • Structured Generation: Generate output that matches specific patterns, ensuring valid JSON/XML/code generation and enforcing structured formats.
  • Multi-Step Workflows: Build complex workflows with Pythonic control flow, enabling the creation of multi-step processes.
  • Constrained Output: Prevent invalid outputs through grammatical constraints, providing reliable and predictable results.
  • Use Case: Create a JSON object from user input by ensuring that the name, age, and email fields adhere to specific regex patterns.

Quick Start

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

name: John Doe
age: 30
email: [email protected]

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 always valid JSON?

To ensure valid JSON generation from an LLM, you apply regex constraints and grammars to restrict the output space. This enforces structured formats, guaranteeing the model produces syntactically correct JSON without hallucinated fields.

Can I use regex to constrain specific fields in structured data generation?

Yes, you can use regex patterns to constrain specific fields during structured data generation. This allows you to enforce precise formats for text elements like names, ages, and emails, preventing invalid outputs from the LLM.

Does this approach for controlling LLM output work with multi-step workflows?

Yes, grammatical constraints support multi-step workflows by utilizing Pythonic control flow. This enables you to build complex, multi-step processes that reliably generate structured data while maintaining predictable results throughout the execution.

What do I need to set up before constraining LLM outputs with grammars?

Before constraining LLM outputs, you need the guidance library and a compatible LLM backend installed in your environment. These dependencies are required to interpret the grammatical constraints and execute the structured generation process.

What is the best way to guarantee valid XML generation from a language model?

The best way to guarantee valid XML generation is to apply grammatical constraints that control the LLM output. This prevents invalid formatting and enforces the required structured XML tags directly during the generation phase.