dspy

Build declarative LM programs with automatic prompt optimization and modular pipelines.

Updated Jul 3, 2026
One-click install
npx skills add https://github.com/CHENHUI-X/toolbox --skill dspy-chenhui-x
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dspy
Source: https://github.com/CHENHUI-X/toolbox/tree/main/custom-skills/research/dspy
Command: npx skills add https://github.com/CHENHUI-X/toolbox --skill dspy-chenhui-x

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 language model programs declaratively and optimize prompts automatically using training data instead of trial-and-error tuning. ## Core Features & Use Cases - Declarative LM Programming: Define tasks with Signatures (inputs → outputs) and compose Modules like Predict, ChainOfThought, ReAct, and ProgramOfThought into complex pipelines. - Automatic Prompt Optimization: Use optimizers such as BootstrapFewShot, MIPRO, and BootstrapFinetune to improve prompts and generate fine-tuning data from labeled examples. - Use Case: Build a RAG question-answering system, then compile it with BootstrapFewShot on 50 training examples to measurably improve answer accuracy without rewriting any 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 and training examples, then use an optimizer like BootstrapFewShot to compile your module. The optimizer generates few-shot demonstrations from your data and embeds them into prompts, improving accuracy without manual prompt editing.

What is the difference between DSPy Predict and ChainOfThought?

Predict makes a direct LM call for simple tasks, while ChainOfThought generates reasoning steps 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 LM pipelines?

DSPy optimizes prompts automatically from training data and offers typed signatures with high modularity, while LangChain relies on manual prompt engineering with prebuilt chains. Choose DSPy when you have training data and need systematic improvement.

Does DSPy support local models like Ollama?

Yes, DSPy supports local models through dspy.OllamaLocal by pointing to a local server URL. It also works with OpenAI, Anthropic Claude, and allows mixing multiple models for different pipeline stages.

How many training examples does DSPy optimization need?

BootstrapFewShot works with 10-50 examples, while MIPRO performs best with 50-200 examples plus a separate validation set. BootstrapFinetune for model fine-tuning recommends 100 or more examples.

When should I not use DSPy?

Avoid DSPy for quick one-off prototypes where manual prompting is faster, or when you lack any training data for optimization. It also has a steeper learning curve than simple prompt templates for basic tasks.