EXPLAINER

DSPy

frameworkfreshness: volatilesources not yet verified

DSPy is a framework for programming — rather than hand-prompting — language-model pipelines: you declare modules and metrics, and optimisers tune prompts or weights automatically.

Short answer: In DSPy you write signatures and modules and a metric, then an optimiser searches prompts/few-shot examples (or fine-tunes) to maximise it. It rewards having an evaluation set and reduces manual prompt fiddling.

What is it?

Instead of endlessly rewording prompts by hand, DSPy lets you describe what each step should do and how to score success, then automatically finds better prompts or examples. It works best when you have test cases.

Also known as: DSPy framework, declarative self-improving python, prompt optimization framework, dspy optimizer, dspy signatures, MIPRO, automatic prompt optimization.

Technical definition

Khattab et al. (2023) introduce DSPy: LM calls are expressed as declarative modules with typed signatures; teleprompters/optimisers (e.g., bootstrapping few-shot demonstrations, instruction proposal, search) compile programs against a metric and training/validation examples. Optimisation cost, reproducibility across model versions and the available optimisers change between releases.

Entity type: framework · Freshness class: volatile.

When should I use it?

Good when you have an evaluation set and want systematic prompt/pipeline improvement.

Implementation patterns

  • Define a metric, collect 20–200 examples, compile, evaluate on held-out data.
  • Re-compile when changing models.
  • Keep optimised prompts under version control.

Technologies and frameworks

Commonly associated: DSPy (Python), optimisers (teleprompters), evaluation metrics. Names are examples of what exists, not recommendations, and projects change quickly.

Practical guide

  1. Write the task as a signature.
  2. Build a small labelled set and metric.
  3. Run baseline, then an optimiser.
  4. Validate on held-out data.
  5. Version the compiled program.

Common failure modes

  • No reliable metric → optimiser overfits to a bad objective.
  • Overfitting to a tiny training set.
  • Optimisation cost surprises.
  • Prompts that do not transfer when the model changes.

Troubleshooting

  • Optimised program worse on new data — Use a held-out set; increase data diversity; simplify the program.

Contrasted with

  • LangChain, Practically — LangChain provides components and integrations; DSPy provides a program-and-optimise methodology.

Questions this page answers

  • What is DSPy?
  • How does automatic prompt optimization work?
  • DSPy vs LangChain?
  • Do I need a dataset for DSPy?

Typical goals: automate prompt optimisation; build modular LM pipelines with metrics.

Sources and verification

Status: not independently verified. This entry was authored on 2026-10-06 from general technical knowledge, without live checking of the sources below. Treat every source as a lead to confirm (identifier, title, authorship, current version) before publication or citation.

Freshness class: volatile — Products, versions, protocols, benchmarks, leaderboards, regulations and dates. Verify against the primary source before relying on specifics; re-review every 3 months.

Time-sensitive claims to verify before relying on them:

  • Current API, optimisers and versions.

Canonical sources (unverified leads):

  • Khattab et al., DSPy: Compiling Declarative Language Model Calls into Self-Improving Pipelines (2023) — arXiv:2310.03714
  • DSPy documentation — dspy.ai (verify)