DSPy is an open-source framework from Stanford NLP for programming rather than prompting language models: you declare typed signatures describing what goes in and what comes out, compose them into modules, and optimizers compile those programs into effective prompts and weights against your own metric and examples.
How does DSPy replace hand-written prompts?
You never write the final prompt text. A module such as chain-of-thought or a retrieval step is declared from structured signatures, then an optimizer takes a small training set plus your scoring function and searches over instructions and few-shot demonstrations to maximize it. The prompt becomes a compiled artifact instead of source code you maintain by hand, which removes most of the trial-and-error loop of prompt engineering when swapping models or strategies.
When should a team choose DSPy?
When output quality hinges on wording and you already have evaluation data with a measurable definition of correct, because that data is exactly what the optimizer consumes. It suits classification, extraction, and retrieval pipelines where quality can be scored automatically, and its metrics slot naturally into broader agent evals. Teams without labeled examples or a clear metric get little from compilation; for them a straightforward agent framework is the better starting point. DSPy pays off exactly when you can define correctness as code.
Frequently asked questions
What is a DSPy signature?
A signature is a declarative specification of a task, naming the input and output fields without spelling out the prompt itself. The framework renders the actual instructions, so changing models or reasoning strategies does not mean editing strings.
Does DSPy replace prompt engineering entirely?
It automates much of the manual iteration. You still have to define what good output means as a metric and supply representative examples; the optimizers then search over instructions and demonstrations to maximize that metric.
No advertising or tracking cookies, and our visitor counts are anonymous. The Cal.com booking widget loads only if you allow it. Privacy Policy.
The page itself, anything our host sets to serve and secure it, and the anonymous visitor count. Always on, and none of it stores anything on your device.
The Cal.com booking widget. Left off, a booking link opens the booking page instead of a popup, so you can still book a call.