Skip to content

Commit 2341fbe

Browse files
committed
[NA] [SDK] chore: better exception for evaluate_experiment with no test cases
1 parent 3fd505b commit 2341fbe

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

sdks/python/src/opik/evaluation/evaluator.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from .scorers import scorer_function, scorer_wrapper_metric
3636
from . import test_result
3737
from .types import ExperimentScoreFunction, LLMTask, ScoringKeyMappingType
38-
from .. import url_helpers
38+
from .. import url_helpers, exceptions
3939
from ..api_objects.dataset.evaluation_suite import suite_result_constructor
4040

4141
if TYPE_CHECKING:
@@ -577,7 +577,7 @@ def evaluate_experiment(
577577
) -> evaluation_result.EvaluationResult:
578578
"""Update the existing experiment with new evaluation metrics. You can use either `scoring_metrics` or `scorer_functions` to calculate
579579
evaluation metrics. The scorer functions doesn't require `scoring_key_mapping` and use reserved parameters
580-
to receive inputs and outputs from the task.
580+
to receive inputs and outputs from the task. The experiment requires at least one test case.
581581
582582
Args:
583583
experiment_name: The name of the experiment to update.
@@ -637,6 +637,11 @@ def evaluate_experiment(
637637
dataset_=dataset_,
638638
scoring_key_mapping=scoring_key_mapping,
639639
)
640+
if not test_cases:
641+
raise exceptions.EmptyExperiment(
642+
f"Experiment {experiment.id} does not have any test traces to run an evaluation"
643+
)
644+
640645
first_trace_id = test_cases[0].trace_id
641646
project_name = rest_operations.get_trace_project_name(
642647
client=client, trace_id=first_trace_id

sdks/python/src/opik/exceptions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ class ExperimentNotFound(OpikException):
102102
pass
103103

104104

105+
class EmptyExperiment(OpikException):
106+
"""Exception raised when an experiment requires test cases for evaluation and has none"""
107+
108+
pass
109+
110+
105111
class DatasetNotFound(OpikException):
106112
pass
107113

0 commit comments

Comments
 (0)