Our AI Support Bot Invented a Refund Policy: How We Cut RAG Hallucinations From 18% to 3% in Production (Real Code)
AI in Production: War Stories, Scenario #1. One real production incident: the alert, the triage (dead ends included), the root cause, the fix with runnable code, the measured result — and how to tell it in a senior interview. This is the hallucination incident. Full original (canonical) on PrepStac

Posted on Nov 27 • Originally published at prepstack.co.in
AI in Production: War Stories, Scenario #1. One real production incident: the alert, the triage (dead ends included), the root cause, the fix with runnable code, the measured result — and how to tell it in a senior interview. This is the hallucination incident.
Full original (canonical) on PrepStack: https://prepstack.co.in/blog/ai-production-scenario-1-rag-hallucinations
Our RAG-powered support bot answers ~520 tickets/month against a knowledge base of product docs, billing policies, and runbooks. Three weeks after launch, a CSM forwarded a screenshot: "did we change the refund policy??"
"You are eligible for a full refund within 60 days of purchase, no questions asked."
Our actual policy was 14 days, conditional. There was no 60-day policy anywhere in the knowledge base — not a draft, not an old version. The model invented it, fluently and confidently.
We hand-labeled 200 recent answers with the support team. 18% contained at least one claim not supported by the retrieved documents. An airline famously lost a tribunal case because its chatbot invented a bereavement-fare policy and the court held the company to it. A hallucinating support bot is not a quality problem; it is a contract-writing machine.
question -> embed -> vector search (k=8, NO score floor [F1], NO freshness filter [F2]) -> PROMPT: "answer using the context" (no "I don't know", no citations [F3]) -> LLM answer -> user (NO verification [F4]) Enter fullscreen mode Exit fullscreen mode The refund question hit all four: it asked about annual plans, our docs only covered monthly, retrieval returned 8 weakly-related chunks [F1], one a deprecated 2023 promo doc [F2], the prompt demanded an answer [F3], and nothing stood between the model's guess and the customer [F4].
Root cause: the pipeline had no concept of "not enough evidence." Every question got k chunks and every set of k chunks got a confident answer. Hallucination wasn't a model defect — it was the designed behavior of a pipeline with no abstention path.
# broken_rag.py - reproduces the failure. Do NOT ship this. import anthropic client = anthropic. Anthropic ( ) DOCS = [ "Refunds: monthly plans may be refunded within 14 days of purchase " "if usage is below 1,000 API calls.", "Billing cycles run from the 1st of each month.", ] def answer ( question: str ) -> str: context = "\n\n". join ( DOCS ) # [F1] no relevance check response = client. messages. create ( model = "claude-sonnet-5-5", max_tokens = 1024, system = "Answer the user's question using the context below.\n\n" + context, # [F3] messages = [ { "role": "user", "content": question } ], ) return next ( b. text for b in response. content if b. type == "text" ) # [F4] straight to user print ( answer ( "What is the refund policy for annual plans?" ) ) # Typical output: a fluent, invented policy for annual plans - the docs only cover monthly.
Enter fullscreen mode Exit fullscreen mode The fix — five layers, each catching what the last misses Principle: every claim must be traceable to a retrieved source, and "I don't know" must be a first-class answer.
# Layer 1 + 2: retrieval gate (relevance floor + freshness filter) def gate_retrieval ( chunks: list [ Chunk ] ) -> list [ Chunk ]: fresh = [ c for c in chunks if not c. superseded ] # layer 2 strong = [ c for c in fresh if c. score >= MIN_RELEVANCE ] # layer 1 (e.g. 0.72) return strong # an EMPTY result is VALID -> routes to abstention, not generation Enter fullscreen mode Exit fullscreen mode # Layer 3: citation-forced generation with an explicit out class Citation ( BaseModel ): doc_id: str quote: str # verbatim sentence from the source supporting the claim class GroundedAnswer ( BaseModel ): can_answer: bool # False when the context does not contain the answer answer: str citations: list [ Citation ] SYSTEM = """Use ONLY the provided context. Every factual claim must carry a verbatim citation. If the context does not contain the answer, set can_answer=false - that is a GOOD outcome.
Do not generalize from a similar-but-different case (e.g. monthly vs annual).""" Enter fullscreen mode Exit fullscreen mode # Layer 4: faithfulness judge - a SEPARATE, cheap model that never sees the question, # so it can't be charmed into agreeing the answer is "helpful" - only that it's SUPPORTED. def judge_faithfulness ( answer, chunks ) -> float: #... returns supported_claims / total_claims via a small model (Haiku-class)...... Enter fullscreen mode Exit fullscreen mode # Layer 5: the pipeline, with abstention as a first-class path def answer_question ( question, retrieved ) -> str: chunks = gate_retrieval ( retrieved ) if not chunks: return ABSTAIN # escalate to a human ticket result = generate ( question, chunks ) if not result. can_answer: return ABSTAIN source_text = " ". join ( c. text for c in chunks ) for cit in result. citations: # deterministic, no LLM if cit. quote not in source_text: return ABSTAIN # fabricated citation -> abstain if judge_faithfulness ( result, chunks ) < MIN_FAITHFULNESS: return ABSTAIN return result. answer Enter fullscreen mode Exit fullscreen mode Four things matter more than any prompt wording:
A fix that handles only one of these will look done and still burn you.
We clawed the judge's latency back three ways: model tiering (judge on a 20x-cheaper small model; verification is narrower than generation), running the judge on the stream while the UI shows "checking sources" (~300 ms perceived, not 600), and prompt caching on the byte-stable system prompt + context (repeat-turn input cost −85%). Net: roughly cost-neutral per query, p95 +under 300 ms.
The 9% abstention is the number stakeholders questioned — "the bot refuses one in eleven?" Yes. Before, those eleven got confident answers and two were wrong in ways a human had to clean up. An honest escalation beats a confident lie on every support metric we track, including CSAT. The remaining 3% is dominated by near-miss generalization — the hardest class. Zero isn't the target; zero undetected is.
STAR, 60 seconds: "Our RAG bot was inventing policies — 18% unsupported claims, including a refund policy that didn't exist. Instead of swapping models, I rebuilt the pipeline around evidence: a retrieval gate with a relevance floor + freshness filter, citation-forced generation with an abstention path, a deterministic verbatim-quote check, and a cheap second-model faithfulness judge gating every answer. 18% → 3%, faithfulness 0.96, policy incidents to zero, and the 9% we escalate became our KB roadmap."
Follow-ups you'll get: why not a better model? (tried; 18%→16% — it's a pipeline problem). Who judges the judge? (a 150-pair golden set; 95% agreement with humans before any threshold ships). How'd you pick 0.72 / 0.85? (from labeled data, not vibes). What does it cost? (have the table). What still gets through? (near-miss generalization, ~3% — name your residual).