guidance

Constrain LLM outputs with regex and grammars for valid JSON, XML, and code.

Updated Jul 3, 2026
One-click install
npx skills add https://github.com/LynxLabVN/office-agent --skill guidance-lynxlabvn
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/LynxLabVN/office-agent/tree/main/agent-core/optional-skills/mlops/guidance
Command: npx skills add https://github.com/LynxLabVN/office-agent --skill guidance-lynxlabvn

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 allows you to control and enforce the syntax, grammar, and format of LLM outputs, ensuring structured and accurate generation of JSON, XML, code, and more.

Core Features & Use Cases

  • Regex Constraints: Apply regex patterns to control the format of generated text.
  • Grammar-Based Generation: Use context-free grammars to enforce complex structures.
  • Token Healing: Automatically correct token boundaries for natural text flow.
  • Use Cases: Format JSON, generate valid code snippets, and enforce structured data output for APIs.

Quick Start

Generate a structured JSON object with a person's name, age, and email by using the following command: generate_person "John Doe" 30 "[email protected]".

Frequently Asked Questions about guidance

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

FAQPage Schema
How do I enforce structured JSON output from an LLM?

You can enforce structured JSON output from an LLM by applying regex constraints and context-free grammars. This ensures generated text strictly follows valid formats, preventing syntax errors during data generation.

Can I use regex patterns to control LLM text generation?

Yes, you can use regex patterns to control LLM text generation and enforce specific formats. This constrains the output to match your defined regular expressions, ensuring accurate text formatting for structured data.

What is the best way to generate valid XML using a large language model?

The best way to generate valid XML is by using grammar-based generation to enforce complex structures. This applies context-free grammars to the LLM, guaranteeing syntactically correct XML outputs for APIs.

How do context-free grammars work for constraining code generation?

Context-free grammars work for constraining code generation by defining strict structural rules that the LLM must follow. This enforces complex structures and ensures the generated code snippets are syntactically valid.

Why does my LLM output have broken token boundaries in structured data?

Broken token boundaries in structured data often occur due to tokenization misalignment during generation. Token healing automatically corrects these boundaries, ensuring natural text flow and valid structured output.