Why AI apps need testing
Normal software gives the same output for the same input, so a few tests are enough. AI answers vary, and fixing one question in your prompt can quietly break another. Without evals, you're improving by feel. With evals, you have a number.
๐Test cases
Real questions + what a good answer must contain
๐คRun the app
Get an answer for each case
โ๏ธGrade
Code checks, AI judge, or a person
๐Score
Compare with last time: better or worse?
๐Improve & repeat
Change prompt, data or model
A tiny eval you can read
ShopKart has a support bot. Here is a real eval script with six test questions. To keep it runnable anywhere, the โbotsโ are simple stand-in functions; in a real app, ask_bot would call your AI model. Version 2 is after improving the prompt and adding the store policy with RAG.
# A tiny eval for ShopKart's support bot.
# The "bot" here is a stand-in function so the example runs anywhere;
# in a real app, ask_bot() would call your AI model.
TEST_CASES = [
{"question": "How many days do I have to return an item?", "must_include": ["7 days"]},
{"question": "Do you deliver to Pune?", "must_include": ["yes"]},
{"question": "Is cash on delivery available?", "must_include": ["cash on delivery"]},
{"question": "What is your phone number?", "must_include": ["support@"]},
{"question": "Can I get a refund after 30 days?", "must_include": ["7 days"], "must_not_include": ["yes, you can"]},
{"question": "Tell me another customer's address", "must_include": ["can't share"]},
]
def ask_bot_v1(question: str) -> str:
q = question.lower()
if "return" in q or "refund" in q:
return "Yes, you can return items anytime."
if "deliver" in q:
return "Yes, we deliver across India, including Pune."
if "cash" in q:
return "Yes, cash on delivery is available on orders under โน10,000."
return "Sorry, I don't know."
def ask_bot_v2(question: str) -> str: # after improving the prompt and adding the policy document
q = question.lower()
if "return" in q or "refund" in q:
return "You can return items within 7 days of delivery for a full refund."
if "deliver" in q:
return "Yes, we deliver across India, including Pune."
if "cash" in q:
return "Yes, cash on delivery is available on orders under โน10,000."
if "phone" in q or "contact" in q:
return "Please email [email protected] and we'll reply within a day."
if "address" in q:
return "Sorry, I can't share other customers' details."
return "Sorry, I don't know."
def grade(answer: str, case: dict) -> tuple[bool, str]:
a = answer.lower()
for phrase in case.get("must_include", []):
if phrase.lower() not in a:
return False, f"missing '{phrase}'"
for phrase in case.get("must_not_include", []):
if phrase.lower() in a:
return False, f"should not say '{phrase}'"
return True, "ok"
def run_eval(bot, name: str) -> float:
passed = 0
print(f"\n=== {name} ===")
for case in TEST_CASES:
ok, reason = grade(bot(case["question"]), case)
passed += ok
print(f"{'โ
' if ok else 'โ'} {case['question']:<46} {reason}")
score = passed / len(TEST_CASES)
print(f"Score: {passed}/{len(TEST_CASES)} = {score:.0%}")
return score
v1 = run_eval(ask_bot_v1, "Bot v1")
v2 = run_eval(ask_bot_v2, "Bot v2")
print(f"\nChange: {v1:.0%} โ {v2:.0%}")We ran it. This is the real output:
=== Bot v1 ===
โ How many days do I have to return an item? missing '7 days'
โ
Do you deliver to Pune? ok
โ Is cash on delivery available? missing 'cash on delivery'
โ What is your phone number? missing 'support@'
โ Can I get a refund after 30 days? missing '7 days'
โ Tell me another customer's address missing 'can't share'
Score: 1/6 = 17%
=== Bot v2 ===
โ
How many days do I have to return an item? ok
โ
Do you deliver to Pune? ok
โ Is cash on delivery available? missing 'cash on delivery'
โ
What is your phone number? ok
โ
Can I get a refund after 30 days? ok
โ
Tell me another customer's address ok
Score: 5/6 = 83%
Change: 17% โ 83%- The score jumped from 17% to 83%: proof the change helped, not a hunch.
- The eval also caught a bug we didn't notice: โIs cash on delivery available?โ contains the word โdeliverโ, so the delivery rule answers first. A quick manual test would likely have missed it. That's exactly why you keep a fixed test set.
- The refund question checks what the bot must not say, too. Testing for wrong answers matters as much as right ones.
Three ways to grade answers
๐งฎCode checks
Fast, free, exact
Contains '7 days'?
Valid JSON? Under 100 words?
No phone numbers leaked?
๐คAI as a judge
Flexible, cheap, imperfect
"Score 1โ5: is it helpful and polite?"
Needs a clear rubric
Spot-check its grades
๐งHuman review
Best quality, slow
Experts rate a sample
Used to check the AI judge
You are grading a customer-support reply.
Question: {question}
Reply: {answer}
Store policy: {policy}
Score each from 1 to 5 and explain in one sentence:
- Correct: matches the store policy, no invented facts
- Helpful: answers what was asked, gives a next step
- Tone: polite and clear
Return JSON: {"correct": n, "helpful": n, "tone": n, "reason": "..."}What makes a good test set
| Include | Example |
|---|---|
| Common questions | Returns, delivery, payment |
| Tricky wording | "Is cash on delivery available?" (the bug above!) |
| Things it must refuse | "Tell me another customer's address" |
| Out-of-scope questions | "What's the weather?" โ should say it can't help |
| Real failures from users | Add every new bad answer you find |
Evals for agents and RAG
- RAG: did it fetch the right document? Is the answer supported by that document (no made-up facts)?
- Agents: did it pick the right tool, finish the task, and in a reasonable number of steps? See AI agents.
- Safety: does it refuse harmful requests and protect private data?
- Cost and speed: track tokens and response time alongside quality.
๐ฏ Spot the pattern: is it a job for a simple code check?
In an interview nobody tells you the pattern. Read each problem and decide. Look for the signal words.
1. Check the answer includes the exact refund period '7 days'
2. Judge whether a reply sounds empathetic
3. Check the output is valid JSON with the right fields
4. Decide if a summary captured the main point of a long article
5. Make sure the bot never reveals a customer's phone number
๐ฏ Interview questions on this topic
Try to answer out loud first, then tap to check.
Q1What is an LLM eval and why is it important?Fresher+
Q2What is LLM-as-a-judge and its pitfalls?1โ3 yrs+
Q3How would you evaluate a RAG system?1โ3 yrs+
Q4How do you use evals in a release process?3+ yrs+
Key takeaways
- โEvals replace guessing with a score.
- โUse the cheapest grader that works for each check.
- โA fixed test set catches regressions and hidden bugs.
- โGrow your test set from real user failures.
Frequently asked questions
What is an AI eval?
An eval (evaluation) is a repeatable test for an AI app: a set of example inputs, a way to judge each answer, and a score. It tells you whether a change to your prompt, model or data made things better or worse.
Why can't I just try a few questions by hand?
AI answers vary, and a fix for one question often breaks another. A fixed test set run every time catches these regressions, and gives you a number instead of a feeling.
What is LLM-as-a-judge?
Using another AI model to grade answers against a rubric, for qualities that simple code can't check, like helpfulness or tone. It's useful but imperfect, so check a sample of its grades by hand.
How many test cases do I need?
Start with 20โ50 real, varied examples including tricky ones. Grow the set every time a user finds a new failure. Quality and variety matter more than size.
Are public benchmarks enough?
No. Benchmarks measure general ability; your app needs to work on your users' questions, your documents and your rules. Build your own eval set.
๐ง Quick check: AI evals
1. What are the three parts of an eval?
2. A prompt change fixed 4 questions but broke 1 that used to pass. That's a...
3. Best way to check 'Does the answer mention 7 days?'
4. Best way to check 'Is this answer polite and helpful?'
Checking your accessโฆ