Skip to content
CodeKruPro

When the answer is not in the documents

59/99

Module · Testing RAG and hallucination

intermediate

about 35 min

What this lesson teaches

The idea

A RAG bot should say it could not find an answer when no document covers the question.

Why a tester cares

A bot pushed too hard toward refusing starts refusing questions it can answer. Test both together: questions it must answer, and questions it must decline.

Words you will meet

Abstention:
the bot saying it does not know.
False refusal:
declining a question the documents do answer.

What you will do

  1. 1Test the answerable set
  2. 2Test the unanswerable set
  3. 3Submit
Jump to practice

A RAG bot should say "I couldn't find that" when the documents do not cover a question. Teams test this, see the refusals, and stop. But a bot tuned too hard toward refusing starts refusing questions it can answer, and users find that just as useless.

Abstention and false refusal are one behaviour seen from two sides, so test them together, with a balanced set: answerable questions that must be answered, and unanswerable ones that must be refused.

Your task

Write both tests. On submit they run against a correct PolicyPal, one that invents answers, and one that refuses too often.

Sign in to practise

The lesson is free to read. A free account lets you talk to the practice bots, run your code and save your score. You will come back to this lesson.

PolicyPal APIShow
PolicyPal's API, at the address in CK_APP_URL:
  POST /policy/ask {"question": "...", "department": "sales"} -> {"answer", "citations": [ids], "retrieved", "trace_id"}
  GET  /policy/docs/<id> -> the document ({"id", "title", "text"}), 404 if it does not exist
  GET  /policy/search?q=...&k=3 -> ranked documents
1

Your code

Write it in
Both are graded the same way.
against PolicyPal

How this is checked: When you submit, your tests run against 4 versions of PolicyPal: 2 correct and 2 with a planted fault. Good tests pass on every correct version and fail on every faulty one. Run tries them on the practice copy first; the result table shows each version.

Core checks earn 50 points and the harder checks the other 50. You can submit as many times as you like.

About this lesson

Test RAG chatbot abstention and false refusals together with a balanced question set

AI Testing for QA EngineersIntermediateTesting RAG and hallucination

How it works

A RAG bot should say it could not find an answer when the documents do not cover a question. Teams test that, see the refusals, and stop. But a bot tuned too hard toward refusing starts refusing questions it can answer, and users find that just as useless.

Abstention and false refusal are one behaviour seen from two sides, so test them together with a balanced set: answerable questions that must be answered, and unanswerable ones that must be refused.

About the assignment

Write tests for answerable and unanswerable questions that pass on a correct PolicyPal and fail on builds that invent answers or refuse too often.

What you will do

  1. List answerable questions with the document that covers each.
  2. List questions no document covers.
  3. Assert answers for the first group, with a citation, and refusals for the second.

Common mistakes

  • Unanswerable questions only

    A bot that refuses everything passes that suite.

  • Accepting any non-refusal as an answer

    An invented answer is not a refusal either. Check for a citation.

In a real test suite

Teams track refusal rates on answerable questions as a product metric, because over-refusal often appears after a safety change and is easy to miss.

Choose the unanswerable questions carefully. They should sound like real questions from the same users, not obvious nonsense, because a bot that refuses odd-sounding questions but invents answers for plausible ones is the dangerous case.

Keep the two halves of the set the same size, or report their pass rates separately. A large unanswerable half can make a bot that refuses everything look acceptable on a single combined number.