Strona główna / Artykuły / Evaluating and Regression-Testing LLM Prompts in Production

Artykuł opublikowany po angielsku.

Evaluating and Regression-Testing LLM Prompts in Production

Build evaluation sets, rubrics and regression suites that tell whether a prompt change helped, covering exact checks, LLM judges, trade-offs and golden cases.

1832 słów

Gut feeling is a poor way to improve a production LLM system. A support team edits a prompt, tries it a few times, and announces that the new version feels better. That isn't an evaluation. The change may have lifted classification quality. It may equally have helped only the handful of examples somebody happened to try, while making replies wordier, slowing responses, hurting unusual cases, or opening the door wider to prompt injection.

When prompts drive a real application, evaluation is the feedback loop that shows whether a change actually helped.

Starting with concrete test cases

Prompt testing begins with specific cases. For a support application, one case could bundle a customer message saying a password-reset link expired, plus the documentation relevant to that problem.

Input:
Customer says their password reset link expired.

Context:
Relevant support documentation.

Expected behavior:
Classify as password-reset issue.
Do not claim the account is locked.
Recommend the documented recovery path.
Return the required structured output.

A runner pushes the case through the application and stores the outcome. Simple in principle, but production setups let many things shift at once. A prompt edit might ride along with a new model, another way of choosing context, fresh retrieval data, different tool definitions, a new output schema or changed generation settings. The thing under test is therefore the whole system configuration, not just the prompt string.

That's partly why prompt work begins to look like software engineering. A prompt turns into an artifact with inputs, expected behavior, versions, tests and regressions.

What a good test set contains

A strong evaluation set isn't a pile of ordinary requests that succeed. For the support system it should deliberately include:

  • plain password-reset cases
  • ambiguous requests
  • cases with missing information
  • documents that contradict each other
  • irrelevant context
  • unusually long conversations
  • hostile customer messages
  • hostile retrieved content
  • requests the system can't support
  • cases that need a tool
  • cases where a tool must not be called
  • tool results that are malformed or incomplete

The final group matters most. An agent should prove more than its ability to succeed. It should show that it fails safely.

Measuring more than one thing

An evaluation, or eval, is a repeatable way to measure performance against stated criteria. The simplest form scores each answer as correct or incorrect, one or zero. That can be enough for classification, but real LLM applications usually need several dimensions. A support reply might be scored on:

  1. Classification: did the system identify the customer's actual issue?
  2. Grounding: do the available evidence and retrieved information back up the response?
  3. Completeness: does it cover everything required to resolve the issue?
  4. Safety: did it avoid unauthorized claims or actions and stay within its permissions?
  5. Format: does the output follow the required structure or schema?
  6. Helpfulness: would it actually help the customer reach their goal?
  7. Efficiency: did it skip unneeded context, retrieval and tool calls while still giving a good answer?

A single quality number can mislead for exactly this reason. A system can grow more helpful and less safe, more accurate and far costlier, or more eloquent while breaking its schema more often. A serious evaluation tracks the dimensions that matter to the application. Stanford's HELM project reflects the same thinking: it assesses models across many scenarios and dimensions rather than squeezing behavior into one capability score, and it spans capability, instruction following, safety, long context, domain-specific tests and more.

The dataset matters more than a clever judge prompt

Imagine testing the support system on just ten easy cases, all of them password resets.

password reset
password reset
password reset
password reset
...

A new prompt could score 100% and still do badly in production. A useful dataset mirrors the mix of cases the system is expected to meet, so it needs variety in wording, difficulty, document quality, languages or dialects where relevant, context length, ambiguity, edge cases, adversarial input and customer circumstances. It also needs enough hard examples to surface the failure modes that matter.

Public benchmarks help compare general model ability. MMLU spans 57 subject areas, and HELM covers many task-specific and risk-oriented scenarios. Neither replaces an application's own set, because a support product defines success in its own terms. The question isn't which model tops a general leaderboard. It's which configuration performs best on the work this application actually does.

Ways to judge an output

Exact comparison

Where the answer is fixed, compare the generated value with the expected one, for example a category equal to password_reset or a priority equal to high. That works poorly for open-ended prose, where many answers can be acceptable.

Rule-based checks

Some properties can be tested deterministically.

Does the JSON parse?
Does the required field exist?
Is urgency one of the permitted values?
Was a prohibited field returned?
Was an unauthorized tool called?

These checks need no second model to make the call, which makes them cheap and trustworthy.

Reference answers

A human-written or human-verified answer gives something to compare against. A support case might record the expected diagnosis and the evidence it must cite.

Expected diagnosis:
Password-reset issue
Required evidence:
Recent reset request + unused reset link
Forbidden claim:
Account is locked

The generated reply is then graded against those requirements.

Rubrics

A rubric is an explicit scoring guide. Rather than asking whether an answer is good, it defines levels per criterion.

Grounding:
0 = contains unsupported claims
1 = mostly grounded
2 = fully grounded

Completeness:
0 = misses critical information
1 = partially complete
2 = complete

Safety:
0 = unsafe action or disclosure
1 = safe

Scoring becomes more reproducible, and the team is forced to spell out what good really means.

LLM-as-a-judge

For open-ended text, another LLM can sometimes act as the grader.

Evaluate this support response.
Criteria:
1. Is the diagnosis supported by the supplied evidence?
2. Does the response answer the customer's question?
3. Does it avoid unsupported claims?
4. Does it follow the required tone?
Return a score from 1 to 5 and explain each score.

That's much cheaper and quicker than having a person read every output, and it handles qualities that simple rules can't capture, like clarity or helpfulness. Yet the judge is a model too, which raises a second problem: who evaluates the evaluator? Studies have repeatedly found bias and instability in model-based judging, including position, style and authority effects. A judge model shouldn't be treated as automatic ground truth.

A sensible order of preference follows. Use deterministic checks wherever possible, human review where necessary, and model-based evaluation where it helps, with validation behind it. Check JSON validity with a parser rather than another LLM. Check whether a refund was really issued against the transaction system, not against the model's own account of what happened. For something like empathy in a customer-facing reply, an LLM judge can contribute one signal, backed by human review.

Regression tests

Suppose version 7 of the support prompt works well. A month on, an engineer changes the context template. Document-grounded answers improve, but the model starts ignoring conversation history. The prompt diff itself might not hint at the problem.

A regression test catches the moment when behavior that used to be acceptable gets worse after a change. The workflow looks like this.

The idea is borrowed from classic software testing. LLM applications just have a lot more components that can shift, which widens the area where regressions hide. A change to any item here can alter behavior.

Prompt
Model
Model version
Context selection
Retrieved documents
Memory
Tool definitions
Tool implementation
Output schema
Generation settings
Safety policies

The regression suite should therefore run the system under representative conditions and not check the prompt text alone.

Trade-offs hide inside a single verdict

Say the old prompt scored as follows.

Classification accuracy: 94%
Grounding:               96%
Schema validity:         99%
Unsafe tool calls:       1%
Average latency:         1.8 s

And the new one scored this.

Classification accuracy: 96%
Grounding:               95%
Schema validity:         99%
Unsafe tool calls:       4%
Average latency:         2.4 s

Calling the new version better would conceal a trade-off. Classification gained two points, but unsafe tool calls quadrupled and latency also went up. Evaluation puts such trade-offs in plain sight.

Averages can conceal serious failures too. If 99% of requests are safe but the other 1% involve unauthorized financial actions, a 99% safety score may be unacceptable. For high-risk behavior, teams often look at the relevant failure category separately so it can't vanish into an aggregate.

Coverage traps in the dataset

A subtle trap exists. A dataset of 1,000 cases in which 900 are near-identical password-reset requests may produce an impressive-looking score while saying little about rare but important situations. Coverage has to be planned. A practical set has layers.

Core cases
    Common production scenarios

Edge cases
    Ambiguous, unusual, incomplete inputs

Adversarial cases
    Injection, manipulation, malicious content

Safety cases
    Requests involving restricted actions or information

Regression cases
    Previously observed failures

Golden cases
    Carefully reviewed examples representing important behavior

A golden case is an especially trusted example whose expected behavior has been carefully reviewed, and it serves as an anchor when comparing versions.

The dataset should keep evolving, too. When monitoring reveals a new production failure, that failure often deserves to become a new regression test. The result is a loop.

Over time the suite becomes a log of mistakes the system has been taught never to repeat.

Where this leads

Prompt engineering now has another layer on top.

That layer outweighs any individual prompting trick. The strongest production systems don't come from finding one magical prompt. They come from an iterative process in which each change is measured against representative cases.

Measurement also opens the door to the next stage. Once performance can be quantified, sensible questions follow. Would more examples help, or a shorter prompt? Should the system retrieve more context, or less? Is a different model worth trying, or a different way of splitting the task? Could prompt search be automated? Is better accuracy worth extra tokens? The answers depend on measurable trade-offs, and that's where prompt optimization starts.