Skip to main content
table.optimize(labels, metric) tunes the instructions of a table’s own LM step against rows you’ve labeled, using the GEPA optimizer.
  • labels is a DataFrame or list of dicts with the table’s key column(s), such as trial (or trial and step for a step-level table), plus the right answer.
  • metric is an output column to match exactly (strings case-insensitively), or a function fn(row, label) returning a score, or (score, feedback) so GEPA knows what went wrong.
  • budget caps how many example runs GEPA makes (default 60). val_frac (default 0.3) is the share of labels held out to score before and after.
The result is the same step with the best instructions found. Only that step reruns for each candidate prompt; its input rows are read once. .optimize_report has train and held-out scores before and after, the candidates, and the LM calls and cost of running the step (reflection calls aren’t counted).

Example: classify steps

examples/optimize_step_kinds.py labels each step from its real tool calls (edit, test, explore or other), then tunes a classifier that only sees the step’s one-sentence summary:
GEPA learns the rule’s edge cases from its misses, such as that writing a test file counts as an edit.

Next steps

Choose a model

Pick the model the tuned step runs on.

Python SDK

Every optimize argument.