Technical

LLM Evaluation Before Launch: Real Cases, Grading, Regression Checks

How to build a small evaluation set from your own records, grade LLM outputs automatically, and catch regressions every time you change the prompt or the model.

Kalvyai Engineering · · Updated · 8 min read

LLM Evaluation Before Launch: Real Cases, Grading, Regression Checks (cover)
On this page

An LLM feature that looked fine in a demo has not been tested. The demo used five inputs someone picked by hand. Production will send thousands of inputs nobody picked. This post covers the process we use before an AI feature goes live in an ERP: collect real cases, grade outputs automatically, and rerun everything whenever the prompt or model changes.

Why LLM features need a different kind of test

Normal code gives the same output for the same input, so a unit test can assert one exact result. LLM features break that in three ways:

  • The same input can produce different outputs on different runs.
  • The output can have the right format and still be wrong in content.
  • A prompt change that fixes one case can quietly break three others.

So you need three things: a set of real inputs with known correct answers, a way to score outputs without reading every one by hand, and a habit of rerunning both every time something changes.

The running example in this post is a feature that reads the text of a vendor bill and returns JSON for a draft bill: vendor name, bill number, bill date, currency, total and tax amount. A person approves the draft before it is posted. The same method works for email classification, support replies, product descriptions or any other LLM task.

Step 1: Write down what correct looks like

Do this before you collect any data. If you cannot say what a correct answer is, you cannot grade one.

  1. Define the output contract. List the fields, their types and which ones are required.
  2. Write field rules. Dates in ISO format (2024-03-31). Amounts as decimals, not strings with currency symbols. null when a value is not on the document, never a guess.
  3. Rank failure costs. A wrong total is worse than a missing vendor reference, because a wrong total can get approved and paid. Mark the fields that matter most as critical.
  4. Define what should be refused or flagged. For example: the document is not a bill, the text is unreadable, or one PDF contains two bills.

This list becomes your grading logic later, so keep it in the repository next to the prompt.

Step 2: Build a small evaluation set from real cases

Where to find cases

The best source is data where the correct answer already exists:

  • Posted records in your ERP. If a bill was entered and posted by hand, the source document plus the posted values is a labelled case.
  • Records that people corrected. These show you where humans disagree with the obvious reading of a document.
  • Support tickets and complaints about earlier versions of the feature, or about the manual process it replaces.
  • Edge cases you add on purpose: credit notes, foreign currency, multi-page bills, scanned images with poor text, bills with several tax rates, and documents that are not bills at all.

Avoid writing synthetic examples as your main source. Made-up inputs tend to be cleaner than real ones, and the feature will look better than it is.

How big it should be

A few dozen to around a hundred well-chosen cases is enough to catch obvious regressions. Most should be typical documents, with a deliberate share of hard ones. Grow the set over time instead of trying to make it complete on day one.

Tag every case so you can see where failures cluster, for example typical, credit_note, foreign_currency, poor_scan, not_a_bill.

Clean, check and freeze

  1. Mask personal data, or keep the set inside the same security boundary as production data.
  2. Have a second person review a sample of labels. A wrong label makes a correct output look like a failure, and you will waste time tuning the prompt toward a mistake.
  3. Store the set as a versioned file in git, so every score can be traced to an exact version of the data.

JSON Lines works well: one case per line, easy to diff.

JSON
{"id": "bill-0007", "tags": ["typical"], "input": "ACME SUPPLIES LTD\nInvoice No: INV-2291\nDate: 31/03/2024\n...\nTotal: 11,800.00", "expected": {"vendor_name": "Acme Supplies Ltd", "bill_number": "INV-2291", "bill_date": "2024-03-31", "currency": "INR", "total": "11800.00", "tax_amount": "1800.00"}}
{"id": "bill-0031", "tags": ["not_a_bill"], "input": "Delivery note - no prices\n...", "expected": {"vendor_name": null, "bill_number": null, "bill_date": null, "currency": null, "total": null, "tax_amount": null}}

Step 3: Grade the outputs

Use the cheapest reliable grader for each field. Go from strict to subjective.

Programmatic checks first

Most structured outputs can be graded with plain code:

  • Schema check: is it valid JSON with all required fields?
  • Exact match after normalisation: lowercase, collapse whitespace, then compare.
  • Numeric tolerance: compare amounts as decimals with a small tolerance for rounding.
  • Null handling: if the expected value is null, the output must be null. Guessing counts as a failure.

Here is a minimal harness. extract_bill is your feature: it takes the input text and returns a dict.

Python
import json
from decimal import Decimal, InvalidOperation
from pathlib import Path

from my_feature import extract_bill  # your LLM feature

FIELDS = ["vendor_name", "bill_number", "bill_date", "currency", "total", "tax_amount"]
CRITICAL = {"bill_number", "total", "tax_amount"}
AMOUNTS = {"total", "tax_amount"}


def norm_text(v):
    return " ".join(str(v).lower().split()) if v is not None else None


def to_decimal(v):
    try:
        return Decimal(str(v))
    except (InvalidOperation, TypeError):
        return None


def grade_field(name, expected, actual):
    if expected is None:
        return actual is None
    if name in AMOUNTS:
        a, e = to_decimal(actual), to_decimal(expected)
        return a is not None and abs(a - e) <= Decimal("0.01")
    return norm_text(actual) == norm_text(expected)


def run(eval_path, out_path):
    results = []
    for line in Path(eval_path).read_text().splitlines():
        case = json.loads(line)
        try:
            output = extract_bill(case["input"])
            schema_ok = isinstance(output, dict) and all(f in output for f in FIELDS)
        except Exception as exc:
            output, schema_ok = {"error": str(exc)}, False

        fields = {
            f: schema_ok and grade_field(f, case["expected"].get(f), output.get(f))
            for f in FIELDS
        }
        results.append({
            "id": case["id"],
            "tags": case.get("tags", []),
            "schema_ok": schema_ok,
            "fields": fields,
            "critical_pass": all(fields[f] for f in CRITICAL),
            "output": output,
        })

    Path(out_path).write_text(json.dumps(results, indent=2))
    return results

Rubrics for free text

Some outputs cannot be matched exactly: a reply to a customer, a summary of a purchase order dispute. For these, write a rubric of yes/no questions:

  • Does the reply mention the correct order number?
  • Does it avoid promising a delivery date that is not in the source data?
  • Is it under the length limit?

Yes/no questions are easier to grade consistently than a score out of ten.

Using an LLM as a grader

An LLM can answer rubric questions, but treat it as another component that needs testing:

  1. Give it one narrow question at a time, not a general "is this good?"
  2. Grade a sample by hand and compare. If the judge and humans disagree often, fix the judge prompt before trusting its scores.
  3. Recheck that agreement whenever you change the judge model or prompt.
  4. Never use the judge as the only gate for critical fields that code can check.

Human review

People still read a sample of outputs every run, plus every case where graders disagree. This is where you find problems nobody wrote a check for yet.

Step 4: Set a baseline and pass criteria

Run the current version against the full set and save the results. Because outputs vary, run it more than once and note which cases pass only some of the time. Those flaky cases are worth investigating on their own.

Then agree on gates before anyone starts changing prompts. For example:

  • Zero schema failures.
  • No case that passed on critical fields in the baseline may fail in the new version.
  • The overall field accuracy must not drop below the baseline by more than a tolerance you choose.
  • Cost per case and response time stay within the limits you set.

The exact numbers depend on your feature and how much a mistake costs. Write them down so a release decision is not a debate.

Step 5: Run regression checks on every change

All of these count as a change and should trigger a full run:

  • Prompt or system prompt text
  • Model, or model version
  • Parameters such as temperature or max tokens
  • Retrieved context, tool definitions or few-shot examples
  • Pre-processing, such as the OCR step that produces the text

The procedure:

  1. Pin the model version. Use the exact version identifier your provider offers instead of a moving alias, so the baseline stays comparable. Your provider's model list shows the exact version names.
  2. Run the full set with the old and new configuration.
  3. Compare per case, not just averages. An average can stay flat while five important cases break and five easy ones get fixed.
  4. Read every newly failing case before deciding.
  5. Check cost and latency alongside accuracy. A new model that is more accurate but much slower may not fit the workflow.
  6. Save the results with the commit, so you can explain later why a version shipped.

A simple comparison script:

Python
import json
import sys


def load(path):
    with open(path) as f:
        return {r["id"]: r for r in json.load(f)}


base, cand = load(sys.argv[1]), load(sys.argv[2])

newly_failing = [i for i, r in base.items()
                 if r["critical_pass"] and not cand.get(i, {}).get("critical_pass")]
newly_passing = [i for i, r in base.items()
                 if not r["critical_pass"] and cand.get(i, {}).get("critical_pass")]
schema_failures = [i for i, r in cand.items() if not r["schema_ok"]]

print(f"Newly failing: {len(newly_failing)} {newly_failing}")
print(f"Newly passing: {len(newly_passing)} {newly_passing}")
print(f"Schema failures: {len(schema_failures)} {schema_failures}")

if newly_failing or schema_failures:
    sys.exit(1)

Run it in CI whenever the prompt or eval files change. A GitHub Actions example:

YAML
name: llm-eval
on:
  pull_request:
    paths:
      - "prompts/**"
      - "eval/**"
      - "my_feature/**"
jobs:
  eval:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.11"
      - run: pip install -r requirements.txt
      - run: python -c "from eval.harness import run; run('eval/bills.jsonl', 'candidate.json')"
        env:
          LLM_API_KEY: ${{ secrets.LLM_API_KEY }}
      - run: python eval/compare.py eval/baseline.json candidate.json

Every run costs model calls, so keep the set small enough to run on each pull request, and set a spending limit on the API key used by CI.

Step 6: Keep the set alive after launch

The evaluation set should grow from production:

  • Use the approval step as a label source. When a person rejects or corrects an AI-generated draft, that case and the corrected values are a ready-made test case.
  • Add new failure types as soon as you see them, with a tag, so the same bug cannot return unnoticed.
  • Keep a held-out portion that you do not look at while tuning prompts. If you only tune against the cases you can see, the prompt slowly fits those cases and the score stops meaning much.
  • Retire nothing silently. If a case is removed because the label was wrong, note why in the commit.

Common mistakes

  • Testing only with inputs the developer wrote.
  • Reporting one average score and never reading individual failures.
  • Switching to a newer model because it is newer, without a full run.
  • Letting an LLM judge grade fields that a few lines of code could check exactly.
  • Treating null and a wrong guess as the same thing. For ERP data, a confident wrong value is the more dangerous one.
  • No record of which prompt, model and dataset version produced which score.

How this fits AI agents inside an ERP

Inside Odoo or ERPNext, an evaluation set is only half of the safety story. The other half is how the feature runs in production: a person approves anything that posts or sends, spending has a ceiling, and every action is logged. Those controls also feed the evaluation loop, since approvals and corrections become new test cases and logs tell you which inputs caused trouble.

If you want to compare models on the same evaluation set inside Odoo, AI Base lets you plug any AI model into Odoo with a hard monthly cap, which keeps evaluation runs and model trials from turning into a surprise bill.

How Kalvyai can help

We build AI agents that work inside Odoo, ERPNext and Shopify with human approvals, budgets and an audit trail, and we set up the evaluation sets and regression checks that go with them. You can read more about that work at kalvyai.com/ai-agents, and browse our ready-made apps at store.kalvyai.com.

If you have an LLM feature you are planning to launch, or one that already behaves differently after a model update, contact us and we can help you build the test set and the checks around it.

Share this article

Last updated 20 Nov 2026

  • LLM evaluation
  • AI agents
  • prompt engineering
  • regression testing
  • ERP AI
  • quality assurance

Kalvyai Engineering · Engineering team

The engineers who build, connect and fix business systems at Kalvyai: Odoo, ERPNext, Shopify and AI agents that work inside them with approvals, budgets and an audit trail.

Comments

No comments yet. Questions and corrections are welcome.

Rate this post or leave a comment

Your rating (optional)
Not rated

Comments appear after an editor approves them. See our privacy notice.

Read next

AI Bank Reconciliation: Suggested Matches a Person Confirms (cover)Technical
Kalvyai EngineeringAI agents

AI Bank Reconciliation: Suggested Matches a Person Confirms

How an AI matcher suggests bank reconciliation matches from descriptions and amounts, explains each one, sorts them by confidence, and leaves the final confirmation to a person.

7 min read

Claude Tool Use for ERP Tasks: Safe Read and Write Actions (cover)Technical
Kalvyai EngineeringAI agents

Claude Tool Use for ERP Tasks: Safe Read and Write Actions

How to give Claude function calling access to your ERP without giving it the keys: narrow tools, argument validation in code, approval gates for writes, and a log entry for every call. Includes a Python example against Odoo.

6 min read

Newsletter

Get new guides in your inbox.

Practical notes on Odoo, ERPNext, Shopify and AI agents, written by the engineers who build them. No spam, and you can ask to stop at any time.

Prefer a feed? Subscribe by RSS. We use your email only to send new articles. See our privacy policy.