Searching the Prompt Space

A genetic algorithm over prompt templates, and an honest null result on held-out data.

Opening question

If a prompt is a configuration with four slots, can search find a better one than chance?

Context

Prompt engineering is usually done by hand. In a search-based software engineering course, Anastasia Strulistova and I framed it as configuration management instead: four slots, 20 options each, so 160,000 templates for a code-summarisation tool.

Technical execution

Fitness blended ROUGE-L with calibrated embedding similarity against Claude Opus reference summaries, with penalties for long prompts and broken output. We compared a genetic algorithm (tournament selection, crossover, mutation, elitism) with a random search on the same budget: 180 evaluations each, over 10 seeded trials.

Results

On the training subset the GA led, 0.676 to 0.664 (Cliff's δ = 0.46, p = 0.082). On a 50-function held-out set with no overlap, it didn't: 0.623 to 0.630 (δ = −0.32, p = 0.227). The report spends a section on why a population-mean advantage didn't carry over to the best individual.

Reflection

Two weaknesses are worth saying out loud. The reference summaries come from a model, so "quality" here means closeness to another model's taste. The function corpus itself was largely generated with an AI assistant. [SEAN: who did what between you and Anastasia?]

This was the first time I took a prompt apart into slots and searched over them. Six months later I proposed the same move one level up: searching over harness parts, such as one harness with another's compaction step, in the thesis's Stage 4 design.

Four slots × 20 options.
Best and mean fitness per generation, GA vs RS (from the report's data).
Train vs held-out, with CIs.