dspy

Build and optimize declarative language model programs with signatures, modules, and teleprompters.

Updated Jun 5, 2026
One-click install
npx skills add https://github.com/xu1713/openhorse --skill dspy-xu1713
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dspy
Source: https://github.com/xu1713/openhorse/tree/main/openhorse/openhorse/skills/mlops/research/dspy
Command: npx skills add https://github.com/xu1713/openhorse --skill dspy-xu1713

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Manual prompt engineering is brittle, hard to maintain, and difficult to improve systematically. DSPy replaces hand-tuned prompts with declarative signatures and modules, then automatically optimizes prompts and few-shot examples from training data. ## Core Features & Use Cases - Declarative Signatures & Modules: Define tasks as input-output signatures and compose them with Predict, ChainOfThought, ReAct, and ProgramOfThought modules. - Automatic Optimization: Use teleprompters like BootstrapFewShot, MIPRO, and BootstrapFinetune to improve prompts and generate fine-tuning data from labeled examples. - Complex Pipelines: Build multi-stage RAG systems, agents with tools, classifiers, and structured extraction with Pydantic-typed 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. ## 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 a teleprompter like BootstrapFewShot or MIPRO to compile your module. The optimizer generates few-shot demonstrations and improved instructions from your data, producing an optimized module 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.

How does DSPy compare to LangChain for building LLM pipelines?

DSPy optimizes prompts automatically from data and offers typed signatures with high modularity, while LangChain relies on manual prompts and prebuilt chains. Choose DSPy when you have training data and need systematic improvement; choose LangChain for quick prototypes with existing integrations.

Does DSPy support local models like Ollama?

Yes, DSPy supports local models through dspy.OllamaLocal by pointing to a local base URL such as http://localhost:11434. It also supports OpenAI, Anthropic Claude, and other providers, and you can mix models for different pipeline stages.

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 is a common cause of poor optimization results.

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 medium-to-high learning curve compared to direct prompting.