stanfordnlp/dspy

DSPy: The framework for programming—not prompting—language models

What it solves

DSPy prevents the need for manual, brittle prompt engineering. Instead of manually tweaking prompts to get a specific output, developers can programmatically define the logic of their AI system and let the framework optimize the prompts and weights automatically.

How it works

DSPy (Declarative Self-improving Python) treats language model calls as programming modules. It allows users to write compositional Python code to build modular AI systems—such as RAG pipelines or agent loops—and then uses algorithms to "teach" the model to deliver high-quality outputs by optimizing the instructions and demonstrations provided to the LM.

Who it’s for

Developers building complex AI systems, including simple classifiers, RAG pipelines, and AI agents, who want a more stable and modular approach to building with foundation models.

Highlights

  • own modular AI systems using compositional Python code.
  • Automatic optimization of prompts and weights.
  • Supports a wide range of applications from simple classifiers to sophisticated RAG and agent loops.
  • Based on research into compiling declarative LM calls into self-improving pipelines.

Related

  • Project
  • Project
  • Project
  • Project
  • Project