dspy

Build declarative LM pipelines with automatic prompt optimization using DSPy.

2|Updated Aug 15, 2026
One-click install
npx skills add https://github.com/Jensen-Yao/agents-skills --skill dspy-jensen-yao
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: dspy
Source: https://github.com/Jensen-Yao/agents-skills/tree/main/skills/dspy
Command: npx skills add https://github.com/Jensen-Yao/agents-skills --skill dspy-jensen-yao

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Manual prompt engineering is fragile and hard to maintain when building multi-stage AI systems like RAG pipelines, agents, and classifiers. This Skill provides expert guidance for DSPy, Stanford NLP's framework that replaces hand-tuned prompts with declarative signatures and data-driven automatic optimization. ## Core Features & Use Cases - Declarative Signatures & Modules: Define tasks as input-output signatures and compose them with Predict, ChainOfThought, ReAct, and ProgramOfThought modules. - Automatic Prompt Optimization: Use teleprompters like BootstrapFewShot, MIPRO, and BootstrapFinetune to improve prompts and generate fine-tuning data from training examples. - Complex System Patterns: Build multi-hop RAG, reranking pipelines, multi-agent routers, and typed structured extraction with Pydantic models. - Use Case: You need a question-answering system over your documents. Define a RAG module with retrieval and generation stages, then compile it with BootstrapFewShot against 50 labeled examples to automatically learn effective few-shot demonstrations. ## 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 or searches for better instructions, returning an improved 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.

DSPy vs LangChain: which should I use for RAG?▼

DSPy offers automatic data-driven prompt optimization, typed signatures, and higher modularity, while LangChain provides manual chains with many existing tool integrations. Choose DSPy when you have training data and need systematic improvement across different LMs.

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 configuring 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 separate 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 suffices, or when you lack any training data for optimization. It also has a medium-to-high learning curve compared to simple prompt templates.