Framework · Orchestration Frameworks

DSPy

Replace hand-tuned prompts with a declarative Python programming model in which you specify input/output behaviour as Signatures, compose Modules (Predict, ChainOfThought, ReAct, ProgramOfThought), and let Optimizers (BootstrapFewShot, MIPROv2, BootstrapFinetune) tune prompts and weights against a metric.

Description

DSPy is the MIT-licensed framework for 'programming—rather than prompting—language models'. DSPy stands for Declarative Self-improving Python. It exposes three layers: Signatures declare what an LM should do (e.g. 'question -> answer'); Modules implement reasoning shapes around those signatures (dspy.Predict, dspy.ChainOfThought, dspy.ReAct, dspy.ProgramOfThought); Optimizers consume a metric and training data to 'tune the prompts and weights of your AI modules' — synthesising few-shot demos, proposing better natural-language instructions, or fine-tuning small LMs. Most often used for classifiers, RAG pipelines, and agent loops where empirically tuned prompts beat hand-crafted strings.

Solution

DSPy compiles to whatever loop the module declares. A dspy.ReAct agent runs the classic thought→action→observation cycle against a signature plus a tools list; dspy.ProgramOfThought emits and executes code; dspy.ChainOfThought adds a reasoning step before the signature output. At authoring time you only write the signature and pick the module. At compile time, an Optimizer (e.g. MIPROv2) iterates with a teacher LM, generates instructions and few-shot examples per step, and uses Bayesian Optimization to search the space of instructions/demonstrations.

Primary use cases

  • declarative programming of LM behaviour via Signatures
  • compiler-driven prompt + weight optimisation against a metric
  • ReAct-style agents whose prompts are co-tuned with the loop
  • RAG pipelines whose intermediate prompts get optimised

Open the full interactive page

Diagram, neighbourhood map, code examples, related patterns and full provenance.

Related