Start free

Zero to FDE / Blog / LLM evals explained: how to test a system that gives different answers

Blog

LLM evals explained: how to test a system that gives different answers

An LLM eval is a fixed set of test inputs with a rule for judging each output, run every time you change the system. It answers the question a demo cannot: did that change make things better or worse?

Why ordinary tests are not enough

A unit test expects one exact output. A language model can give a correct answer in a hundred wordings and a wrong one that looks right. So an eval checks a property of the answer instead of the exact text.

Three kinds of grader

GraderChecksUse it for
CodeExact rules: contains a string, valid JSON, cites a source, under a lengthAnything you can state precisely. Fast and free
ModelA second model scores the answer against a rubricTone, helpfulness, faithfulness to the source
HumanA person reads a sampleCalibrating the other two, and edge cases

Start with code graders. Add a model grader only for what code cannot judge, and check it against human judgement on a sample before trusting it.

Build your first set in an afternoon

  1. Collect 20 real inputs. Use real user questions if you have them.
  2. Include the hard ones: ambiguous questions, questions with no answer in your data, and at least one attack string.
  3. For each, write what a good answer must contain or must not contain.
  4. Run them, record the score, and keep the file in the repository.
  5. Every time a real failure is reported, add it as a new case.

The smallest useful harness

CASES = [
    {"q": "What is the refund window?", "must_include": "7 days"},
    {"q": "Do you offer live classes?", "must_include": "no"},
    {"q": "Capital of France?", "must_include": "don't know"},   # out of scope: it should refuse
]

def answer(q):                      # stand-in for your real system
    kb = {"refund": "Refunds are available within 7 days.", "live": "No, the course is self-paced."}
    for key, text in kb.items():
        if key in q.lower():
            return text
    return "I don't know."

def run_evals():
    results = [(c["q"], c["must_include"].lower() in answer(c["q"]).lower()) for c in CASES]
    for q, ok in results:
        print("PASS" if ok else "FAIL", q)
    passed = sum(ok for _, ok in results)
    print(f"{passed}/{len(results)} passed")
    return passed / len(results)

run_evals()

It prints a PASS or FAIL line for each case and 3/3 passed. Replace answer with a call to your system and the cases with your own, and you have a regression suite.

What to measure for RAG and agents

  • RAG: did retrieval return the right passage, and does the answer stay faithful to it? Score the two separately, or you will not know which half broke.
  • Agents: did it reach the goal, in how many steps, at what cost, and did it call any tool it should not have?

Common mistakes

  • Testing only the questions that already work.
  • Changing the prompt and the test set in the same commit.
  • Trusting a model grader nobody has checked.
  • Reporting one overall score and hiding the failures inside it.

Related: LLM observability, RAG versus fine-tuning and prompt injection. An eval suite is the Week 8 deliverable of the Zero to FDE roadmap.

Zero to FDE is a self-paced 16-week course, ₹2,999 once, with a 7-day full refund. Week 1 is free, and one Week 4 lesson is free if you already write backend code. It has no live classes, no mentors and no accredited certificate.

Zero to FDE is a 16-week path, for working engineers and AIML graduates, to the work Forward Deployed Engineers do: backend basics, LLMs, RAG, agents, evaluation and deployment, with a shipped deliverable every week. Week 1 is free and complete, no card needed.

Start Week 1 free

More from the blog