Notes

Automatic Prompt Optimization

Hand-tuning a prompt is a loop: change a word, run the examples, see whether the score moved. Automatic prompt optimization closes that loop with code — a search over candidate prompts, scored on data, with a model proposing each next candidate.

What the loop needs
  • A metric — exact match, a rubric scored by another model, anything that returns a number.
  • A small labelled development set, typically tens to a few hundred examples.
  • A proposal step: a model reads the current prompt and its failures, and writes a replacement.
How the search is steered

There are no numeric gradients to follow, because the thing being optimised is text. So the methods substitute something else. APE generates many candidate instructions and keeps the highest-scoring. Others feed the failing cases back as a written critique — a "textual gradient" — and edit in that direction, carrying a beam of candidates forward. Frameworks such as DSPy go further: given a program and a metric, they optimise the instruction and the few-shot examples chosen to accompany it, and the examples are often where most of the gain sits.

Why bother

Because prompts do not transfer. Wording tuned against one model drifts when the provider ships a new version, and redoing it by hand costs a day each time. The failure mode to guard against is overfitting: a prompt that wins on fifty development examples and is no better in production. Hold out a test set, and rerun the optimiser after a model upgrade rather than trusting last quarter's prompt.

Automatic prompt optimization replaces hand-tuning with a search: a model proposes candidate prompts, each is scored against a small labelled set using a chosen metric, and the best survives to be edited again. Methods range from generating and selecting instructions to using written critiques of failures as pseudo-gradients, and frameworks such as DSPy optimise the few-shot examples too. It matters because prompts do not survive model upgrades, and retuning by hand does not scale.

Getting the best out of an AI assistant often comes down to how you word the request, and finding the right wording is fiddly, repetitive guesswork. Automatic prompt optimization hands that chore to the machine. You supply a few dozen examples with the answers you actually want, plus a way of marking the results. The system then writes its own instructions, tests them, reads where they failed, and rewrites. After a few rounds it keeps whichever wording scored best. It is the difference between tweaking a recipe by taste and running a proper taste test — and it has to be redone whenever the underlying model changes.