{"slug": "llm-regression-testing-with-promptfoo-derived-metrics", "title": "LLM Regression Testing With Promptfoo Derived Metrics", "summary": "A hands-on test of Promptfoo 0.127.0 on Ubuntu 22.04.5 with Node.js v22.23.5 found that a rejected derived metric formula halts an eval before any test case runs, while a malformed response field produces a separate schema failure — two distinct failure modes the author distinguished using exit codes. The author ran `npx promptfoo eval --no-cache` against a two-case support ticket classifier fixture, where setting REGRESS=1 changed only the billing ticket's priority from the string 'normal' to the number 1, triggering one schema failure while routing still passed. The test follows Promptfoo 0.126.0's November 18, 2026 restriction on derived metric string syntax, which still permits arithmetic and ternaries but blocks function calls.", "body_md": "In this blog post, we will see how to run LLM regression testing with Promptfoo using a support ticket classifier. I will start with a passing baseline, break one field in the response, and check what the failure looks like in the terminal. Then we will fix a derived metric formula that can stop an eval before it runs a single case.\n\n**Quick answer:** For LLM regression testing, run `npx promptfoo eval --no-cache` against fixed inputs and assert the response contract separately from the business rule. In my two-case fixture, a numeric priority caused one schema failure while routing still passed. A rejected derived metric formula stopped the eval entirely. Those are different failures, and the exit codes helped me tell them apart.\n\n*Tested on Ubuntu 22.04.5 LTS x86_64 with Promptfoo 0.127.0, Node.js v22.23.5, and npm 10.9.9 on December 4, 2026.*\n\nTable of Contents\n\n## What is LLM regression testing?\n\nLLM regression testing reruns representative inputs after a prompt, model, or application change and checks whether the responses still meet the same requirements. The expected result is a contract, not necessarily an exact sentence. For a classifier, a valid JSON object and the correct queue are more useful checks than matching an entire response string.\n\nOn November 18, 2026, [Promptfoo 0.126.0](https://github.com/promptfoo/promptfoo/releases/tag/0.126.0) restricted the syntax allowed in derived metric strings. Arithmetic and ternaries still work, but a function call can stop the eval before the first test. I tested on [0.127.0, released December 2, 2026](https://github.com/promptfoo/promptfoo/releases/tag/0.127.0), so you can see what that looks like on a current release and how it differs from a bad response.\n\nIf you are new to LLM testing, my [beginner’s guide to testing LLMs](https://qainsights.com/how-to-test-llms-a-beginners-guide/) covers the broader picture. Here I want to answer a narrower question: can the contract tests prove they fail for the right reason before I wire them up to a real model? That is worth checking first. A green suite that never caught a known bad response is not much of a safety net.\n\n## How do you set up a Promptfoo eval without an API key?\n\nStart with a local JavaScript provider that returns known responses. I used two imaginary support tickets, one about a duplicate charge and one about an app that would not start. Neither the prompt nor the ticket needs to leave the machine for this eval. The fixture substitutes for a model response; it is not a model or a benchmark.\n\n**1. Install the pinned version.** Run this in an empty lab directory. Check the Node version first, because a Promptfoo upgrade can also change the supported runtime. Keep the lockfile if you turn this lab into a project so that a change in its dependencies is not mixed with a change in the eval.\n\n```\n# Run from a clean lab directory\nnode --version\nnpm --version\nnpm install --no-audit --no-fund [email protected]\nnpx promptfoo --version\nexport PROMPTFOO_DISABLE_TELEMETRY=1\n```\n\n**2. Save this as `ticket-provider.cjs`.** The provider puts a billing ticket in the billing queue and returns a string priority by default. When I set `REGRESS=1`, only the billing ticket changes, and its priority becomes a number. I kept routing unchanged so the results would show exactly which check caught the regression.\n\n```\nmodule.exports = class TicketFixture {\n  id() {\n    return 'ticket-fixture';\n  }\n\n  async callApi(_prompt, context) {\n    const isBilling = context.vars.ticket.includes('charged');\n    const queue = isBilling ? 'billing' : 'technical';\n    const priority = isBilling && process.env.REGRESS === '1' ? 1 : 'normal';\n    return { output: JSON.stringify({ queue, priority }) };\n  }\n};\n```\n\n**Tip:** Use a controlled bad response before you try a live provider. When you switch to a model, you may have to investigate sampling, retries, or a different model revision. None of those should be in the way when you are checking whether your schema assertion can catch an integer where it expects a string.\n\n## How do you test an LLM response against a JSON schema?\n\nPut an `is-json` assertion in `defaultTest` so both rows use the same schema, then check the expected queue separately on each row. The schema requires two fields, rejects extras, and limits the allowed values. The routing assertion checks an input-specific decision that the schema cannot infer: both queue names are legal, but only one is correct for each ticket.\n\n**3. Save the eval as `promptfooconfig.yaml`.** I named the schema assertion `Schema` and the business assertion `Routing`. The distinction pays off on a failure: you can see whether the output broke the parser contract or followed the contract while making a bad decision.\n\n```\ndescription: Support ticket output contract\nproviders:\n  - file://ticket-provider.cjs\nprompts:\n  - 'Return the support queue and priority as JSON: {{ticket}}'\ndefaultTest:\n  assert:\n    - type: is-json\n      metric: Schema\n      value:\n        type: object\n        required: [queue, priority]\n        additionalProperties: false\n        properties:\n          queue: { enum: [billing, technical] }\n          priority: { type: string, enum: [normal, urgent] }\ntests:\n  - description: Billing ticket\n    vars:\n      ticket: I was charged twice.\n    assert:\n      - type: javascript\n        metric: Routing\n        value: 'JSON.parse(output).queue === \"billing\"'\n  - description: Technical ticket\n    vars:\n      ticket: The app will not start.\n    assert:\n      - type: javascript\n        metric: Routing\n        value: 'JSON.parse(output).queue === \"technical\"'\nderivedMetrics:\n  - name: WeakerCheck\n    value: 'Schema < Routing ? Schema : Routing'\n```\n\nThe expected queue lives in the test, not in the provider configuration. That matters when you replace the stub with an actual model. You want the test data to keep its expectations rather than derive them from whatever the provider happened to return. Add cases that represent what users actually ask, but strip real names, account details, and secrets before saving them.\n\n## How do you prove the Promptfoo eval catches a regression?\n\nRun the same suite twice, changing only the fixture’s response. The first run establishes that the known-good outputs pass. The second must fail the billing case for the reason we expected. I disabled the cache, progress bar, sharing, and the table so I could capture clean summaries and compare the saved JSON instead of reading the full terminal table.\n\n**4. Run the baseline and the controlled regression.** Run the commands from the same directory as the config. Print each exit code immediately after its eval so you do not accidentally capture the status from another command.\n\n```\n# Run the known-good responses and keep the JSON report\nREGRESS=0 npx promptfoo eval -c promptfooconfig.yaml --no-cache \\\n  --no-progress-bar --no-share --no-table -o baseline.json\nprintf 'exit=%s\\n' \"$?\"\n\n# Change one field and repeat the same test cases\nREGRESS=1 npx promptfoo eval -c promptfooconfig.yaml --no-cache \\\n  --no-progress-bar --no-share --no-table -o regression.json\nprintf 'exit=%s\\n' \"$?\"\n```\n\nMy baseline passed two cases and exited `0`. The regression passed one and failed one, with zero run errors and exit `100`. The billing response still had `queue: billing`, but `priority` was `1`. The report showed `Schema=0` and `Routing=1` for that row. The technical ticket did not change.\n\nThat is the split I care about when someone changes an LLM response path. A response can look reasonable in a chat window and still break the code that reads it. My [walkthrough of an LLM request and response cycle](https://qainsights.com/how-does-an-llm-request-and-response-cycle-work-a-full-walkthrough/) shows where such a response sits in the larger flow.\n\n## Why does a Promptfoo derived metric formula stop the eval?\n\nPromptfoo checks string formulas before it evaluates the rows. In this lab `WeakerCheck` is the lower of the two named scores; it is a summary, not a substitute for the individual assertions. I changed its working ternary to `min(Schema, Routing)` to show what happens when a string formula uses a function call.\n\n**5. Break the formula in a copy, then use the original config again.** This time leave the fixture in its baseline mode. That way, any change in behavior comes from the config, not the response.\n\n```\n# Make a copy with an unsupported function call\nsed 's/Schema < Routing ? Schema : Routing/min(Schema, Routing)/' \\\n  promptfooconfig.yaml > invalid-formula.yaml\nREGRESS=0 npx promptfoo eval -c invalid-formula.yaml --no-cache \\\n  --no-progress-bar --no-share --no-table -o invalid-formula.json\nprintf 'exit=%s\\n' \"$?\"\n\n# Use the original config with the supported ternary\nREGRESS=0 npx promptfoo eval -c promptfooconfig.yaml --no-cache \\\n  --no-progress-bar --no-share --no-table -o baseline.json\nprintf 'exit=%s\\n' \"$?\"\n```\n\nI got `Invalid formula for derived metric \"WeakerCheck\": Expected arithmetic over numeric scores` and exit `1`. There was no test-case run line and no output report for that command. The ternary config completed both cases. In the JSON reports, the aggregate `WeakerCheck` was `2` for the baseline and `1` for the response regression. The formula error does not give you a zero score; it leaves you with no graded rows to interpret.\n\n**Tip:** Read the [Promptfoo assertions and metrics documentation](https://www.promptfoo.dev/docs/configuration/expected-outputs/) before moving a spreadsheet formula into YAML. The supported ternary computes the lower score here. If you need scoring logic that is not expressible with a string formula, the docs describe a JavaScript config function. I would keep that out of the config unless the extra logic is really needed.\n\n## How do you read the exit status in CI?\n\nLet the eval command return its status to CI and keep its output for diagnosis. In this version and fixture, `0` meant both tests passed, `100` meant there was an assertion failure, and `1` meant the invalid configuration stopped the run. Both nonzero outcomes should make a gate red, but only the assertion failure in this exercise produced a results JSON you can inspect.\n\n| Run | Exit | What to inspect first | \n|---|---|---|\n| Passing baseline | 0 | Both checks passed on both fixtures | \n| Response regression | 100 | Billing row and schema assertion in regression.json | \n| Invalid formula | 1 | Formula in the config and the first error in stderr | \n\nI would point CI at a fresh output path on each run. Otherwise a previous report can still be on disk when a new run aborts, and you can end up reviewing evidence from the wrong build. Keep stdout and stderr even if you also collect the JSON. If there is no report, the log may be the only useful artifact.\n\n## Honest Pros and Cons\n\nThe good part is that two tiny fixtures are enough to prove the harness behaves as intended. The schema catches something a human might overlook, and the separately named checks explain the failure better than one overall score. I also like that the same case can be wired to a real provider later without changing the expected queue.\n\nThe trade-off is that a fixture cannot tell you how often a live model makes the wrong decision. A schema cannot prove that a valid-looking answer is useful either. Keep this suite as a quick contract check, then run a separate set against the model and prompt you actually deploy. For live runs, record the provider and model revision so you know what you compared.\n\n## FAQ\n\n### Can I run Promptfoo without an API key?\n\nYes. For a deterministic harness check, supply a local JavaScript provider that returns fixture outputs and choose assertions that do not call a model. This proves your evaluator can catch known problems without credentials. It does not measure real model behavior, and a hosted model or model-based grader may still require a key.\n\n### What is the difference between a named assertion and a derived metric?\n\nA named assertion assigns a label to the result of a check, such as whether a response satisfies a JSON schema. A derived metric calculates a secondary value from named scores. Use the assertion to enforce the contract and the derived metric to summarize, compare, or report on those results.\n\n### Why does min() stop a Promptfoo eval before any cases run?\n\nThe string formula parser does not accept function calls in the version tested here. It validates the expression before grading any cases. To select the lower of two numeric named scores, use a comparison and a ternary, as in the WeakerCheck example. This changes the formula, not the fixture or the assertions.\n\n### How do I fail CI when an LLM response breaks its JSON contract?\n\nMake the JSON Schema assertion part of the suite and let the eval process exit status reach CI. In this run, Promptfoo exited 100 on a failed assertion. Keep the JSON results and the console log, since an invalid configuration can also fail the job but may not write a report.\n\n## Final Words\n\nI would start with a small contract for the output your application actually consumes. Prove it can fail with a fixture, then reuse the assertions on a small live evaluation before you add more cases. Keep formula mistakes visible as setup failures. A scoring formula should help you understand the results, not hide the reason a run stopped.\n\nHappy Testing!\n\n## Explore related guides\n\n- [How to Test LLMs? A Beginner’s Guide](https://qainsights.com/how-to-test-llms-a-beginners-guide/)\n- [How Does an LLM Request and Response Cycle Work?](https://qainsights.com/how-does-an-llm-request-and-response-cycle-work-a-full-walkthrough/)\n- [Throughput vs Goodput in LLM Testing](https://qainsights.com/throughput-vs-goodput-the-performance-metric-you-are-probably-ignoring-in-llm-testing/)\n- [How to Measure Time to First Token in AI Systems](https://qainsights.com/how-to-measure-time-to-first-token-ttft-in-ai-systems/)", "url": "https://wpnews.pro/news/llm-regression-testing-with-promptfoo-derived-metrics", "canonical_source": "https://qainsights.com/llm-regression-testing/", "published_at": "2026-12-05 21:46:22+00:00", "updated_at": "2026-12-05 22:16:13.132569+00:00", "lang": "en", "topics": ["large-language-models", "ai-tools", "developer-tools"], "entities": ["Promptfoo", "Promptfoo 0.127.0", "Promptfoo 0.126.0", "Node.js", "npm", "Ubuntu"], "also_reported_by": [], "takeaway": "Assert the response contract separately from the business rule and run `npx promptfoo eval --no-cache` against fixed inputs, since a numeric priority caused one schema failure while routing still passed, and a rejected derived metric formula stopped the eval before any case ran.", "recommendation": {"advice": "Run `npx promptfoo eval --no-cache` against a controlled bad fixture before wiring a live model, and assert schema and business rules as separate checks so exit codes distinguish a bad response from a rejected derived metric formula.", "playbook": "evals-testing", "playbook_url": "https://wpnews.pro/playbooks/evals-testing"}, "alternates": {"html": "https://wpnews.pro/news/llm-regression-testing-with-promptfoo-derived-metrics", "markdown": "https://wpnews.pro/news/llm-regression-testing-with-promptfoo-derived-metrics.md", "text": "https://wpnews.pro/news/llm-regression-testing-with-promptfoo-derived-metrics.txt", "jsonld": "https://wpnews.pro/news/llm-regression-testing-with-promptfoo-derived-metrics.jsonld"}}