dspy

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

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

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. DSPy replaces hand-tuned prompts with declarative signatures and modules that can be automatically optimized against your own data and metrics. ## 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 generate few-shot examples and improve instructions from training data. - 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 Install dspy with pip, configure your LM provider such as Claude or OpenAI, define a signature like "question -> answer", and run dspy.ChainOfThought on your first question.

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 a teleprompter such as BootstrapFewShot with a metric function and a training set of dspy.Example objects. Call optimizer.compile(module, trainset=trainset) to generate few-shot demonstrations that improve your module's accuracy 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 LLM pipelines?▼

DSPy optimizes prompts automatically from data and offers typed 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; 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 base URL such as http://localhost:11434. It also supports OpenAI, Anthropic Claude, and multiple models configured for different pipeline stages.

How much training data 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.

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 or metrics to optimize against. It also adds a medium-high learning curve compared to direct API calls.