Skip to content

Non-Empty

The NonEmptyMetric checks that the actual output is not empty or whitespace-only.

How It Works

  1. Strips leading and trailing whitespace from the output
  2. Checks if the resulting string has a length greater than zero
  3. Returns 1.0 if the output is non-empty, 0.0 otherwise

Parameters

Parameter Type Default Description
threshold float 1.0 Minimum score to pass

This metric has no additional parameters.

Required Fields

Field Required
input No
actual_output Yes
expected_output No

Usage

from eval_lib.metrics import NonEmptyMetric
from eval_lib.test_case import EvalTestCase
import asyncio

test_case = EvalTestCase(
    input="Say something",
    actual_output="Hello, world!"
)

metric = NonEmptyMetric(threshold=1.0)
result = asyncio.run(metric.evaluate(test_case))
print(result.score)  # 1.0

Example Scenarios

Pass (1.0)

metric = NonEmptyMetric()
EvalTestCase(
    input="Generate a response",
    actual_output="Here is my response."
)
# Output is non-empty

Fail (0.0)

metric = NonEmptyMetric()
EvalTestCase(
    input="Generate a response",
    actual_output=""
)
# Output is empty

Fail (0.0) — whitespace only

metric = NonEmptyMetric()
EvalTestCase(
    input="Generate a response",
    actual_output="   \n\t  "
)
# Output contains only whitespace