Ends With
The EndsWithMetric checks whether the actual output ends with a specified suffix string.
How It Works
- Optionally converts both the output and suffix to lowercase
- Checks if the output ends with the given suffix
- Returns
1.0 if the suffix matches, 0.0 otherwise
Parameters
| Parameter | Type | Default | Description |
threshold | float | 1.0 | Minimum score to pass |
suffix | str | required | The suffix string to check for |
case_sensitive | bool | True | Whether matching is case-sensitive |
Required Fields
| Field | Required |
input | No |
actual_output | Yes |
expected_output | No |
Usage
from eval_lib.metrics import EndsWithMetric
from eval_lib.test_case import EvalTestCase
import asyncio
test_case = EvalTestCase(
input="Write a sentence ending with a period",
actual_output="The quick brown fox jumps over the lazy dog."
)
metric = EndsWithMetric(threshold=1.0, suffix=".")
result = asyncio.run(metric.evaluate(test_case))
print(result.score) # 1.0
Example Scenarios
Pass (1.0)
metric = EndsWithMetric(suffix="```", case_sensitive=True)
EvalTestCase(
input="Return a code block",
actual_output='```python\nprint("hello")\n```'
)
# Output ends with the expected suffix
Fail (0.0)
metric = EndsWithMetric(suffix=".", case_sensitive=True)
EvalTestCase(
input="Write a complete sentence",
actual_output="The answer is 42"
)
# Output does not end with "."