FDE Times dataFDE jobs open 932▼14 Change in open roles over 7 days, like-for-like: roles from companies we started tracking this week are left outNew in 7 days 62Companies hiring 202Remote-friendly 24%Median US pay $201kTop hirer Databricks 92
中文VI

The newspaper of the Forward Deployed Engineer

Tools

DSPy turns a client's eval set into a machine that finds prompts

An algorithm once beat the best-known human-written reasoning prompt; DSPy applies that search to whole pipelines, so switching models no longer means retuning by hand.

ShareLinkedInFacebookX

In brief

  • The APE paper showed that instructions generated by an LLM matched or beat those written by human annotators on 19 of 24 NLP tasks.
  • DSPy treats prompts as parameters: its compiler optimizes an entire pipeline to maximize the metric you supply.
  • An optimizer is only as good as its metric and eval set, so the most valuable work for an FDE is defining what "correct" means with the client.
Diagram of the DSPy loop in the article's hypothetical example: 300 labelled emails are split into 200 tuning emails and 100 holdout emails the optimizer never sees. The 200 emails go into the Optimizer. The Module (email to class) is compiled, the Optimizer tries instructions and few-shot examples, and the Metric (correct label = 1, wrong = 0) scores each candidate and returns the score. The FDE and the client must define what "correct" means themselves. The compiled prompt is scored on the 100 holdout emails: the hand-written prompt scores 78, the compiled one 86/100, or about 400 fewer misrouted emails a month at 5,000 emails a month.
With DSPy, the FDE's job is to define what "correct" means. The optimizer finds the wording, and the holdout set gives the final score. Figures are a hypothetical example from the article.

The most famous chain-of-thought prompt, a human-written instruction telling a model to think step by step, was once beaten by an algorithm that uses a language model. The Automatic Prompt Engineer (APE) method found a longer variant that asks the model to work through the problem step by step “to be sure we have the right answer”.

According to DAIR.AI’s Prompt Engineering Guide, that phrasing improved results on two sets of math problems, MultiArith and GSM8K.

What matters is how the sentence came about. Nobody sat down and thought of it. An algorithm searched for it and selected it, much the way engineers tune hyperparameters.

An FDE runs into this problem almost every week. On a client site, you can spend a whole week tuning prompts for a classification or extraction pipeline. Then the client switches models and everything has to be redone. DSPy turns that hand-tuning into an optimization problem, with the client’s eval set as the objective function.

Prompts as parameters

The idea of finding prompts algorithmically was set out clearly in “Large Language Models Are Human-Level Prompt Engineers” by Zhou and colleagues, posted to arXiv on November 3, 2022. APE’s mechanism is fairly simple: an LLM proposes a batch of candidate instructions, and the system searches that batch for the one that scores highest.

Across 24 NLP tasks, instructions generated by APE matched or beat those written by human annotators on 19.

DSPy applies the same logic at the level of the pipeline. The paper by Khattab, Zaharia, Potts and colleagues, posted on October 5, 2023, describes a compiler that can optimize any DSPy pipeline to maximize a given metric.

DSPy modules are parameterized, meaning they can learn, for example by learning prompts or sets of few-shot examples.

Stanford NLP’s official README describes DSPy as a framework for programming language models rather than prompting them. The full name is Declarative Self-improving Python, and according to the README, the framework includes algorithms for optimizing both prompts and model weights.

When is DSPy worth using?

DSPy fits best when three conditions hold: the task has a measurable answer, the client has labeled data or is willing to label it, and the pipeline will keep changing in model or requirements. Without the first condition, for instance when a client just wants answers that “sound better” and nobody can define what better means, the optimizer has nothing to hold on to.

Take a hypothetical bank that wants to sort complaint emails automatically into 6 categories so each reaches the right department. The operations team labels 300 emails. You split off 200 as optimization data and keep 100 aside as a holdout set that the optimizer never sees. The metric is just a function: a predicted label that matches the human label scores 1, a wrong one scores 0.

The sketch below shows those three pieces in code: a module that declares inputs and outputs, a metric function, and a compile call. It is an illustrative sketch; check the optimizer class names and specific parameters against the documentation for the DSPy version you are using.

import dspy

# Module: declare the task, don't write a prompt
classify = dspy.Predict("email -> complaint_category")

# Metric: 1 if it matches the human label, 0 otherwise
def label_match(example, prediction, trace=None):
    return prediction.complaint_category == example.complaint_category

# Compile: the optimizer tries instructions and few-shot examples from 200 emails
optimizer = dspy.BootstrapFewShot(metric=label_match)
optimized = optimizer.compile(classify, trainset=optimization_emails)

# Report scores only on the 100 holdout emails

Suppose the hand-written prompt scores 78/100 on the holdout set. You run the compiler and let it try options, scoring each with the metric. If the best option reaches 86/100 on the holdout, the gap is 8 emails in every 100.

At 5,000 emails a month, the bank sends roughly 400 fewer emails to the wrong place each month, a figure an operations director grasps immediately.

Task Who does it
Define what “correct” means FDE with the client
Label data and split off the holdout Client, checked by the FDE
Generate and test prompt options Optimizer
Read the remaining errors on the holdout FDE

The last row is where the value lies. The 14 emails still misclassified usually point to an ambiguous category or inconsistent labeling, and that becomes the agenda for the next meeting with the client.

The optimizer is loyal only to the metric

DSPy optimizes exactly what you measure, nothing more. If the metric checks only the output format and ignores the content, you will get back a prompt that is very good at returning the right format. If the eval set is too small or skewed, the prompt will overfit to those few dozen examples.

That is why the holdout score is the number to report, rather than the score on the optimization data.

Cost needs to be counted too. Every option tried means another batch of model calls, so start with a small dataset and a cheap model before running at scale.

Even so, compared with the alternatives, prompt optimization remains the economical choice. The authors of GEPA, a reflective prompt-evolution method published in 2025 by Agrawal, Khattab and colleagues, point out that reinforcement learning methods such as GRPO often need thousands of rollouts to learn a new task.

Across six tasks, GEPA beat GRPO by 6% on average, and by up to 20% on some tasks, while using up to 35 times fewer rollouts. The lesson for FDEs: exhaust prompt optimization before proposing fine-tuning to a client.

What to learn first to be useful right away

Start with the skill of writing metrics and building eval sets, because that is the part DSPy cannot do for you. Leave the API for later. Then read the APE abstract to understand the propose-and-score loop, and read the DSPy paper to see how modules, metrics and the compiler fit together.

When reading FDE or AI engineer job descriptions, look for phrases such as “eval”, “prompt optimization” or DSPy by name. On a CV, skip “proficient in prompt engineering”. Write one sentence with numbers instead: how many examples your eval set had, that you used automatic optimization, and how far holdout accuracy rose.

A hand-written prompt goes stale the moment the client changes models. A well-defined eval set stays useful, and next time you only need to rerun the compiler.

Was this article useful?

Use with your AI assistantAsk Claude ↗Ask ChatGPT ↗
5 sources
Read next on the roadmap · Stage 3: Applied AIWhat AutoGen's maintenance mode teaches FDEs about picking frameworksMicrosoft now steers new users to its Agent Framework, so ask first who will maintain a tool after you leave, then whether security will approve it.