FailLoud Playground / Guides

My chatbot cites sources that don't exist. How can I detect hallucinated citations automatically?

Short answer

Resolve every citation against the retrieval set, in code. A citation — a citations entry or an inline marker like [9] — that points at nothing retrieved is fabricated, however confident it looks. FailLoud FL006 unsupported_answer does exactly this and names each fabricated citation with its JSON path. It is a deterministic guardrail: no second model grading the first.

Why chatbots fabricate citations

A language model generates the shape of a citation the same way it generates any other text — plausibly. If the prompt rewards citing, it will cite, whether or not retrieval returned anything with that name. The citation looks like evidence and behaves like evidence in every downstream system that doesn't check it. Checking it is cheap: the retrieval set is a list, and membership in a list is not a judgement call.

The technique

  1. Collect the identifiers the answer cites — the citations array and inline markers ([2], [doc_a]).
  2. Collect the identifiers retrieval actually returned.
  3. Fail every cited identifier with no match. Then check the matched sources carry text — a citation to an empty source backs nothing.
  4. Extend the same suspicion to figures: every number in the answer must appear in the cited sources.

The worked example

$ failloud check examples/rag_failing.json --only FL006
  ✗ $.citations — Citation 'refund_policy' does not resolve to any retrieved source.
  ✗ $.answer — Citation [9] does not resolve to any retrieved source.
Verdict: FAIL (4 error(s), 0 warning(s)) — exit code 1

FailLoud runs this as part of the standard six-check pass (failloud check answer.json), in Python via run_single(doc, "FL006"), and over MCP as the check_groundedness tool — so the citation gate can sit in CI, in the request path, or inside an agent loop.

What this does not catch

A citation to a real source that doesn't support the sentence is a misreading, not a fabrication — catching it needs a judge (human or model). Fabrication is the deterministic layer, and it is the layer that embarrasses: the source never existed at all.