dspy

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Manual prompt engineering is brittle, hard to maintain, and difficult to improve systematically. This Skill replaces hand-tuned prompts with declarative, data-driven LM programming using Stanford NLP's DSPy framework, so prompts and pipelines optimize automatically from training 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 Prompt Optimization: Use teleprompters like BootstrapFewShot, MIPRO, and BootstrapFinetune to improve prompts and generate fine-tuning data from metrics. - Composable Pipelines: Build multi-stage RAG systems, agents, classifiers, and extraction pipelines with typed outputs via Pydantic. - Use Case: Build a multi-hop RAG question-answering system, define an exact-match metric, then compile it with BootstrapFewShot on 50 examples to measurably improve answer accuracy without rewriting any 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 compile your module with an optimizer like BootstrapFewShot or MIPRO. The optimizer generates few-shot demonstrations and better instructions from your data, producing an improved module without manual prompt editing.

How do I build a RAG system with DSPy?▼

Create a dspy.Module combining dspy.Retrieve for fetching passages and dspy.ChainOfThought for generating answers from context. Configure a retriever like ChromadbRM, then optionally optimize the pipeline with BootstrapFewShot using question-answer training pairs.

DSPy vs LangChain: which should I use for LM pipelines?▼

DSPy optimizes prompts automatically from data and metrics, offering typed signatures and portable modules, 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 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 to avoid overfitting.

When should I not use DSPy?▼

Avoid DSPy for quick one-off prototypes where manual prompting suffices, or when you lack any training data or a definable metric. Its optimization loop adds complexity and compute cost that simple chains do not justify.