liveBook · Manning

Mutation operator

As explained in Building LLM Applications with DSPy

Mutation is an optimization operation that modifies a candidate solution to produce another candidate.

A mutation operator modifies a candidate solution to create a new candidate. In prompt optimization, it changes a prompt’s wording, instructions, or demonstrations; the modified prompt is then evaluated. section 6.5.1

Mutation works alongside crossover, which combines prompts. A search may select prompts from a pool for either operation. In GEPA, candidates on the Pareto front can be selected for mutation, with stronger candidates favored but others sometimes chosen to preserve exploration. section 6.5.1 section 6.5.2

Mutating a prompt

GEPA creates Prompt 3 by mutating Prompt 2. It first evaluates the new prompt on a minibatch, then evaluates it on the full validation set if it performs well. Because Prompt 3 scores highest on at least one example, it joins the Pareto front. section 6.5.2

Table 6.4 Maintaining the Pareto front after three steps
Prompt
Parent
Ex 1
Ex 2
Ex 3
Ex 4
Ex 5
In Pareto
1
–
0.5
0.6
0.7
0.4
0.1
False
2
1
0.6
0.7
0.8
0.5
0.0
True
3
2
0.4
0.3
0.2
0.3
0.2
True

Compare the example scores for Prompts 1, 2, and 3 and see which candidates remain on the Pareto front after mutation. section 6.5.2

How Building LLM Applications with DSPy covers it

How deep it goes
Defines prompt mutation and describes candidate selection and evaluation, without detailing how prompt changes are generated.
Examples
Shows prompts mutated by changing wording, instructions, or demonstrations, including Prompt 3 mutated from Prompt 2.
What you can do after
Understand how modified prompt candidates are evaluated and selected during optimization.
How it connects
Connects mutation to genetic algorithms, crossover, Pareto fronts, and prompt optimization.

Also explained in

Compare how 2 books explain mutation operator →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building LLM Applications with DSPy. The section links point to the parts of the book it draws on.