dspy

Build declarative LM pipelines with automatic prompt optimization using DSPy signatures, modules, and optimizers.

1|Updated Mar 5, 2026
One-click install
npx skills add https://github.com/Clay-HHK/claude-skills --skill dspy-clay-hhk
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: dspy
Source: https://github.com/Clay-HHK/claude-skills/tree/main/dspy
Command: npx skills add https://github.com/Clay-HHK/claude-skills --skill dspy-clay-hhk

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires dspy, openai, anthropic, and includes references (resource) components.

What problem does it solve? Manual prompt engineering is fragile, hard to maintain, and difficult to improve systematically. This Skill helps you build complex LM-powered systems declaratively and optimize prompts automatically using training data instead of trial-and-error tuning. ## Core Features & Use Cases - Declarative Signatures and Modules: Define tasks as input-output signatures and compose them with Predict, ChainOfThought, ReAct, and ProgramOfThought modules. - Automatic Prompt Optimization: Use BootstrapFewShot, MIPRO, and BootstrapFinetune optimizers to improve prompts and generate fine-tuning data from labeled examples. - Complex Pipelines: Build multi-stage RAG systems, tool-using agents, classifiers, and structured extraction pipelines with type-safe Pydantic outputs. - Use Case: Build a multi-hop RAG question-answering system, then optimize it with BootstrapFewShot on 50 labeled examples to measurably improve answer accuracy without rewriting prompts by hand. ## Quick Start Use the dspy skill to build a chain-of-thought question answering module and optimize it with BootstrapFewShot on my training examples.

Frequently Asked Questions about dspy

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

FAQPage Schema
How do I optimize prompts automatically with DSPy?▼

Define a metric function, prepare labeled training examples with dspy.Example, then compile your module with an optimizer like BootstrapFewShot or MIPRO. The optimizer generates few-shot demonstrations and improved instructions based on your metric scores.

What is the difference between DSPy Predict and ChainOfThought?▼

Predict makes a direct LM call for simple tasks, while ChainOfThought generates step-by-step reasoning before the answer. ChainOfThought is roughly twice as slow but significantly more accurate on math and logical reasoning tasks.

DSPy vs LangChain: which should I use for building agents?▼

DSPy offers automatic data-driven prompt optimization, typed signatures, and high modularity, while LangChain relies on manual prompting with pre-built chains. Choose DSPy when you have training data and need systematic improvement; choose LangChain for quick prototypes with existing integrations.

Does DSPy support Claude and local models like Ollama?▼

Yes, DSPy supports Anthropic Claude via dspy.Claude, OpenAI via dspy.OpenAI, and local models through dspy.OllamaLocal. You can also configure different models for different pipeline stages using dspy.settings.context.

How many training examples does DSPy optimization need?▼

BootstrapFewShot works with 10-50 examples, MIPRO performs best with 50-200 examples plus a validation set, and BootstrapFinetune recommends 100 or more examples. Insufficient data leads to overfitting and poor generalization.

Why is my DSPy optimizer overfitting to training data?▼

Overfitting happens when max_bootstrapped_demos is set too high, training data is too small, or no held-out validation set is used. Keep bootstrapped demos at 3-5, split data into train/validation/test sets, and evaluate on unseen examples.