guidance

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

Updated Apr 12, 2026
One-click install
npx skills add https://github.com/thisismynewfmail-ui/Monika-agent --skill guidance-thisismynewfmail-ui
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/thisismynewfmail-ui/Monika-agent/tree/main/skills/mlops/inference/guidance
Command: npx skills add https://github.com/thisismynewfmail-ui/Monika-agent --skill guidance-thisismynewfmail-ui

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

It solves the difficulty of obtaining reliably formatted and valid LLM outputs, preventing malformed JSON, XML, code, or other structured data.

Core Features & Use Cases

  • Regex & Grammar Constraints: Guarantees syntax compliance for generated text.
  • Token Healing: Ensures natural token boundaries without spacing errors.
  • Multi‑Step Workflows: Enables complex pipelines where each step respects format rules.
  • Use Case Example: Build a data‑extraction pipeline that reliably returns well‑formed JSON objects from raw model responses.

Quick Start

Ask the guidance skill to generate a valid JSON object for a user profile.

Frequently Asked Questions about guidance

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

FAQPage Schema
How do I guarantee valid JSON from an LLM response?

To guarantee valid JSON from an LLM response, use regex and grammar constraints to enforce syntax compliance during generation. This prevents malformed structured data and ensures the output matches your required format.

What is constrained generation for large language models?

Constrained generation controls LLM output by applying regex and grammar rules to token selection. This mechanism ensures the generated text strictly adheres to specified formats like JSON or XML.

How do I build a multi-step LLM workflow with structured output?

You can build multi-step LLM workflows by applying format constraints at each generation stage. This ensures every pipeline step respects the required syntax rules for structured data extraction.

Does the Guidance library work with Hugging Face transformers?

Yes, the Guidance library works with Hugging Face transformers as a compatible backend. You need both the Guidance Python library and a supported backend like transformers to enforce output constraints.

Why does my LLM generate broken XML or code syntax?

Broken XML or code generation often occurs due to unnatural token boundaries during text generation. Applying grammar constraints and token healing ensures natural boundaries and prevents syntax errors.

Can I enforce regex patterns during LLM text generation?

Yes, you can enforce regex patterns during LLM text generation to restrict the model's output. This guarantees the generated text complies with specific syntax requirements before the response is returned.