Testing AI Features: Evals, RAG & Hallucinations · Lesson 1 of 6 · Bonus module

You Can't assertEqual an LLM

The same prompt returns different words every run. Every test you've ever written assumed a fixed expected value. That assumption is gone — and what replaces it is the whole skill.

By Shahriyar · Updated

Test the property, not the string

You can't assert the output equals a golden sentence. You can assert properties of it: does it cite a source, is it under 200 words, does it refuse the off-topic question, does it contain the account number from the context. Each property is a check that survives the wording changing.

▸ The shift, in one comparison
# impossible — the model never says it the same way twice
assert answer == "Your balance is $412."

# testable — properties that hold however it's phrased
assert "412" in answer                    # the fact is present
assert len(answer.split()) < 60            # it stayed concise
assert judge(answer, "states the balance") # a rubric check

The three ways to score

Grounded in published practice on LLM evaluation and non-deterministic testing

All lessons in Testing AI Features: Evals, RAG & Hallucinations

  1. You Can't assertEqual an LLM
  2. Golden Sets and Offline Evals
  3. Testing RAG: Retrieval vs Generation
  4. Measuring Hallucination
  5. Adversarial Testing: Jailbreaks and Injection
  6. Guardrails, CI, and the Interview Answer