guidance

Enforce regex or grammar constraints on LLM text generation in Python.

1|Updated Feb 10, 2026
One-click install
npx skills add https://github.com/informatico-madrid/Architect-Expert-Gap-Forge --skill guidance-informatico-madrid
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: guidance
Source: https://github.com/informatico-madrid/Architect-Expert-Gap-Forge/tree/main/.github/skills/guidance
Command: npx skills add https://github.com/informatico-madrid/Architect-Expert-Gap-Forge --skill guidance-informatico-madrid

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill solves the challenge of generating predictable, structured, and valid outputs from Large Language Models, overcoming the inherent randomness of free-form text generation.

Core Features & Use Cases

  • Constrained Generation: Enforce syntax using regex or grammars, guaranteeing valid JSON, XML, code, or specific formats.
  • Structured Workflows: Build multi-step LLM interactions with Pythonic control flow.
  • Use Case: Generate a valid JSON object representing a user profile, ensuring all fields (name, email, age) adhere to strict formats, preventing downstream parsing errors.

Quick Start

Use the guidance skill to generate a JSON object for a user profile with name, age, and email.

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?

To force an LLM to generate valid JSON output, you can use constrained generation techniques that enforce syntax via regular expressions and grammars, guaranteeing predictable structured outputs and preventing downstream parsing errors.

What is constrained text generation in large language models?

Constrained text generation is a mechanism that enforces specific syntax using regular expressions or grammars to control LLM outputs, overcoming the inherent randomness of free-form text generation to produce valid formats.

Can I use structured output generation with local models via llama.cpp?

Yes, structured output generation integrates with various LLM backends including OpenAI, Anthropic, and local models via Transformers or llama.cpp, allowing you to apply grammatical constraints across different model environments.

How do I build multi-step LLM interactions with Pythonic control flow?

You can build multi-step LLM interactions with Pythonic control flow by using libraries that support structured workflows, enabling the creation of complex generation sequences that enforce syntax at each step.

Why does my LLM output fail JSON parsing even with explicit instructions?

LLM output fails JSON parsing due to inherent generation randomness, which can be solved by enforcing syntax via regular expressions and grammars to guarantee strict format adherence and prevent unexpected parsing errors.

Does constrained generation work with Anthropic and OpenAI models?

Yes, constrained generation supports integration with various LLM backends including OpenAI and Anthropic, allowing you to apply regex and grammar-based syntax enforcement across different API providers.