dspy

Build and optimize declarative language model pipelines with DSPy signatures, modules, and optimizers.

14|5|Updated Apr 9, 2026
One-click install
npx skills add https://github.com/MLT-OSS/hermes-agent-go --skill dspy-mlt-oss
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dspy
Source: https://github.com/MLT-OSS/hermes-agent-go/tree/main/skills/mlops/research/dspy
Command: npx skills add https://github.com/MLT-OSS/hermes-agent-go --skill dspy-mlt-oss

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Manually tuning prompts for complex LLM systems is fragile and hard to reproduce. This Skill teaches how to program language models declaratively with DSPy, replacing hand-written prompts with structured 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 BootstrapFewShot, MIPRO, and BootstrapFinetune to improve prompts and generate fine-tuning data from training examples. - Production Pipelines: Build RAG systems, multi-hop retrieval, agents, classifiers, and multi-stage document pipelines with evaluation metrics. - Use Case: Build a RAG question-answering system, define an exact-match metric, then run BootstrapFewShot on 50 examples to automatically generate few-shot demonstrations that raise accuracy without manual prompt edits. ## 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 the BootstrapFewShot optimizer with a metric function and 10-50 training examples. Call optimizer.compile(module, trainset=trainset) and DSPy generates few-shot demonstrations from high-scoring predictions, improving your module without manual prompt edits.

How to build a RAG system with DSPy?

Create a dspy.Module combining dspy.Retrieve(k=3) with a ChainOfThought module taking context and question as inputs. Configure a retriever like ChromadbRM, then optionally optimize the pipeline with BootstrapFewShot using question-answer training pairs.

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, improving accuracy on math and logic tasks. ChainOfThought is roughly twice as slow but significantly better for complex reasoning.

Does DSPy support Anthropic Claude and local models?

Yes. Configure Claude with dspy.Claude(model=..., api_key=...), OpenAI with dspy.OpenAI, and local models via dspy.OllamaLocal pointing at a local server. You can also switch models per task using dspy.settings.context.

When should I use MIPRO instead of BootstrapFewShot?

Use MIPRO when you have 50-200 training examples plus a separate validation set and want state-of-the-art instruction optimization. It runs 100+ trials over 10-30 minutes, while BootstrapFewShot is faster and better as a first attempt with smaller datasets.

Why does DSPy optimization overfit my training data?

Overfitting happens when max_bootstrapped_demos is set too high or training data is too small. Keep demonstrations at 3-5, use proper train/validation/test splits, and evaluate the optimized module only on a held-out test set.