Simon Willison applied the DSPy framework to the SQL system prompt powering Datasette Agent, turning what is normally a manual, intuition-driven process into a scored, automated optimization loop. The write-up lands the same week that DSPy featured in an AIE keynote, signaling the technique is moving from research curiosity to production workflow.
The pattern
DSPy treats prompts as learnable parameters rather than static strings. You define a metric, supply a set of examples, and let the optimizer rewrite and score prompt variants until it finds a version that measurably outperforms the baseline. For Willison's use case, the metric was straightforward: does the agent produce SQL that returns the correct result against a real Datasette instance?
This is the core shift DSPy enables. Instead of asking "does this prompt feel right," you ask "what is this prompt's score on my eval set" and let gradient-free optimization do the rest.
Why now
Three things converged to make this practical in 2026. First, DSPy's optimizer tooling matured enough that a single engineer can wire it up in an afternoon rather than a research sprint. Second, inference costs dropped far enough that running dozens of prompt variants against a real eval set is no longer prohibitive. Third, the broader Agents ecosystem has normalized the idea that agents need evals, not just vibes.
The AIE keynote mention is a leading indicator: when framework authors are demoing a tool at conferences, adoption typically accelerates over the following quarter.
How it works in practice
- Define your task signature. In DSPy terms, this is the input/output contract: natural-language question in, valid SQL out.
- Build a small labeled dataset. Willison used real queries against Datasette. Aim for 20 to 50 examples that cover your failure modes, not just the easy cases.
- Choose a metric. For SQL, execution correctness is the cleanest signal: run the generated query, compare results to a known-good answer set.
- Run a DSPy optimizer.
BootstrapFewShotorMIPROv2are the current go-to choices. The optimizer samples prompt rewrites, scores them against your metric, and keeps what works. - Inspect the winning prompt. DSPy outputs a human-readable prompt. Read it. You will often learn something about what the model actually needs versus what you assumed it needed.
- Re-run on a held-out test set before shipping. Optimization can overfit to your eval examples just like any other ML process.
For teams running high-volume inference, pairing this workflow with automatic prefix caching in vLLM means the repeated system-prompt prefix across hundreds of eval calls gets cached at the KV level, cutting compute costs for the optimization loop materially.
The trade-off
DSPy optimization is not free. You need a reliable eval harness before you start, and building one for SQL agents requires a live or reproducible database fixture. Teams without that infrastructure will spend more time on scaffolding than on actual prompt improvement.
There is also an interpretability cost. The optimizer can produce prompts that score well but read strangely. You own the output prompt, so you need to audit it for correctness, safety constraints, and alignment with your product's tone. Treat the optimizer's output as a strong draft, not a final artifact.
Finally, DSPy optimizers make many model calls. Without caching or a cheap evaluation model, a single optimization run can cost more than weeks of manual prompt tweaking. Budget accordingly, and consider running initial passes against a smaller, faster model before validating the winner on your production model.
Where it goes next
The Prompt Engineering discipline is bifurcating. One path stays manual and intuitive, relying on experienced engineers to craft prompts by feel. The other path treats prompts as code artifacts with test coverage and automated improvement. DSPy is the clearest current embodiment of the second path.
As local inference hardware catches up, the same workflow Willison ran against a hosted model becomes viable on-device. The LocalLLaMA community is already benchmarking DeepSeek V4 Flash on dual RTX PRO 6000 setups and finding it matches Sonnet-class quality at faster throughput for coding tasks. Running a full DSPy optimization loop locally, at Sonnet quality, with no API costs, is a near-term reality for well-resourced teams.
Separately, open-source tooling like Seismograph is emerging to detect silent drift in LLM API behavior over time. Once you have a DSPy-optimized prompt and a scored eval set, Seismograph-style monitoring lets you know the moment a model update degrades your hard-won performance gains. Optimization and monitoring are two halves of the same production discipline.
If you ship agents that touch structured data, the Willison write-up is worth reading end to end: it is one of the clearest worked examples of DSPy applied to a real production system prompt available right now.
The teams that build eval harnesses today will have a compounding advantage as optimizers improve: better evals make better optimization, which surfaces better prompts, which makes evals easier to pass.
READY TO ASCEND
Get AI news that respects your time
The signal, distilled. Curated AI news and prompt-engineering insight. No noise.