QA AND TEST AUTOMATION · PART 10 · TESTING AI FEATURES · BASICS · 88 OF 112

Why AI Features Are Hard to Test, and What Works

Why a chatbot breaks the usual expected-equals-actual test, shown with ShopRung's support chat on a real local model: three different answers to one question, an occasional invented answer, and the parts that stay deterministic. How testers split an AI feature into testable layers, check properties instead of exact text, repeat runs and measure pass rates.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 67
  63. 68
  64. 69
  65. 70
  66. 71
  67. 72
  68. 73
  69. 74
  70. 75
  71. 76
  72. 77
  73. 78
  74. 79
  75. 80
  76. 81
  77. 82
  78. 83
  79. 84
  80. 85
  81. 86
  82. 87
  83. 88
  84. 89
  85. 90
  86. 91
  87. 92
  88. 93
  89. 94
  90. 95
  91. 96
  92. 97
  93. 98
  94. 99
  95. 100
  96. 101
  97. 102
  98. 103
  99. 104
  100. 105
  101. 106
  102. 107
  103. 108
  104. 109
  105. 110
  106. 111
  107. 112
1 / 11

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • Different answers
  • sometimes wrong
  • deterministic layers
  • fake model
  • property checks
  • pass rates

Notes

Same question

We asked ShopRung's chat, running on the local model llama three point two with three billion parameters, how much shipping costs, three times. Three different wordings came back. All three were right: four ninety nine, free from seventy five dollars. An assert equals on the text would fail on the second run. Yet the answers are fine.

"How much is shipping?"
1: Shipping costs $4.99 per order if
   your subtotal ... is less than $75.00,
   but it's free when your total is
   $75.00 or more.
2: Shipping costs $4.99 ... If you have
   a coupon that brings your subtotal
   above $75.00, ...
3: Shipping costs are $4.99 per order
   unless your subtotal after any
   discount is $75.00 or more, in which
   case it's free.

Sometimes wrong

Worse, the same question can be answered well twice and badly once. Asked whether a shipped order can be cancelled, two runs gave the correct rule from the help page. The first said it did not know, and suggested calling a customer service team that does not exist. One run of a test would have passed or failed by luck.

"Cancel a shipped order?"
2, 3: No, a SHIPPED or DELIVERED order
      can no longer be cancelled. ✓

1:    I don't know how to cancel a
      shipment. You can try emailing
      support@shoprung.test ... or call
      our customer service team. ✗

there is no phone team: invented

Why

Why? A language model writes one piece of a word at a time, choosing from a probability list. With a temperature above zero, ShopRung uses zero point seven, it samples, so less likely words sometimes win. The answer also depends on its context: which help pages were retrieved, the conversation so far, the exact wording. New model versions answer differently. Even temperature zero can drift on different hardware.

Sources of variation
  • sampling: each next word is drawn from probabilities (temperature 0.7 here)
  • context: retrieved pages, history, wording of the question
  • model updates: new versions answer differently
  • hardware and batching: even temperature 0 can drift

Not all of it varies

The good news: most of an AI feature is ordinary code. ShopRung's retrieval picks the same help sections for the same question every time. An off topic question, like the capital of France, got the same refusal three times out of three, with zero tokens in about a millisecond, because code refuses it before any model call. The order tool refused Bob access to Alice's order every time. Test these layers with normal unit and API tests.

Deterministic: test classically
retrieval: same sections for the
  same question, every run
out of scope: "capital of France"
  3/3 identical refusal, 0 tokens,
  about 1 ms, no model call
order tool: Bob asking for
  Alice's order: refused 3/3
guardrails: rules in code

A fake model

To test the plumbing, swap the model. ShopRung starts with a built in fake model by default, which gives the same answer every time and needs no setup. Your API tests can then check status codes, the response shape, sources, refusals and guardrails exactly, in CI, in milliseconds. The real model, through Ollama, is for evals: the tests about answer quality.

SHOPRUNG_CHAT_MODEL
fake (default):
  same answer every run
  no setup, CI-friendly
llama3.2:3b via Ollama:
  real answers, real variation

API tests use the fake;
evals use the real model

Check properties

For the answers themselves, check properties instead of exact text. The shipping answer must contain four ninety nine and seventy five dollars, and must not contain a made up coupon. The sources must include the shipping page. Answers stay short, with no leaked markup. We wrote checks like these for twelve questions and ran each three times: thirty two of thirty six answers passed, eighty nine percent.

Property checks
must contain: "$4.99", "$75.00"
must not contain: "FREE100",
  "90 days", "Paris"
sources include: shipping
length: under 3 sentences
format: no raw <help> tags

real run: 32 of 36 answers
  passed these checks (89%)

Repeat and measure

Because one run proves little, repeat. Run each question several times and report a pass rate, per question and overall. Set thresholds: maybe ninety percent overall, but one hundred percent for safety checks, such as never inventing a coupon. Then compare every change, a new prompt or a new model, against the last run. The next episodes build exactly this.

From one run to many
  • run each question N times
  • report a pass RATE per question and overall
  • set a threshold: e.g. ≥ 90% overall, 100% for safety checks (no fake coupons)
  • compare with the last run before shipping a change

Common mistakes

Mistakes. Asserting the exact answer text. Running a question once and calling it done. Testing everything through the real model, which is slow and flaky, when most layers are deterministic. Forgetting retrieval, tools and guardrails, which cause many real failures. And having no fixed set of questions, so nobody can tell whether a change made things better or worse.

Avoid these
  • assert answer == "..."
  • one run, then "it works"
  • testing only through the real model (slow, flaky)
  • no tests for retrieval, tools and guardrails
  • no fixed question set to compare versions

Say it like this

In the interview: I split the feature into layers. Retrieval, tools, guardrails and refusals are code, tested with unit and API tests, using a fake model in CI. Answer quality gets evals: a fixed set of questions, property checks such as must contain and must not contain, several runs per question, and pass rates with thresholds, compared from one version to the next.

In the interview
  • "I split it into layers.
  • Retrieval, tools, guardrails and refusals are code: unit and API
  • tests, with a fake model in CI.
  • Answer quality gets evals: a fixed question set, property
  • checks (must contain, must not), several runs per question, pass
  • rates with thresholds, compared
  • version to version."

Interview questions

Q1Why can you not assert the exact answer of an LLM feature?

The model samples words from probabilities, so the same question gives different wordings, and sometimes different facts, on every run.

Q2Which parts of an AI feature are deterministic?

Usually retrieval, routing, tool code and its access control, input and output guardrails, refusals and response formatting. Test them with normal unit and API tests.

Q3What is a fake model for?

A stand-in that gives the same answer every time, so API and integration tests can check the plumbing quickly and reliably in CI.

Q4What is a property check?

An assertion about what must or must not be true of an answer (contains a fact, no invented codes, cites a source, short, no markup) instead of the exact text.

Q5Why run each question several times?

One run can pass or fail by chance; repeated runs give a pass rate you can compare and set thresholds on.

Q6What does temperature do?

It controls how much the model samples less likely words: higher means more variety, lower means more repeatable, though even 0 can drift.

Q7Give a real example of an LLM failure from ShopRung's chat.

Asked whether a shipped order can be cancelled, it answered correctly twice but once suggested calling a customer service team that does not exist.

Q8What thresholds would you set?

A high overall pass rate (e.g. 90%) and 100% on safety checks such as never inventing coupons or leaking data, compared against the previous version.