Skip to main content
Every eval is a function that receives an EvalContext. Knowing what the context holds and how it becomes a result covers most of what you need to write evals.

Define an eval

  • The eval’s name is the Python function name or the first argument to evaluate(). Its id is <file>::<name>, for example support.eval.ts::test_cancellation.
  • dataset defaults to the file name (evals.py becomes evals, support.eval.ts becomes support).
  • Functions can be sync or async.
  • With no options, use a bare @eval or evaluate(name, fn).
The full option list (reference, default_score_key, timeout, trials, target, evaluators, cases, input_loader) is in the Python and TypeScript references.

The context

Options you pass to the decorator start out on ctx. Your eval fills in the rest: store() sets several fields in one call. metadata and trace_data merge. A score with the same key as an existing score replaces it.
You don’t return anything. When the function finishes, the context is built into a result.

Run information

The context also tells your eval where it’s running. You can use this to tag traces in an external tool, or to read the settings of a run config:

Errors

An exception other than an assertion failure is not a score. It’s recorded as the result’s error: the exception type, the message and the traceback. Anything already on the context, such as the input and any output you set, is kept. Errored results don’t pass, and evaluators don’t run on them.

Timeouts

Set timeout (in seconds) on an eval, in file defaults, or for every eval with --timeout or timeout in ezvals.json. The run-wide value overrides per-eval timeouts. When an eval hits its timeout it stops, and its error is TimeoutError: Evaluation timed out after 5.0s. The timeout cancels the whole eval function, so an except TimeoutError inside the eval never runs. To score slowness instead of treating it as an error, put a shorter time limit on the agent call yourself:
In TypeScript, code that blocks the event loop can’t be interrupted. The eval is still reported as timed out, but the blocking work keeps running until it finishes.

Returning several results

An eval can also return a list of results instead of using ctx. This is useful when one call produces many outputs to grade. In Python, return EvalResult objects. In TypeScript, return plain objects with the same fields.
Prefer cases when you can. Each case can be selected, rerun and regraded on its own. Evals that return several results can’t be regraded.