Tools / Prompt programming & optimization

DSPy

framework

Stanford-born framework for programming - not prompting - LMs; declare tasks as signatures and let optimizers tune prompts and weights.

Role Prompt programming and optimizationMaintained by Stanford NLP GroupLanguages PythonLicense MIT

What it is

DSPy ("Declarative Self-improving Python") replaces hand-written prompts with code. You describe what each step should do as a typed signature, compose steps into modules (from a single prediction to a ReAct agent), and then run an optimizer that automatically improves the prompts, few-shot examples or even model weights against a metric you define. It started at Stanford NLP, led by Omar Khattab (now an MIT professor), and grew into a broad research and open-source community. DSPy 3.0 (August 2025) added optimizers such as GEPA and reinforcement-learning training.

How it works

A signature like "question -> answer" declares inputs and outputs; a module such as Predict, ChainOfThought or ReAct decides how to run it; an adapter turns that into the actual prompt for the configured LM. You chain modules in normal Python to build a pipeline or agent. Then you give an optimizer a handful of examples and a metric, and it searches for better instructions and demonstrations (or fine-tunes weights), producing a compiled program that scores higher on your metric.

Key concepts

Signature
A declarative, typed spec of a task's inputs and outputs that replaces a hand-written prompt.
Module
A strategy for running a signature, e.g. Predict (direct), ChainOfThought (reasoning) or ReAct (tools in a loop).
Optimizer
An algorithm (e.g. MIPROv2, GEPA, BootstrapFewShot) that tunes prompts, examples or weights against a metric.
Metric
A scoring function you write that tells DSPy what a good output is.
Adapter
The component that turns signatures into actual prompts and parses the model's reply (e.g. ChatAdapter, JSONAdapter).

Use it when

  • You have a measurable task (classification, extraction, RAG, LLM-as-judge) and want quality to improve systematically, not by prompt tweaking.
  • You need to move a pipeline to a cheaper or different model and re-optimize instead of rewriting prompts.
  • You want modular LM programs whose parts can be tested and optimized independently.

Look elsewhere when

  • You have no examples or metric to optimize against; much of DSPy's value comes from the optimizers.
  • You need a full agent runtime with durable state, deployment and UI; pair DSPy with another framework for that.

Who uses it

  • Shopify

    Extracts structured metadata across shops using DSPy with the GEPA optimizer.

    Evidence: youtube.com

  • Dropbox

    Optimized the relevance judge behind Dropbox Dash with DSPy.

    Evidence: dropbox.tech

  • JetBlue

    Uses DSPy for multiple chatbot use cases on Databricks.

    Evidence: databricks.com

  • Nubank

    Optimizes modular, versioned prompts for financial-service agents with DSPy and GEPA.

    Evidence: building.nubank.com

Milestones

  1. DSPy 3.0 released with GEPA and SIMBA optimizers, dspy.GRPO RL training, and MLflow 3.0 integration (github.com)
  2. GEPA paper: reflective prompt evolution can outperform reinforcement learning (arxiv.org)
  3. DSPy paper: compiling declarative language model calls into self-improving pipelines (arxiv.org)

Start learning