dspy

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

Updated May 4, 2026
One-click install
npx skills add https://github.com/Junkfooooood/hermes-governance --skill dspy-junkfooooood
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dspy
Source: https://github.com/Junkfooooood/hermes-governance/tree/main/skills/mlops/research/dspy
Command: npx skills add https://github.com/Junkfooooood/hermes-governance --skill dspy-junkfooooood

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, then uses data-driven optimizers to automatically improve prompts and few-shot examples. ## 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 demonstrations and better instructions from training data. - 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 use an optimizer like BootstrapFewShot to compile your module. The optimizer generates few-shot demonstrations from high-scoring predictions and injects them into future prompts automatically.

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 training data and offers typed signatures with high modularity, while LangChain relies on manual prompt engineering with prebuilt chains. Choose DSPy when you have labeled data and need systematic improvement.

Does DSPy support Anthropic Claude and local models?

Yes, DSPy supports Anthropic Claude via dspy.Claude, OpenAI via dspy.OpenAI, and local models through dspy.OllamaLocal. You can also configure different models for different pipeline stages using dspy.settings.context.

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.

When should I not use DSPy?

Avoid DSPy for quick one-off prototypes where manual prompting suffices, or when you lack training data for optimization. It also adds a medium-high learning curve compared to simple prompt strings.