dspy

Build declarative language-model programs and optimize prompts for RAG pipelines.

Updated Mar 25, 2026
One-click install
npx skills add https://github.com/afel6/scal-ai-pipeline --skill dspy-afel6
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dspy
Source: https://github.com/afel6/scal-ai-pipeline/tree/main/hermes_skills_library/mlops/research/dspy
Command: npx skills add https://github.com/afel6/scal-ai-pipeline --skill dspy-afel6

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

dspy removes brittle manual prompt engineering and ad-hoc LM calls by providing a declarative, modular programming model for language models that makes pipelines reproducible, testable, and optimizable.

Core Features & Use Cases

  • Declarative Signatures & Modules: Define inputs and outputs with typed signatures and compose Predict, ChainOfThought, ProgramOfThought, and ReAct modules into reusable pipelines.
  • Automatic Prompt Optimization: Improve performance using built-in optimizers (BootstrapFewShot, MIPRO, BootstrapFinetune) and custom metrics for few-shot and instruction tuning.
  • RAG & Agent Integration: Build retrieval-augmented generation, multi-stage QA, and agentic systems with retrieval, reranking, and tool use while exporting optimized modules for production.
  • Use Case: Create a multi-hop RAG system that generates search queries, retrieves supporting documents, reranks passages, and produces concise, validated answers for research or customer support.

Quick Start

Use dspy to declare a QA signature, wire a retriever and a ChainOfThought generator, and run a question through the pipeline to get a concise, validated answer.

Frequently Asked Questions about dspy

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

FAQPage Schema
How do I build declarative LM pipelines for modular RAG and agents?

To build RAG and agent pipelines, define typed input/output signatures and compose ChainOfThought or ReAct modules. This declarative approach replaces brittle manual prompt engineering with reproducible, testable language model programs for multi-stage question answering.

What is automatic prompt optimization for language model programs?

Automatic prompt optimization improves language model program performance using built-in optimizers like BootstrapFewShot, MIPRO, and BootstrapFinetune. These optimizers apply few-shot and instruction tuning against custom metrics, removing the need for ad-hoc manual prompt adjustments.

How do I create a multi-hop RAG system that retrieves and reranks documents?

Multi-hop RAG systems are created by wiring a retriever and a ChainOfThought generator into a declarative pipeline. The system generates search queries, retrieves supporting documents, reranks passages, and produces concise, validated answers for research or support.

Does dspy support multi-provider language models for production ML pipelines?

Yes, production ML pipelines are supported with multi-provider language model integration. Optimized declarative modules can be exported for production use, ensuring retrieval-augmented generation and agentic tool use workflows remain reproducible and scalable.

What's the best way to replace manual prompt engineering with reproducible code?

The best way to replace manual prompt engineering is using declarative signatures and modular programming for language models. This makes pipelines reproducible and testable, applying automatic optimizers like MIPRO and BootstrapFewShot instead of ad-hoc prompt tuning.

When should I not use declarative programming for language model pipelines?

Declarative programming for language models may not suit projects requiring single, isolated ad-hoc LM calls without optimization. It is designed for modular pipelines, structured signatures, and multi-stage workflows needing automatic few-shot or instruction tuning.