DSPy

DSPy — “Declarative Self-improving Python” — is a framework from Stanford NLP for programming rather than prompting language models. MIT licensed.

🔗 https://dspy.ai/ · https://github.com/stanfordnlp/dspy

Core Abstractions

AbstractionRole
SignaturesDeclare a task’s input/output specification
ModulesCompose those signatures into systems
OptimizersAlgorithms that refine the prompts and weights behind them

The pitch is that you specify what the model should do and let optimizers discover the prompt that achieves it, rather than hand-tuning strings. Applications range from simple classifiers to RAG pipelines and agent loops.

Why It Matters Here

DSPy is the direct structural answer to Prompt Sensitivity — if retrieval and ranking quality shift with prompt phrasing, then the prompt is a parameter to be optimized rather than a constant to be authored. That reframing matters for any RAG pipeline whose generation stage is currently a hand-written template.

Omar Khattab is among the framework’s authors, connecting it to the ColBERT line of retrieval work also covered here.

  • LangChain — the prompt-chaining approach DSPy positions against
  • RAGAS — evaluation, which DSPy optimizers need a metric from