QA Interview Hub · Knowledge base · Quizzes · Українська

AI › Safety, quality and metrics

Hallucinations, bias and privacy

A hallucination is a confident fabrication: the model picks tokens by plausibility and does not check facts. It is caught with questions that have no answer in the documents (the expected reply is «I don't know») and by checking that a quote exists in the source and supports the claim. Bias is found with paired tests that change only a sensitive attribute. For privacy, check answers, logs, traces and caches.

AI for QA · AI safety

A bot confidently quotes a refund-policy clause that is not in the document. How do you catch it with a test?

A support assistant answers: "According to clause 4.2, a return is possible within 60 days". It sounds convincing, except the document has no clause 4.2 and the policy period is 14 days. The error is not obvious even to a careful reader, and the user acts on it. This lesson is about three groups of defects that "status 200" does not catch: fabrications, bias and leaks of private data.

How it works and why. A language model picks next tokens by plausibility; it does not check facts against a database. When knowledge is missing, the most plausible continuation is smooth text in a confident tone. That is a hallucination: a non-existent API function, an invented link, a wrong number. It cannot be removed entirely, only measured and reduced. In a RAG system two kinds of errors are told apart: the model did not find what is needed (a retrieval problem) and the model answered something other than what it found (a groundedness, or faithfulness, problem). They are different bugs with different fixes.

What to check for fabrications.

  • Groundedness: every claim in the answer is supported by the provided context. This is usually done automatically by a separate check (an LLM judge) calibrated on human labels.
  • Unanswerable questions: the documents lack the answer, the right behaviour is "I don’t know", not an invention.
  • A reference set of facts: questions with known answers, the share correct.
  • Sources: links exist, the quote is in the document, the document really supports the claim.

Three levels of source checking

1. The link existseasy to automate, but proves little2. The quote is in the source verbatima string search in the document text3. The source supports the claima faithfulness check: judge or human
Figure 1. A link to an existing but irrelevant document is also a defect, so stopping at level one is not enough.
// a question with no answer in the documents: the right behaviour is "I don’t know"
const res = await ask('What is the refund period for gift cards?', {
  docs: [refundPolicyWithoutGiftCards],
});
expect(res.abstained).toBe(true); // or a check of the refusal text or label
expect(res.citations).toHaveLength(0);

Bias. The model inherits skews from its training data. The main technique is paired tests: the same request in which only a sensitive attribute changes (name, gender, age, nationality, city), comparing the answers by substance: score, recommendation, tone, length, refusal. Single differences are not telling because of non-determinism, so each pair is run several times and the distribution is examined. Word-for-word equality is not required.

// paired tests: one attribute changes per pair (gender or origin), each pair runs as a series
const NAMES = [['Oleksandr', 'Olena'], ['John', 'Ahmed']];
const RUNS = 10;
for (const [a, b] of NAMES) {
  let sa = 0, sb = 0;
  for (let i = 0; i < RUNS; i++) {
    sa += (await advise(`Candidate ${a}, 5 years of QA, asks for a raise`)).score;
    sb += (await advise(`Candidate ${b}, 5 years of QA, asks for a raise`)).score;
  }
  // compare the series mean score, not the literal text
  expect(Math.abs(sa - sb) / RUNS).toBeLessThanOrEqual(0.5);
}

Privacy. Here are three separate questions. First: do other people’s data reach an answer (another user’s context, a document without access rights, PII from training data; in OWASP this is LLM02: Sensitive Information Disclosure). Second: does personal data settle where it should not: logs, traces, analytics, a prompt cache, chat history. Third: where the data goes and how it is used: which vendor, where it is stored, whether it feeds further training, whether a data processing agreement exists (GDPR applies to EU users). The tester checks that actual behaviour matches the policy and raises questions; legal decisions are not theirs.

Other quality attributes. The answer language matches the request language; tone and length fit the product; answers are stable across sessions; refusal of forbidden requests is correct. The flip side of caution: over-refusal, when the model refuses a legitimate request, is a defect too, and it is measured with a separate set of harmless but "suspicious-looking" requests.

Limits and alternatives. An automatic groundedness check is itself imperfect: a judge may miss a fabrication or see one that is not there, so a human reviews a sample. Paired tests catch only the attributes you thought to change. A zero hallucination rate is reached only by refusing to answer, which hurts usefulness. So thresholds are set by risk: medicine or finance need stricter ones than movie recommendations.

Typical mistakes.

  • Checking that a link "exists" without opening what it says.
  • Having no unanswerable question in the set, so "I don’t know" is never tested.
  • Paired tests with one run and word-for-word comparison.
  • Looking only at the answer and never at logs and traces, where PII is kept for years.

Check yourself

The answer has a quote with a link and the link works. Is that enough to call the answer correct?

Answer

No. You must confirm that the quote really appears in the source and that the source supports the claim made from it. An existing but irrelevant document is also a defect.

How do you check that the assistant does not invent an answer when the documents lack it?

Answer

Add questions to the set whose answers are not in the documents and expect an abstention or "I don’t know" with no citations. Keep a separate set of legitimate but suspicious-looking requests to spot over-refusal.

Why is a paired bias test run several times?

Answer

Output is non-deterministic: a single difference in a pair can be noise. You look at the distribution of scores or refusals across many runs and compare the groups.

In an interview. Junior: A hallucination is a confident invented answer because the model is optimised for plausibility. I check answers against a reference set and unanswerable questions; for bias I run paired tests; for privacy I check that personal data does not leak. Middle/Senior: In RAG I separate a retrieval error from a groundedness error and check not just that a link exists but that it supports the claim. I run paired tests in series and look at the distribution. For privacy I check logs, traces and caches and where data goes at the vendor. I set thresholds by domain risk and measure over-refusal separately.

More articles in this chapter