stanfordnlp/dspy

DSPy

LLM programming framework with declarative prompt optimization

★ 15k 1.2k forks Python MIT
llmprompt-optimizationprogrammingstanford
4.0Overall
Functionality
4.0
Documentation
3.5
Activity
4.5
Ease of use
3.0

Highlights

  • Declarative prompt optimization
  • Multiple automatic optimizers
  • Built-in evaluation and debugging

Use cases

  • Quantifiable prompt tuning
  • Research auto-optimization
  • Prompt-stability-sensitive pipelines

Review

DSPy, from Stanford NLP, reframes LLM prompt engineering as programming plus automatic optimization: you declare input/output Signatures and module composition, and an optimizer (Teleprompter) searches for better prompts and few-shot examples on data. It represents the paradigm shift of prompt engineering from hand-writing to automation.

Core capabilities include the Signature/Module/Predictor abstraction, built-in modules (dspy.ChainOfThought, dspy.ReAct, etc.), multiple automatic optimizers (BootstrapFewShot, MIPRO, COPRO), a backend abstraction decoupling LM and Retriever, and dspy.Evaluate evaluation and dspy.inspect debugging tools. Recent versions add conversational and multi-agent modes.

The highlight is that prompts are no longer hand-written, a big shift for heavy prompt engineers, and optimizers do reliably improve metrics on small-to-medium tasks. The downside is a steep learning curve, a mental model quite different from conventional LangChain-style development, heavy dependence on data volume and evaluation metrics, and an unfavorable cost-benefit ratio for small projects.

Use cases: prompt engineering tasks with quantifiable evaluation, automatic prompt tuning in research experiments, production pipelines sensitive to prompt stability. Not worth introducing for one-off scripts.