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.
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.
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.
Table of Contents
What is LLM regression testing? #
LLM 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.
On November 18, 2026, Promptfoo 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, so you can see what that looks like on a current release and how it differs from a bad response.
If you are new to LLM testing, my beginner’s guide to testing LLMs 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.
How do you set up a Promptfoo eval without an API key? #
Start 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.
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.
node --version
npm --version
npm install --no-audit --no-fund [email protected]
npx promptfoo --version
export PROMPTFOO_DISABLE_TELEMETRY=1
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.
module.exports = class TicketFixture {
id() {
return 'ticket-fixture';
}
async callApi(_prompt, context) {
const isBilling = context.vars.ticket.includes('charged');
const queue = isBilling ? 'billing' : 'technical';
const priority = isBilling && process.env.REGRESS === '1' ? 1 : 'normal';
return { output: JSON.stringify({ queue, priority }) };
}
};
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.
How do you test an LLM response against a JSON schema? #
Put 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.
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.
description: Support ticket output contract
providers:
- file://ticket-provider.cjs
prompts:
- 'Return the support queue and priority as JSON: {{ticket}}'
defaultTest:
assert:
- type: is-json
metric: Schema
value:
type: object
required: [queue, priority]
additionalProperties: false
properties:
queue: { enum: [billing, technical] }
priority: { type: string, enum: [normal, urgent] }
tests:
- description: Billing ticket
vars:
ticket: I was charged twice.
assert:
- type: javascript
metric: Routing
value: 'JSON.parse(output).queue === "billing"'
- description: Technical ticket
vars:
ticket: The app will not start.
assert:
- type: javascript
metric: Routing
value: 'JSON.parse(output).queue === "technical"'
derivedMetrics:
- name: WeakerCheck
value: 'Schema < Routing ? Schema : Routing'
The 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.
How do you prove the Promptfoo eval catches a regression? #
Run 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.
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.
REGRESS=0 npx promptfoo eval -c promptfooconfig.yaml --no-cache \
--no-progress-bar --no-share --no-table -o baseline.json
printf 'exit=%s\n' "$?"
REGRESS=1 npx promptfoo eval -c promptfooconfig.yaml --no-cache \
--no-progress-bar --no-share --no-table -o regression.json
printf 'exit=%s\n' "$?"
My 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.
That 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 shows where such a response sits in the larger flow.
Why does a Promptfoo derived metric formula stop the eval? #
Promptfoo 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.
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.
sed 's/Schema < Routing ? Schema : Routing/min(Schema, Routing)/' \
promptfooconfig.yaml > invalid-formula.yaml
REGRESS=0 npx promptfoo eval -c invalid-formula.yaml --no-cache \
--no-progress-bar --no-share --no-table -o invalid-formula.json
printf 'exit=%s\n' "$?"
REGRESS=0 npx promptfoo eval -c promptfooconfig.yaml --no-cache \
--no-progress-bar --no-share --no-table -o baseline.json
printf 'exit=%s\n' "$?"
I 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.
Tip: Read the Promptfoo assertions and metrics documentation 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.
How do you read the exit status in CI? #
Let 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.
| Run | Exit | What to inspect first |
|---|---|---|
| Passing baseline | 0 | Both checks passed on both fixtures |
| Response regression | 100 | Billing row and schema assertion in regression.json |
| Invalid formula | 1 | Formula in the config and the first error in stderr |
I 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.
Honest Pros and Cons #
The 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.
The 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.
FAQ #
Can I run Promptfoo without an API key?
Yes. 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.
What is the difference between a named assertion and a derived metric?
A 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.
Why does min() stop a Promptfoo eval before any cases run?
The 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.
How do I fail CI when an LLM response breaks its JSON contract?
Make 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.
Final Words #
I 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.
Happy Testing!
Explore related guides #
- How to Test LLMs? A Beginner’s Guide
- How Does an LLM Request and Response Cycle Work?
- Throughput vs Goodput in LLM Testing
- How to Measure Time to First Token in AI Systems