We use analytics and advertising tools by default. You can update this anytime.
How to stop handwriting prompts, start measuring them, and let AI rewrite them for you
Before you start: This is a technical guide for developers, with Python code you can copy and run. If you don’t code, you can still follow the explanations or ask a coding agent like Claude or Codex to run the steps for you.
At the first AI Engineer Summit in San Francisco in the fall of 2023, someone walked up to me and confidently said, “Didn’t you know prompt engineering is dead already?”
I was a prompt engineer at the time, so this wasn’t what I wanted to hear. “What do you mean?” I asked.
“Try DSPy,” the man said.
That night I went home and tried the thing that was supposedly going to put me out of business. I still had to understand the task, find good examples, and check the output, which were parts of prompt engineering that mattered. But I no longer had to handwrite brittle prompt strings and watch them break when a new model came along.
When we moved from GPT-3.5 to GPT-4, many of my carefully written rules stopped working. That happens every time a new frontier model comes out or when you move a workflow to another provider or an open-source model. DSPy, an open-source framework that writes your prompts for you, keeps the task separate from the prompt. Switching models can mean changing one line of code and letting DSPy generate new prompts. The judgment about what the task should be is still mine.
Watch the livestream: I recently discussed this with Drew Breunig, cofounder of Cmpnd, and Isaac Miller, the lead maintainer of DSPy. This guide draws on that conversation, but you don’t need to watch it first.
DSPy (Declarative Self-improving Python) is an open-source Python framework, originally created at Stanford by the researcher Omar Khattab, now at MIT, for programming language models rather than prompting them. You define a task using typed inputs and outputs and provide examples and a way to score results. An optimizer improves the instructions based on what works.
I’ve used DSPy on projects ranging from creating AI personas for a large credit card company to running evaluations as head of evals at Every. I also wrote the book Context Engineering with DSPy because I found the original documentation difficult to approach. The documentation is much better now, but the mental model can still take a little time to click.
If you’ve been told to learn DSPy and don’t know where to start, this guide is for you. I’ll explain what it is, when it’s useful, and its six main building blocks. Then we’ll work through an example: training an AI agent judge to identify AI-generated text and using that judge to train a program that rewrites AI text to sound more human.
Upgrade your membership to continue reading the full guide.
Subscribe to continue