examples/eval-named-metrics/README.md
This example demonstrates custom metric naming and derivation in promptfoo.
npx promptfoo@latest init --example eval-named-metrics
cd eval-named-metrics
promptfoo eval
Dynamic Metric Names: Using template variables like {{speechStyle}}Style in defaultTest.assert to apply different metric names per test case. This enables:
Static Metric Names: Hardcoded metric names like Tone, Consistency, and Length
Derived Metrics: Creating custom metrics based on formulas (e.g., DoubleConsistency = Consistency * 2)
defaultTest:
assert:
- type: llm-rubric
value: The response uses {{speechStyle}} speech patterns
metric: '{{speechStyle}}Style'
tests:
- vars:
body: Ahoy there!
speechStyle: pirate # Results in metric name "pirateStyle"
- vars:
body: Set sail!
speechStyle: nautical # Results in metric name "nauticalStyle"
This allows you to maintain hundreds of test cases with a compact defaultTest configuration while still having unique, filterable metric names per test.