dspy

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

Updated Sep 10, 2026
One-click install
npx skills add https://github.com/loteiron/ZeusAgent --skill dspy-loteiron
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: dspy
Source: https://github.com/loteiron/ZeusAgent/tree/main/optional-skills/mlops/research/dspy
Command: npx skills add https://github.com/loteiron/ZeusAgent --skill dspy-loteiron

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Manually tuning prompts for language model applications is slow, brittle, and hard to reproduce. DSPy replaces hand-crafted prompts with declarative signatures and modules, then uses data-driven optimizers to automatically improve prompts and few-shot examples against a metric you define. ## 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 BootstrapFewShot, MIPRO, COPRO, and BootstrapFinetune to generate demonstrations, tune instructions, or export fine-tuning datasets from training examples. - Composable 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 any 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 compile your module with an optimizer like BootstrapFewShot or MIPRO. The optimizer generates few-shot demonstrations and improved instructions from your data, producing a module that scores higher on your metric.

What is the difference between DSPy Predict and ChainOfThought?▼

Predict makes a direct LM call from a signature without reasoning steps, making it faster for simple tasks. ChainOfThought generates a rationale before the answer, roughly doubling latency but improving accuracy on reasoning and math problems.

DSPy vs LangChain: which should I use for LM pipelines?▼

DSPy optimizes prompts automatically from training data and offers typed signatures with high modularity, suiting complex multi-stage systems. LangChain fits quick prototypes and simple chains using existing tool integrations where manual prompting is acceptable.

Does DSPy support local models like Ollama?▼

Yes, DSPy supports local models through dspy.OllamaLocal pointed at a local base URL such as http://localhost:11434. It also supports OpenAI, Anthropic Claude, and multiple models configured for different pipeline stages.

How many training examples does DSPy optimization need?▼

BootstrapFewShot works with 10-50 examples, while MIPRO benefits from 50-200 examples plus a separate validation set. BootstrapFinetune for weight fine-tuning recommends 100 or more examples to avoid overfitting.

Why is my DSPy optimizer overfitting the training data?▼

Overfitting happens when max_bootstrapped_demos is set too high or the training set is too small and unrepresentative. Keep bootstrapped demos at 3-5, use diverse examples covering edge cases, and always evaluate on a held-out test set.