Post · 3 min read· pp. 157–159

Evaluator

gepa.gepa_launcher.Evaluator

Bases: Protocol

Methods:

__call__(candidate: str | Candidate, example: object | None = None, **kwargs: Any) -> tuple[float, SideInfo] | float

Score a candidate, returning a score and diagnostic side information (ASI).

This is the function you write. GEPA calls it repeatedly with mutated candidates and collects the returned scores and diagnostics to drive the optimization loop.

Parameters:

NameTypeDescriptionDefault
candidate`strCandidate`The text parameter(s) to evaluate. Type matches seed_candidate: plain str if you passed a string, or dict[str, str] if you passed a dict.
example`objectNone`One item from dataset. Not passed in single-task search mode (dataset=None).
opt_state(optional) Declare opt_state: OptimizationState in your signature to receive historical best evaluations for warm-starting. This is a reserved parameter name — GEPA injects it automatically.required

Returns:

TypeDescription
`tuple[float, SideInfo]float`
`tuple[float, SideInfo]float`
`tuple[float, SideInfo]float`
`tuple[float, SideInfo]float`
`tuple[float, SideInfo]float`

Evaluator signature per mode:

Single-Task Search (dataset=None) — called without example::

text
import gepa.gepa_launcher as oa

def evaluate(candidate):
    result = run_code(candidate["code"])
    oa.log(f"Output: {result}")      # ASI via oa.log()
    return compute_score(result)

Multi-Task Search / Generalization (dataset provided) — called per example::

text
def evaluate(candidate, example):
    pred = run(candidate["prompt"], example["input"])
    score = 1.0 if pred == example["expected"] else 0.0
    return score, {"Input": example["input"], "Output": pred}

Reserved side_info keys

"log", "stdout", "stderr" are used by GEPA's automatic capture. If you use them, GEPA stores captured output under "_gepa_log" etc. to avoid collisions.

Source code in gepa/gepa_launcher.py

text
def __call__(
    self, candidate: str | Candidate, example: object | None = None, **kwargs: Any
) -> tuple[float, SideInfo] | float:
    """Score a candidate, returning a score and diagnostic side information (ASI).

    This is the function you write.  GEPA calls it repeatedly with
    mutated candidates and collects the returned scores and diagnostics
    to drive the optimization loop.

    Args:
        candidate: The text parameter(s) to evaluate.  Type matches
            ``seed_candidate``: plain ``str`` if you passed a string,
            or ``dict[str, str]`` if you passed a dict.
        example: One item from ``dataset``.  **Not passed** in
            single-task search mode (``dataset=None``).
        opt_state: *(optional)* Declare ``opt_state: OptimizationState``
            in your signature to receive historical best evaluations
            for warm-starting.  This is a **reserved parameter name**
            — GEPA injects it automatically.

    Returns:
        Either ``(score, side_info)`` or just ``score``:

        - **score** (float): Higher is better.
        - **side_info** (:data:`SideInfo`): Diagnostic dict (ASI)
          powering LLM reflection.

        If you return score-only, use ``oa.log()`` or
        ``capture_stdio=True`` to provide diagnostic context.

    Evaluator signature per mode:

    **Single-Task Search** (``dataset=None``) — called without ``example``::

        import gepa.gepa_launcher as oa

        def evaluate(candidate):
            result = run_code(candidate["code"])
            oa.log(f"Output: {result}")      # ASI via oa.log()
            return compute_score(result)

    **Multi-Task Search / Generalization** (``dataset`` provided) — called per example::

        def evaluate(candidate, example):
            pred = run(candidate["prompt"], example["input"])
            score = 1.0 if pred == example["expected"] else 0.0
            return score, {"Input": example["input"], "Output": pred}

    Reserved side_info keys:
        ``"log"``, ``"stdout"``, ``"stderr"`` are used by GEPA's
        automatic capture.  If you use them, GEPA stores captured
        output under ``"_gepa_log"`` etc. to avoid collisions.
    """
    ...