Skip to main content
The @eval decorator marks functions as evaluations. Here’s a complete example:

Configuration Options

Dataset

Groups related evaluations together:
If not specified, dataset defaults to the filename (e.g., evals.pyevals).

Labels

Tags for filtering:
Filter with CLI:

Pre-populated Fields

Set context fields directly in the decorator:

Default Score Key

Specify the key for scores (used when assertions fail or with store(scores=...)):

Timeout

Set a maximum execution time:
On timeout, the evaluation fails with an error message.

Target Hook

Run a function before the evaluation body:
This separates agent invocation from assertion logic.

Evaluators

Post-processing functions that add scores:

Input Loader

Load test examples dynamically from external sources (databases, APIs):
Each example from the loader becomes a separate eval run. The loader is called lazily at eval time (not at import time), making it ideal for fetching from LangSmith, databases, or APIs. Loader return format:
  • Return a list of dicts with input, reference, and/or metadata keys
  • Or return objects with .input, .reference, .metadata attributes
input_loader cannot be combined with input=, reference=, or cases=.

Sync and Async

Both sync and async functions work—just use async def if your code uses await.

Returning Multiple Results

Return a list of EvalResult objects for batch evaluations:

All Options Reference