Concepts / Iterating on Prompts

Iterating on Prompts

Automated prompt engineering tools search for prompts that maximize evaluation metrics on evaluation data you specify, much as automated ML tools search for hyperparameters.

  • Programming

The Tempting Promise of Automation

Imagine you have a language model task and you need a prompt that works well. One option is to spend an afternoon rewording the instructions by hand, testing each version, and keeping the best one. Many people who hear about prompt engineering tools assume the next step is simple: hand the task to a tool, let it run, and receive a finished prompt that is guaranteed to be the best one available. This article examines that belief and shows why it is incomplete.

The starting point is a fact about the search problem itself. For any task, the number of possible prompts is effectively unlimited, and manual prompt engineering is slow. Automation exists to speed up that search. Automation does not, however, turn an unreliable process into a reliable one. The rest of this article explains the difference.

What do you think happens?

A tool reports that one prompt achieved the highest score on its metrics. Is that enough to conclude the prompt is correct in general?

Reveal answer
Answer:

No. The score shows performance on the metrics and evaluation data you chose. It answers a narrower question than whether the prompt is correct in general.

A prompt optimization tool can find a prompt that maximizes the evaluation metrics you care about on your evaluation data. The measurement is only as good as the setup you gave the tool, so the score must be read in that light.

A First Reply as Evidence

Suppose you type a request into a model and receive a reply that technically responds but does not do what you wanted. This is an ordinary moment in prompt work, not a sign that you have failed. Writing a prompt is closer to a conversation with an unfamiliar collaborator than to filling in a form correctly on the first attempt. You read what came back, notice where it fell short, and adjust your wording so the next reply moves closer to your goal.

In the real world

Consider a concrete case from the source material. You ask a model to pick the best video game. A reasonable-sounding reply comes back saying that opinions differ and that no game can be called the absolute best. That answer is defensible, but it may not be useful if you needed a single pick. The mismatch between what you asked and what you received is the starting signal for refinement.

A model's response is best treated as evidence about how your prompt was interpreted. When the reply is off target, the useful question is not only whether the model is wrong but what your wording led it to assume. In the video game case, the model treated a request for a winner as a request for a judgment about contested opinions. A revised prompt that says a pick is wanted even if opinions differ tells the model to commit to an answer while acknowledging the disagreement. The revision is a targeted response to what the first reply revealed.

Before

First request: Pick the best video game.

The reply hedges, saying opinions differ and no single game is best.

After

Revised request: Pick a game and commit to it, even if opinions differ.

The reply commits to one pick while noting that others may disagree.

First requestPick the best video gameReplyOpinions differ, no singlebestRevised requestA pick is wanted even ifopinions differReplyCommits to one picksent to modelrevise wordingsent to model
How the video game request and its reply change from the first draft to the revised prompt. The request changes, and the reply changes with it.

Iteration is therefore a deliberate cycle. You write a prompt, run it, read the reply, judge it against your goal, and revise. Then the cycle repeats. Stopping is also a decision you make on purpose, when the response meets your goal. A single attempt is rarely the finished instruction, and treating the first version as a draft is what makes the evidence in each reply useful.

Search as Automated Tuning

Optimization tools take a task description and turn it into a search. You supply the input and output formats, the evaluation metrics, and the evaluation data. The tool then proposes candidate prompts, measures each one against your metrics on your data, and keeps the candidates that score best. Some tools search over a single prompt, and others search over a chain of prompts that are run in sequence.

A helpful comparison comes from automated machine learning. Automated ML tools search for the best hyperparameters of a classical model, such as a learning rate or a tree depth, by trying settings and scoring them. Prompt optimization tools do the same kind of search, except the thing being tuned is the text of a prompt rather than a numeric setting. The search ends with a prompt, and that prompt is only as trustworthy as the metrics and data behind its score.

Candidate promptsScore on metrics anddataKeep best candidatesStopping criteriamet?Best promptmeasurerankyesno, propose next round
Each round proposes candidate prompts, scores them on the evaluation data, keeps the best, and checks whether the stopping criteria are met.

Tracing One Round of the Search

Worked example

One round of prompt search for an essay grader

A team wants a prompt for an application that grades college essays on a scale from 1 to 5, and it sets up an optimization tool to search for one.

  1. 1
    Define the inputs

    The team supplies the input and output formats (an essay in, a grade from 1 to 5 out), the evaluation metrics, and a set of graded essays as evaluation data.

  2. 2
    Propose candidates

    The tool generates several candidate prompts. Some may be concise, some may be detailed, and each is a different wording of the same task.

  3. 3
    Score each candidate

    Each candidate grades the same evaluation essays, and its results are measured against the chosen metrics. The scores belong to this data and these metrics only.

  4. 4
    Keep and repeat

    The best-scoring candidates are kept, new candidates are proposed from them, and the loop runs again until the stopping criteria are met.

Result

The final prompt is the best scorer found under this setup. It is not proven to be the best prompt for essay grading in general, because the search only measured what the team asked it to measure.

Models as Prompt Authors

A second route to automation uses the language model itself as the author of prompts. The simplest version is to ask a model directly for a prompt. For example, you could ask it to help write a concise prompt for an application that grades college essays on a scale from 1 to 5. Models can also be asked to critique a prompt you already have, to improve it, or to generate in-context examples that you then include in the prompt.

These uses have the same underlying idea: the model reads a prompt as text and produces a changed version of that text. A model's critique is also a kind of evidence, but it is evidence you must still check. A suggested rewrite is a candidate, and it earns a place in your work only after it is tested on your data.

How Promptbreeder Breeds Prompts

Promptbreeder is an example of an AI-powered optimization tool built on an evolutionary strategy. Its approach is to selectively breed prompts, so that good prompts produce variations and the search gradually moves toward prompts that satisfy your criteria. The process begins with an initial prompt. An AI model then generates mutations of that prompt. The mutation step is guided by a set of mutator prompts, which shape how the model changes the text.

The tool takes the most promising mutation, generates mutations of it, and repeats. The loop stops when a prompt satisfies your criteria. Read this as a loop rather than a straight line. The tool does not generate one prompt and stop. It keeps returning to the mutation step, using the most promising candidate so far as the new parent, until the stopping condition is met.

Initial promptAI model mutatespromptGuided by mutator promptsMost promisingmutationCriteria satisfied?Final promptparentcandidatesyesno, use as new parent
An initial prompt is mutated by an AI model, the most promising mutation is selected, and the selected prompt either satisfies the criteria or becomes the parent for the next round of mutation.

Pitfalls of Prompt Engineering Tools

A tool that searches for prompts can fail you in three main ways. The sections below take them one at a time, because each one needs a different kind of attention.

Reducing Tool Risk in Practice

The pitfalls point toward a set of practices. The first is to follow the keep-it-simple principle: before using any tool, write your own prompts without one. This builds a clearer understanding of the underlying model and of what your requirements actually are, and that understanding lets you judge a tool's output when you do use one.

  1. 1
    Write your own prompts first, so you understand the model and your requirements.
  2. 2
    Inspect every prompt the tool produces to see whether it makes sense.
  3. 3
    Track how many API calls the tool generates during a run.
  4. 4
    Remember that developers can make mistakes, and verify the tool's output rather than accepting it as authoritative.
Best practice

Treat a tool as an assistant whose output you verify, not as an authority whose output you accept. The two checks, inspecting the prompts and counting the API calls, are what make that verification possible.

Refining Prompts Through Revision Cycles

Refinement goes faster when you understand the model you are working with. Each cycle has five parts: you write a prompt, run it, read the reply, judge whether the reply meets your goal, and revise the prompt based on what the reply showed. The stopping point is a decision you make, not something that happens automatically after one attempt.

Learning a Model's Habits

Models differ from one another, and those differences show up in what they handle well and where they need more guidance. The source notes that models have distinct tendencies, such as differing strengths and preferences for where instructions appear in a prompt. Learning these tendencies is part of the work, because a prompt that succeeds on one model can underperform on another.

This knowledge feeds back into prompt design. When you notice that a model responds better to an instruction placed in a certain position, or that it hedges on a particular kind of request, that observation shapes the next revision. Each revision becomes more informed, so later prompts start closer to the goal than your first draft did.

Testing Changes Systematically

Once you start revising prompts, a second problem appears: it becomes hard to know which change caused which result. The source recommends making changes in a systematic way rather than editing freely and hoping for the best. It names three supporting practices.

  1. 1
    Version your prompts so that each wording remains retrievable.
  2. 2
    Use an experiment tracking tool to record runs and how they scored.
  3. 3
    Standardize the evaluation metrics and the evaluation data so that different prompts are scored on the same terms and can be compared fairly.

The practice comes down to one controlled comparison. You save a new version, run it and the previous version against the same evaluation data, and record the results so they can be compared against a baseline. The test data and metrics stay fixed while the prompt changes, so any difference in score can be attributed to the prompt.

Judging Changes Across the Whole System

A prompt is often one part of a larger system, and improvement in one place can hide damage somewhere else. A prompt might improve the model's performance on one subtask while making the whole system perform worse. A change that looks like a win when you examine one behavior should still be checked against the outcome the system as a whole needs to produce.

Practice: Diagnosing a Weak Reply

EASY

A model is asked, 'Name the best city to visit.' It replies that the answer depends entirely on personal taste and declines to name one. Using the revision cycle from this article, write one revised prompt. Then state what the first reply revealed about how your original wording was interpreted.

Hints
  • Ask what your wording led the model to assume, in the same way the video game reply revealed an assumption about contested opinions.
  • A revision can state that a single pick is wanted and that the model should commit to one even if preferences differ.

Key Takeaways

  • An automated prompt engineering tool searches for the prompt that maximizes your chosen evaluation metrics on your chosen evaluation data, much as automated ML tunes hyperparameters. A high score answers a narrower question than whether the prompt is correct in general.
  • AI models can write, critique, and improve prompts, and Promptbreeder applies this in an evolutionary loop of mutation, selection, and repetition until the stopping criteria are met.
  • Tools carry real risks, including hidden API calls that multiply cost, developer mistakes such as wrong templates and typos, and changes made without warning. Reduce these risks by writing prompts yourself first, inspecting the tool's output, and tracking API calls.
  • A first prompt is a draft. Each reply is evidence about how the prompt was interpreted, and deliberate revision based on that evidence is the core of iteration.
  • Iterate systematically by versioning prompts, tracking experiments, and standardizing metrics and data, and judge every change across the whole system rather than on a single subtask.

Related concepts

More concepts starting with I