dspy

Build declarative modular language-model programs and optimize prompts with DSPy teleprompters.

Updated May 2, 2026
One-click install
npx skills add https://github.com/qcmuu/AI-Research-Skills --skill dspy-qcmuu
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dspy
Source: https://github.com/qcmuu/AI-Research-Skills/tree/main/16-prompt-engineering/dspy
Command: npx skills add https://github.com/qcmuu/AI-Research-Skills --skill dspy-qcmuu

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

DSPy replaces brittle, hand-written prompt chains with a declarative way to define LM programs and then optimize them using examples and evaluation metrics.

Core Features & Use Cases

  • Declarative signatures for LM tasks: Define inputs/outputs for classification, extraction, QA, and structured generation.
  • Composable modules for multi-stage systems: Build pipelines for RAG, agents (ReAct), multi-hop reasoning, and code-assisted computation.
  • Automatic prompt optimization: Improve performance with teleprompters like BootstrapFewShot and MIPRO using a user-defined metric.
  • Strong practical patterns: Structured outputs, retrieval + generation, reranking, verification loops, and evaluation tooling.

Use it when you need dependable research workflows (e.g., RAG + reranking) or agentic systems that must be improved systematically rather than by repeated manual prompt tweaking.

Quick Start

Tell your AI coding agent: "Install DSPy, define a QA signature, implement a retrieval-augmented module with DSPy.Retrieve and ChainOfThought, then optimize the module with BootstrapFewShot using a correctness metric."

Frequently Asked Questions about dspy

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I automatically optimize prompts for RAG pipelines instead of manual tweaking?

To automatically optimize prompts for RAG pipelines, define declarative signatures and modules, then use teleprompters like BootstrapFewShot with a user-defined correctness metric. This replaces manual prompt tweaking by systematically compiling and tuning language-model programs using evaluation-driven feedback loops.

What is declarative programming for language-model programs and when should I use it?

Declarative programming for language-model programs defines inputs and outputs for tasks like classification and extraction without hand-written prompt chains. Use it for dependable research workflows, multi-stage reasoning, or agentic systems that require systematic improvement rather than manual prompt adjustments.

How do I build multi-stage agents with structured outputs using OpenAI and Anthropic providers?

Build multi-stage agents with structured outputs by configuring an OpenAI or Anthropic LM provider and composing modular pipelines. Define task signatures, implement retrieval-augmented modules with ChainOfThought, and apply teleprompters to compile and optimize the agentic system using metric-based feedback.

Can I use DSPy to build ReAct agents and multi-hop reasoning systems?

Yes, you can build ReAct agents and multi-hop reasoning systems using composable modules. Define declarative signatures for each reasoning stage, configure your LM provider, and apply automatic prompt optimization with teleprompters to systematically improve agent performance using evaluation metrics.

Does DSPy support evaluation-driven prompt tuning for classification and extraction tasks?

DSPy supports evaluation-driven prompt tuning for classification and extraction by applying teleprompters to optimize declarative signatures. You define a metric-based feedback loop, then compile the language-model program using BootstrapFewShot or MIPRO to automatically improve structured generation accuracy.

What are the limitations of automatic prompt optimization for complex AI pipelines?

Automatic prompt optimization for complex AI pipelines requires defining explicit signatures, configuring LM providers, and providing a user-defined evaluation metric. It depends on metric-based feedback loops and teleprompters, meaning poor metrics or insufficient examples will yield suboptimal compilation results for multi-stage reasoning systems.