DSPy

DSPy

★ 4.4 🔖 7000 saves 💰 Free GitHub

DSPy is Stanford’s framework for programming — not prompting — language models, with 38,000+ stars on GitHub, turning fragile hand-written prompts into modular, self-optimizing Python programs.

Overview

Hand-tuned prompts break every time you change models or data. DSPy (Declarative Self-improving Python, from Stanford NLP) replaces them with code: you declare what a step should do with a Signature, compose steps into Modules such as chain-of-thought or ReAct agents, and let DSPy’s optimizers automatically compile the prompts and few-shot demonstrations that make your program hit its metric. The framework grew out of a line of peer-reviewed research, most recently GEPA (2025), a reflective prompt-evolution optimizer reported to outperform reinforcement learning approaches for prompt optimization. Because programs are model-agnostic Python, the same pipeline can be re-optimized when you swap the underlying LM. DSPy is widely used for serious RAG pipelines, agent loops and classifiers where quality must be measured and improved systematically rather than vibes-tested. Documentation lives at dspy.ai, and the project is actively maintained as of October 2026.

Key Features

  • Signatures – declare inputs and outputs; DSPy handles the prompting mechanics.
  • Composable modules – Predict, ChainOfThought, ReAct and more, combined into full pipelines.
  • Automatic optimizers – compile prompts and demonstrations against your metric, including the GEPA optimizer.
  • Model-agnostic – re-optimize the same program when you change language-model providers.
  • RAG and agents – building blocks for retrieval pipelines and tool-using agent loops.
  • Evaluation built in – metrics and datasets are first-class parts of the workflow.
  • Research-grade lineage – backed by Stanford NLP papers on prompt and pipeline optimization.

💳 Pricing

DSPy is free and open source under the MIT license. The only cost is inference: you pay your chosen model provider’s API rates, or nothing when running local models.

Who Is It For

Developers and researchers building production LM systems — RAG, agents, classification — who want prompts that are optimized by data and metrics instead of maintained by hand.

🚀 Visit DSPy Official Site

🚩 Report an issue