dspy

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

Updated Jun 7, 2026
One-click install
npx skills add https://github.com/Chensihakniroth/ANAKOT-AGENT --skill dspy-chensihakniroth
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: dspy
Source: https://github.com/Chensihakniroth/ANAKOT-AGENT/tree/main/optional-skills/mlops/research/dspy
Command: npx skills add https://github.com/Chensihakniroth/ANAKOT-AGENT --skill dspy-chensihakniroth

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 teaches how to use DSPy to program language models declaratively and optimize prompts automatically using data-driven methods instead of trial-and-error tuning. ## Core Features & Use Cases - Declarative LM Programming: Define tasks with Signatures (inputs → outputs) and compose them with modules like Predict, ChainOfThought, ReAct, and ProgramOfThought. - Automatic Prompt Optimization: Use optimizers such as BootstrapFewShot, MIPRO, and BootstrapFinetune to improve prompts and generate fine-tuning data from training examples. - Complex AI Pipelines: Build multi-stage RAG systems, tool-using agents, classifiers, and structured extraction pipelines with type-safe Pydantic outputs. - Use Case: Imagine you are building a question-answering system over company documents. Use this Skill to construct a RAG pipeline, define an accuracy metric, and let DSPy automatically optimize the prompts against your training set. ## 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?▼

Use DSPy optimizers like BootstrapFewShot or MIPRO by providing a training set of examples and a metric function. The optimizer generates few-shot demonstrations or searches for better instructions, then compiles an improved version of your module.

What is the difference between DSPy Predict and ChainOfThought?▼

Predict makes a direct LM call without reasoning steps, making it faster for simple tasks. ChainOfThought generates a rationale before the answer, which improves accuracy on reasoning and math problems but runs roughly twice as slow.

DSPy vs LangChain for building LLM applications?▼

DSPy optimizes prompts automatically from data and offers type-safe 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 base URL such as http://localhost:11434. It also supports OpenAI, Anthropic Claude, and other providers through a unified configuration interface.

How many training examples does DSPy need for optimization?▼

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 does DSPy optimization overfit my training data?▼

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