Papers › DSPy: Compiling Declarative Language Model Calls into Self-Improving Pipelines

DSPy: Compiling Declarative Language Model Calls into Self-Improving Pipelines

5 Oct 2023arXiv:2310.03714archive 2025-07-28

Omar Khattab, Arnav Singhvi, Paridhi Maheshwari, Zhiyuan Zhang, Keshav Santhanam, Sri Vardhamanan, Saiful Haq, Ashutosh Sharma, Thomas T. Joshi, Hanna Moazam, Heather Miller, Matei Zaharia, Christopher Potts

The ML community is rapidly exploring techniques for prompting language models (LMs) and for stacking them into pipelines that solve complex tasks. Unfortunately, existing LM pipelines are typically implemented using hard-coded "prompt templates", i.e. lengthy strings discovered via trial and error. Toward a more systematic approach for developing and optimizing LM pipelines, we introduce DSPy, a programming model that abstracts LM pipelines as text transformation graphs, i.e. imperative computational graphs where LMs are invoked through declarative modules. DSPy modules are parameterized, meaning they can learn (by creating and collecting demonstrations) how to apply compositions of prompting, finetuning, augmentation, and reasoning techniques. We design a compiler that will optimize any DSPy pipeline to maximize a given metric. We conduct two case studies, showing that succinct DSPy programs can express and optimize sophisticated LM pipelines that reason about math word problems, tackle multi-hop retrieval, answer complex questions, and control agent loops. Within minutes of compiling, a few lines of DSPy allow GPT-3.5 and llama2-13b-chat to self-bootstrap pipelines that outperform standard few-shot prompting (generally by over 25% and 65%, respectively) and pipelines with expert-created demonstrations (by up to 5-46% and 16-40%, respectively). On top of that, DSPy programs compiled to open and relatively small LMs like 770M-parameter T5 and llama2-13b-chat are competitive with approaches that rely on expert-written prompt chains for proprietary GPT-3.5. DSPy is available at https://github.com/stanfordnlp/dspy

PaperPDFCodeCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2310.03714")

Code

Syntology Ran 3 of 7 code samples harvested from 1 repository linked to this paper; 4 have no recorded run. Of those that ran: 3 ran with no contract checked.

By repository: community (archive-listed): 7 samples from 1 repository, 3 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

stanfordnlp/dspy officialmentioned in papermentioned on GitHubpytorchMIT report
stanfordnlp/dsp mentioned on GitHubpytorchMIT report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

7 samples harvested; 3 ran; 0 honoured the contract we drafted; 4 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

3ran
4unverified

Licence: 0 of the 7 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from stanfordnlp/dsp. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

deduplicate stanfordnlp/dsp/dspy/dsp/utils/utils.py community (archive-listed) ran fingerprinted MIT (permissive) · 8823c5b244127289 · report
flatten stanfordnlp/dsp/dspy/dsp/utils/utils.py community (archive-listed) ran MIT (permissive) · f3fc668675b416fa · report
timestamp stanfordnlp/dsp/dspy/dsp/utils/utils.py community (archive-listed) ran MIT (permissive) · a1443403bbc0e0a0 · report
DPR_tokenize stanfordnlp/dsp/dspy/dsp/utils/dpr.py community (archive-listed) unverified MIT (permissive) · 47676c1faa234786 · report
find_data_errors_completion stanfordnlp/dsp/dspy/clients/utils_finetune.py community (archive-listed) unverified MIT (permissive) · f7dd796d65e2945a · report
has_answer stanfordnlp/dsp/dspy/dsp/utils/dpr.py community (archive-listed) unverified MIT (permissive) · 750c77c03f65dc36 · report
locate_answers stanfordnlp/dsp/dspy/dsp/utils/dpr.py community (archive-listed) unverified MIT (permissive) · 007531ee995976cc · report

Tasks

Language ModelingLanguage ModellingMathQuestion Answering

Results from the paper archive 2025-07-28

TaskDatasetModelMetricValueRank at snapshotLeaderboardReport
Question Answering FEVER DSP EM 62.2 #4 of 8 Archive leaderboard report
Question Answering WebQuestions DSP EM 59.4 #3 of 37 Archive leaderboard report

Ranks are positions in the archive's leaderboards as they stood at the 2025-07-28 snapshot. Results published since then are not among these rows, so a rank here is not a current standing.

Methods

AdafactorAdamAttentionAttention DropoutBPECosine AnnealingDense ConnectionsDropoutGPT-3Gated Linear UnitInverse Square Root ScheduleLayer NormalizationLinear LayerLinear Warmup With Cosine AnnealingMulti-Head AttentionResidual ConnectionSentencePieceSoftmaxT5Weight Decay

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections