Skip to content

Commit 4f1d951

Browse files
ekon15claude
andauthored
fix: warn when Eval() receives an empty dataset (#109)
* warn when Eval() receives an empty dataset Print a warning to stderr when no data rows are found after iterating the dataset, so users get an actionable signal instead of silently landing on an empty experiment in the UI. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * use eprint and bcolors.WARNING for empty dataset warning Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * ruff format Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: ekon15 <ekon15@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d82c425 commit 4f1d951

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

py/src/braintrust/framework.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,6 +1695,11 @@ async def with_max_concurrency(coro):
16951695
for trial_index in range(evaluator.trial_count):
16961696
tasks.append(asyncio.create_task(with_max_concurrency(run_evaluator_task(datum, trial_index))))
16971697

1698+
if not tasks:
1699+
eprint(
1700+
f"{bcolors.WARNING}Warning: no data rows found for evaluator '{evaluator.eval_name}'. The experiment will be empty.{bcolors.ENDC}"
1701+
)
1702+
16981703
results = []
16991704
for task in std_tqdm(tasks, desc=f"{evaluator.eval_name} (tasks)", position=position, disable=position is None):
17001705
results.append(await task)

py/src/braintrust/test_framework.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,3 +607,22 @@ async def test_eval_enable_cache():
607607
)
608608
state.span_cache.start.assert_called()
609609
state.span_cache.stop.assert_called()
610+
611+
612+
@pytest.mark.asyncio
613+
async def test_run_evaluator_empty_dataset_warns(capsys):
614+
"""Warn when run_evaluator receives an empty dataset."""
615+
evaluator = Evaluator(
616+
project_name="test-project",
617+
eval_name="test-evaluator",
618+
data=[],
619+
task=lambda input: input,
620+
scores=[],
621+
experiment_name=None,
622+
metadata=None,
623+
)
624+
await run_evaluator(experiment=None, evaluator=evaluator, position=None, filters=[])
625+
626+
captured = capsys.readouterr()
627+
assert "Warning" in captured.err
628+
assert "empty" in captured.err.lower()

0 commit comments

Comments
 (0)