AI GLOSSARY · PROMPTS AND INSTRUCTIONS

DSPy

Markdown version · Wikidata Q133755245

Definition

DSPy is a Python framework for building language-model programs. You declare each task's inputs and outputs, and optimizers tune the prompts against a metric you define, instead of you writing the prompts by hand.

Also called: dspy framework, dspy stanford, dspy python, DSPy library.

In plain language

Most people steer a language model by writing and rewriting a prompt until it works, and the prompt often breaks when the model changes. DSPy is a Python toolkit that asks you to describe the job instead: what goes in, what should come out, and how to score a good answer. It then tries prompt variations and keeps the better ones. You still need example data and a score that reflects what you care about, and tuning costs model calls. A poor score function gives you a program that is tuned to the wrong thing.

Technical definition

DSPy's documentation describes three ideas. Signatures declare typed inputs and outputs for a task. Modules set the strategy for running a signature, for example direct completion, step-by-step reasoning or a tool-using loop, behind the same interface. Optimizers take examples and a metric and tune the program against it. The paper by Khattab et al. (arXiv, submitted 5 October 2023) presents DSPy as a programming model that treats language-model pipelines as text-transformation graphs and uses a compiler to optimise a pipeline for a given metric.

Worked examples in this catalogue

Catalogue examples point at a skill, guide or coding tool listed on this site, with what to run and what you see. An example marked illustrative describes the item from its own documentation; it was not executed for this page. Platform Scores are our assessment under a published method, not a safety guarantee.

  1. Skill by Skill Almanac · Illustrative, not executed

    prompt-writing 57/100 · Provisional, not yet measuredScored · Method v0.2 · How we score

    What you see
    The skill writes and lints LLM prompts with a fixed structure, injection rules and a numeric test plan.
    Why it exercises the concept
    This is the hand-written route that DSPy tries to replace with declared tasks and an optimizer. Having both in view shows what moves from prompt text into code and metrics.
  2. Skill by Skill Almanac · Illustrative, not executed

    llm-eval-test-sets 57/100 · Provisional, not yet measuredScored · Method v0.2 · How we score

    What you see
    The skill builds and validates an eval dataset for any LLM feature, with a checker for duplicates, missing graders, imbalance and leakage.
    Why it exercises the concept
    DSPy optimizers need examples and a scoring function. A clean eval set is the kind of input they rely on, and leakage between tuning and test data would distort the result.
  3. Guide · Illustrative, not executed

    Prompt Engineering for Agents vs Chat Models

    What you see
    The guide covers prompt engineering for coding agents and agent runs.
    Why it exercises the concept
    It shows the manual practice that a programmatic approach such as DSPy aims to automate, so you can judge when hand-tuning is enough.

How it shows up when you use agents

DSPy is a library, not a coding agent. You meet it when someone wants a language-model pipeline, such as question answering over documents, to improve by measurement instead of by editing prompt text. In a coding-agent session it shows up as a Python dependency you or the agent installs with pip install -U dspy, per dspy.ai.

  • The metric is the specification. The optimizer pushes the program toward whatever the score function rewards. If the metric is weak, the tuned prompts follow it. Write the metric first and test it on a few cases by hand.
  • Data comes first. Optimizers need examples. A small, clean, held-out test set is the safer habit, and examples used for tuning should not appear in the test set.
  • Tuning is not free. IBM describes the method as the model proposing prompt variations that are tested against your metric, which implies several model calls per run. Check your provider's pricing and rate limits before a large run.
  • Prompts still exist. DSPy generates them; you can read them. Inspect what it produced before you ship it.

Next action: try it on one narrow task with a small set of labelled examples and compare the result with your hand-written prompt on the same held-out set. See Prompt engineering.

Common confusions

  • DSPy versus prompt engineering. DSPy automates part of the work by searching over prompts against a metric. It does not remove the need to define the task and the score.
  • DSPy versus LangChain. Both are used to build language-model applications, and DSPy's main idea is optimizing programs against a metric. See LangChain for its own scope.
  • Optimizing versus fine-tuning. The paper says DSPy modules can learn to apply prompting, finetuning, augmentation and reasoning techniques, so some options change model weights and others change only prompts. Read the optimizer's documentation to see which one you are using. See Fine-tuning.
  • A signature versus a prompt. A signature declares inputs and outputs; the prompt text is produced from it.

More in Prompts and instructions

Next steps

  1. Prompt Engineering for Agents vs Chat Models The long-form guide.
  2. prompt-writing A skill that exercises it.
  3. Prompt engineering Related term.
  4. Few-shot prompting Related term.
  5. All glossary terms A to Z and by family.

Sources

Definitions are written by Skill Almanac from these sources and were checked against them on 2026-11-24. Wikipedia is never the only source.

Review record

Last verified

Drafted by claude-sonnet-5-5; sources and example targets checked by claude-haiku-5-5 source check; claude-sonnet-5-5 editor pass on 2026-11-24. Last verified .

This entry is still in review, so it is not listed in search engines yet.

Change log (2)
  • : First version.
  • : Verifier pass: applied verifier corrections to wording and attributions.