DeepEvaldeepeval 4.2 · Python 3.9+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
23 small wins to finish your pathNext lesson

ErrorConfig: when a metric cannot run

Every run so far had what its metric needed. Real test sets are messier, and one test case a metric cannot score stops the whole run unless you say otherwise.

python
broken = cases + [
    LLMTestCase(input="Can I get a refund?", actual_output="Yes, within 30 days."),
]

A third question, about refunds, with no expected answer written yet. Exact match needs one.

Example
from deepeval import evaluate
from deepeval.evaluate import DisplayConfig

quiet = DisplayConfig(print_results=False, show_indicator=False)
try:
    evaluate(test_cases=broken, metrics=[ExactMatchMetric()], display_config=quiet)
except Exception as error:
    print(type(error).__name__)
    print(error)

The whole run stopped. The two test cases that were fine got no result either, because evaluate raised instead of returning. The message says exactly what is missing and which metric wanted it.

Two ways to carry on

ErrorConfig decides what a run does when a metric cannot finish. It has two switches, and they mean different things.

python
def show(result):
    for test in result.test_results:
        errors = [data.error for data in test.metrics_data or []]
        print(test.name, test.success, errors)

A small helper, so the next two runs print the same way: each test case's name, whether it passed, and any error its metrics recorded.

Example
from deepeval.evaluate import ErrorConfig

result = evaluate(test_cases=broken, metrics=[ExactMatchMetric()], display_config=quiet,
                  error_config=ErrorConfig(skip_on_missing_params=True))
show(result)

skip_on_missing_params skips a metric on any test case that lacks what the metric needs. The refund question has no metric data at all, and it is reported as a success.

Look at the summary too. It counts two tests, not three. The skipped case is in test_results but left out of the pass rate, so the two disagree about how many tests there were.

Example
result = evaluate(test_cases=broken, metrics=[ExactMatchMetric()], display_config=quiet,
                  error_config=ErrorConfig(ignore_errors=True))
show(result)

ignore_errors lets the metric fail, records the error on the test case, and carries on. The refund question now fails, with the reason attached, and the summary counts three tests.

Which one to use
Skip when a metric does not apply to some cases, like exact match on questions that have no single right answer. Ignore when a case is broken and you want it counted as a failure rather than hidden. If both are on, skipping wins.
Try it yourself
  • Give the refund question an expected output and run it with neither switch.
  • Turn both switches on together and check which behaviour you get.

You understood something today that you didn't yesterday.