guidance

Enforce regex and grammar constraints during LLM inference for valid structured outputs.

1|Updated Apr 24, 2026
One-click install
npx skills add https://github.com/automatedigital/spark --skill guidance-automatedigital
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/automatedigital/spark/tree/main/skills/mlops/inference/guidance
Command: npx skills add https://github.com/automatedigital/spark --skill guidance-automatedigital

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill solves the frequent issue of LLMs generating malformed, invalid structured outputs (such as broken JSON, incorrectly formatted dates, or syntactically invalid code) that break downstream automation, data processing, and integration workflows.

Core Features & Use Cases

  • Constrained Generation: Enforce valid output formats using regex patterns, context-free grammars, and selection constraints for JSON, XML, code, and custom data formats.
  • Token Healing: Automatically fix awkward tokenization boundaries to produce natural, correctly spaced text without manual prompt tuning.
  • Reusable Workflows: Build multi-step LLM workflows including data extraction, classification, and ReAct agent tool use with Pythonic control flow. For example, if you need to extract customer data from unstructured support tickets into valid JSON for your CRM, this Skill guarantees the output matches your required schema without manual validation or retry loops.

Quick Start

Use the Guidance skill to generate a valid JSON user profile with name, age, and email fields from the provided unstructured customer support text.

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 output from LLM inference without retry loops?

To guarantee valid JSON output from LLM inference, apply regex patterns and grammar-based constraints during generation to eliminate malformed structures. This enforces schema compliance directly in the decoding phase, removing the need for manual validation or retry loops.

Does constrained generation work with Anthropic, OpenAI, and local llama.cpp models?

Yes, constrained generation is compatible with Anthropic, OpenAI, Hugging Face Transformers, and local llama.cpp backends. Regex constraints and selection rules apply uniformly across these API and local model providers to ensure valid structured outputs.

What's the best way to extract unstructured text into valid JSON for workflow automation?

The best way to extract unstructured text into valid JSON is using context-free grammars and selection constraints during generation. This guarantees the extracted data matches your required schema automatically, enabling seamless downstream workflow automation.

Why does my LLM produce broken JSON and malformed code during generation?

LLMs produce broken JSON and malformed code due to unconstrained generation and awkward tokenization boundaries. Applying grammar-based constraints and automatic token healing fixes these boundaries to produce natural, correctly spaced, and syntactically valid text.

Can I build multi-step ReAct agent workflows with format enforcement?

Yes, you can build multi-step ReAct agent workflows with Pythonic control flow while enforcing format constraints. This ensures tool use outputs remain valid JSON or XML throughout the entire data extraction and classification process.

When do I need regex constraints for LLM structured output?

You need regex constraints for LLM structured output when generating custom formatted data, valid JSON, XML, or code for downstream automation. It is required when unconstrained generation breaks data processing and integration workflows.