claudegoodies
Skill

guidance

From NousResearch

Control LLM output with regex and grammars, guarantee valid JSON/XML/code generation, enforce structured formats, and build multi-step workflows with Guidance - Microsoft Research's constrained generation framework

Wraps Guidance (Microsoft Research's Python library) to constrain LLM output with regex, grammars, and select() for guaranteed valid JSON/XML/structured formats.

Use it when

  • Need generated output to match a regex, e.g. dates, emails, phone numbers
  • Forcing valid JSON/XML output structure without post-hoc validation
  • Restricting model output to a fixed set of choices via select()
  • Building multi-step generation workflows with Pythonic control flow and @guidance functions

Skip it if

  • Requires installing and depending on the guidance and transformers Python packages
  • Only useful if working in Python with models Guidance supports (OpenAI, Anthropic, Transformers, llama.cpp)
  • Modern LLM APIs already offer native JSON mode/structured output tooling that may cover simpler cases

Facts

Status
Actively maintained
Last commit

Source preview

The instructions Claude Code reads when this skill runs.

# Guidance: Constrained LLM Generation

## When to Use This Skill

Use Guidance when you need to:
- **Control LLM output syntax** with regex or grammars
- **Guarantee valid JSON/XML/code** generation
- **Reduce latency** vs traditional prompting approaches
- **Enforce structured formats** (dates, emails, IDs, etc.)
- **Build multi-step workflows** with Pythonic control flow
- **Prevent invalid outputs** through grammatical constraints

**GitHub Stars**: 18,000+ | **From**: Microsoft Research

## Installation

```bash
# Base installation
pip install guidance

# With specific backends
pip install guidance[transformers]  # Hugging Face models
pip install guidance[llama_cpp]     # llama.cpp models
```

## Quick Start

### Basic Example: Structured Generation

```python
from guidance import models, gen

# Load model (supports OpenAI, Transformers, llama.cpp)
lm = models.OpenAI("gpt-4")

# Generate with constraints
result = lm + "The capital of France is " + gen("capital", max_tokens=5)

print(result["capital"])  # "Paris"
```

### With Anthropic Claude

```python
from guidance import models, gen, system, user, assistant

# Configure Claude
lm = models.Anthropic("claude-sonnet-4-5-20250929")

# Use context managers for chat format
with system():
    lm += "You are a helpful assistant."

with user():
    lm += "What is the capital of France?"

with assistant():
    lm += gen(max_token
View full source on GitHub →

Other skills