dspy

Build declarative LM pipelines with automatic prompt optimization using DSPy.

13.0k|930|Updated Nov 3, 2025
One-click install
npx skills add https://github.com/Orchestra-Research/AI-research-SKILLs --skill dspy-orchestra-research
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: dspy
Source: https://github.com/Orchestra-Research/AI-research-SKILLs/tree/main/16-prompt-engineering/dspy
Command: npx skills add https://github.com/Orchestra-Research/AI-research-SKILLs --skill dspy-orchestra-research

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 port across language models. This Skill replaces hand-tuned prompts with declarative signatures and modules, then uses data-driven optimizers to systematically improve prompts and pipelines. ## 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, and BootstrapFinetune to generate few-shot examples, tune instructions, and export fine-tuning data from training examples. - Complex Pipelines: Build multi-stage RAG systems, tool-using agents, 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 compile your module with an optimizer like BootstrapFewShot or MIPRO. The optimizer generates few-shot demonstrations and improved instructions from your data, producing a better-performing module without manual prompt edits.

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 LLM pipelines?▼

DSPy offers automatic data-driven prompt optimization, typed signatures, and high portability across models, while LangChain relies on manual prompts with prebuilt chains. Choose DSPy when you have training data and need systematic improvement; choose LangChain for quick prototypes with existing tools.

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 mixing multiple models for different pipeline stages.

How many training examples does DSPy optimization need?▼

BootstrapFewShot works with 10-50 examples, MIPRO benefits from 50-200 examples plus a validation set, and BootstrapFinetune recommends 100 or more. Insufficient data is a common cause of poor optimization results.

How do I get structured JSON output from a language model in DSPy?▼

Use dspy.TypedPredictor with a Pydantic BaseModel as the output field type in your signature. This provides type safety, automatic validation, and JSON schema generation for structured extraction tasks.