Customize Metric Naming and Derivation
Promptfoo config demonstrating dynamic and derived metric names, letting one assertion report under a different metric per test case.
Why it matters
Enhance your prompt evaluation process by defining and deriving custom metrics. This asset allows for more nuanced and specific performance analysis beyond standard metrics.
Outcomes
What it gets done
Define custom metric names for prompt evaluation.
Implement logic for deriving new metrics from existing ones.
Tailor evaluation criteria to specific project needs.
Improve the precision of prompt performance reporting.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/pfoo-named-metrics | bash Overview
Named Metrics
This Promptfoo example demonstrates dynamic and derived metric names, using a Nunjucks-templated metric field so one llm-rubric assertion reports under a different metric per test, plus a derivedMetrics formula computing one metric from another. Use it as a template when organizing eval results under custom metric names, including per-test dynamic naming and metrics derived from other metrics.
What it does
This Promptfoo config demonstrates custom and dynamically named metrics for evaluation. A derivedMetrics block defines DoubleConsistency as a computed metric equal to Consistency * 2, combining an existing metric via a formula rather than a fresh assertion. A defaultTest shows dynamic metric naming: its llm-rubric assertion checks that a response uses {{speechStyle}} speech patterns, and its metric field itself contains a Nunjucks template variable ({{speechStyle}}Style), so the same single assertion definition renders to a differently named metric per test - "pirateStyle", "nauticalStyle", "archaicStyle" - letting results be filtered by style without duplicating the assertion. Two prompt templates rewrite input text as pirate speech or 17th-century seafarer speech.
Later tests layer static metrics alongside the dynamic one: a JSON-validation test tagged with the Consistency metric, which then feeds the derived DoubleConsistency metric, and a "complex validation" test with two more static metrics - Length (a JavaScript length check) and Relevance (a similar semantic check).
When to use - and when NOT to
Use it as a template for organizing eval results under custom metric names, including metrics whose name is computed per test via Nunjucks templating, and metrics computed from other metrics via derivedMetrics. Do not use it if Promptfoo's default per-assertion-type reporting already gives you the breakdown you need.
Inputs and outputs
Input: the YAML config - two style-rewriting prompt templates, a derivedMetrics formula, and test cases combining dynamic and static metric names. Output: Promptfoo's evaluation report broken down by named metric - pirateStyle, nauticalStyle, archaicStyle, Consistency, DoubleConsistency, Length, Relevance - rather than by raw assertion type alone.
Integrations
Uses Promptfoo's metric field, including Nunjucks template variables for dynamic naming, and its derivedMetrics feature for computing one metric from another.
Who it's for
Teams that need eval results broken down by custom, meaningful metric names - especially when the same assertion logic needs to report under a different metric name per test case.
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.