Non-Empty¶
The NonEmptyMetric checks that the actual output is not empty or whitespace-only.
How It Works¶
- Strips leading and trailing whitespace from the output
- Checks if the resulting string has a length greater than zero
- Returns
1.0if the output is non-empty,0.0otherwise
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