{"slug": "our-ai-support-bot-invented-a-refund-policy-how-we-cut-rag-hallucinations-from-3", "title": "Our AI Support Bot Invented a Refund Policy: How We Cut RAG Hallucinations From 18% to 3% in Production (Real Code)", "summary": "A support team cut hallucinated claims in its RAG-powered support bot from 18% to 3% by adding a retrieval gate with a relevance score floor and freshness filter, citation-forced generation with an explicit abstention path, and a verification layer between the model and the customer. The bot, answering roughly 520 tickets a month, had invented a 60-day no-questions-asked refund policy that did not exist in the knowledge base; hand-labeling 200 answers showed 18% contained at least one claim unsupported by retrieved documents. The team traced the failure to a pipeline with no concept of insufficient evidence, where every question got k chunks and every set of chunks got a confident answer.", "body_md": "**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.\n\nFull original (canonical) on PrepStack: [https://prepstack.co.in/blog/ai-production-scenario-1-rag-hallucinations](https://prepstack.co.in/blog/ai-production-scenario-1-rag-hallucinations)\n\nOur 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??\"\n\nThe bot had told a customer:\n\n\"You are eligible for a full refund within 60 days of purchase, no questions asked.\"\n\nOur 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.\n\nWe 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.**\n\n``` php\n  question -> embed -> vector search (k=8, NO score floor [F1], NO freshness filter [F2])\n          -> PROMPT: \"answer using the context\" (no \"I don't know\", no citations [F3])\n          -> LLM answer -> user   (NO verification [F4])\n```\n\nThe 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].\n\n**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.\n\n``` python\n# broken_rag.py - reproduces the failure. Do NOT ship this.\nimport anthropic\nclient = anthropic.Anthropic()\n\nDOCS = [\n    \"Refunds: monthly plans may be refunded within 14 days of purchase \"\n    \"if usage is below 1,000 API calls.\",\n    \"Billing cycles run from the 1st of each month.\",\n]\n\ndef answer(question: str) -> str:\n    context = \"\\n\\n\".join(DOCS)                 # [F1] no relevance check\n    response = client.messages.create(\n        model=\"claude-sonnet-5-5\", max_tokens=1024,\n        system=\"Answer the user's question using the context below.\\n\\n\" + context,  # [F3]\n        messages=[{\"role\": \"user\", \"content\": question}],\n    )\n    return next(b.text for b in response.content if b.type == \"text\")  # [F4] straight to user\n\nprint(answer(\"What is the refund policy for annual plans?\"))\n# Typical output: a fluent, invented policy for annual plans - the docs only cover monthly.\n```\n\nPrinciple: **every claim must be traceable to a retrieved source, and \"I don't know\" must be a first-class answer.**\n\n```\n# Layer 1 + 2: retrieval gate (relevance floor + freshness filter)\ndef gate_retrieval(chunks: list[Chunk]) -> list[Chunk]:\n    fresh  = [c for c in chunks if not c.superseded]       # layer 2\n    strong = [c for c in fresh if c.score >= MIN_RELEVANCE]  # layer 1 (e.g. 0.72)\n    return strong        # an EMPTY result is VALID -> routes to abstention, not generation\n# Layer 3: citation-forced generation with an explicit out\nclass Citation(BaseModel):\n    doc_id: str\n    quote: str           # verbatim sentence from the source supporting the claim\n\nclass GroundedAnswer(BaseModel):\n    can_answer: bool     # False when the context does not contain the answer\n    answer: str\n    citations: list[Citation]\n\nSYSTEM = \"\"\"Use ONLY the provided context. Every factual claim must carry a\nverbatim citation. If the context does not contain the answer, set\ncan_answer=false - that is a GOOD outcome. Do not generalize from a\nsimilar-but-different case (e.g. monthly vs annual).\"\"\"\n# Layer 4: faithfulness judge - a SEPARATE, cheap model that never sees the question,\n# so it can't be charmed into agreeing the answer is \"helpful\" - only that it's SUPPORTED.\ndef judge_faithfulness(answer, chunks) -> float:\n    # ... returns supported_claims / total_claims via a small model (Haiku-class) ...\n    ...\n# Layer 5: the pipeline, with abstention as a first-class path\ndef answer_question(question, retrieved) -> str:\n    chunks = gate_retrieval(retrieved)\n    if not chunks:                       return ABSTAIN   # escalate to a human ticket\n    result = generate(question, chunks)\n    if not result.can_answer:            return ABSTAIN\n    source_text = \" \".join(c.text for c in chunks)\n    for cit in result.citations:                          # deterministic, no LLM\n        if cit.quote not in source_text: return ABSTAIN   # fabricated citation -> abstain\n    if judge_faithfulness(result, chunks) < MIN_FAITHFULNESS: return ABSTAIN\n    return result.answer\n```\n\nFour things matter more than any prompt wording:\n\n`gate_retrieval` returning `[]` is the system saying \"escalate to a human.\" Before the fix, that state was unrepresentable.`cit.quote not in source_text` is dumb string containment — and that's its virtue. An LLM cannot talk its way past it. Catches fabricated citations with zero model calls.`abstain` logs became our knowledge-base content roadmap.\n| # | Case | Caught by | \n|---|---|---|\n| 1 | Pure fabrication (the 60-day policy) | Judge (claims unsupported) | \n| 2 | Wrong-source citation | Verbatim citation check | \n| 3 | Stale truth (superseded promo doc) | Freshness filter (layer 2) | \n| 4 | Near-miss generalization (monthly → annual) | Prompt rule + judge | \n| 5 | Partial truth (real window, invented \"no questions asked\") | Judge (per-claim split) | \n| 6 | Confident answer on garbage retrieval (0.61) | Relevance gate (layer 1) | \n\nA fix that handles only one of these will look done and still burn you.\n\n| Addition | Latency | Cost | \n|---|---|---|\n| Citation-forced structured output | ~0 | +15% output tokens | \n| Verbatim citation check | <1 ms | $0 | \n| Faithfulness judge (small model) | +400-600 ms | ~$0.0004/query | \n\nWe 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.\n\n| Metric | Before | After | \n|---|---|---|\n| Answers with ≥1 unsupported claim | 18% | **3%** | \n| Faithfulness (judge-scored) | not measured | **0.96** | \n| Policy-risk incidents reaching customers | ~2/month | **0 in 8 weeks** | \n| Abstention rate | 0% (by design!) | 9%, all escalated to humans | \n\nThe 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.\n\n**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.\"*\n\nFollow-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).\n\n*Originally published on [PrepStack](https://prepstack.co.in/blog/ai-production-scenario-1-rag-hallucinations).*", "url": "https://wpnews.pro/news/our-ai-support-bot-invented-a-refund-policy-how-we-cut-rag-hallucinations-from-3", "canonical_source": "https://dev.to/kirandeepjassalcrypto/our-ai-support-bot-invented-a-refund-policy-how-we-cut-rag-hallucinations-from-18-to-3-in-225e", "published_at": "2026-11-27 17:06:29+00:00", "updated_at": "2026-11-27 17:11:54.069073+00:00", "lang": "en", "topics": ["artificial-intelligence", "large-language-models", "ai-agents", "ai-tools"], "entities": ["PrepStack", "Anthropic", "Claude"], "also_reported_by": [], "takeaway": "Gating retrieval on a relevance floor (about 0.72) plus a freshness filter, forcing verbatim citations with a can_answer flag, and verifying answers before delivery cut unsupported claims from 18% to 3%.", "recommendation": {"advice": "Add a relevance score floor and freshness filter before generation, force verbatim citations with an explicit can_answer abstention, and verify claims before answers reach users.", "playbook": "output-verification", "playbook_url": "https://wpnews.pro/playbooks/output-verification"}, "alternates": {"html": "https://wpnews.pro/news/our-ai-support-bot-invented-a-refund-policy-how-we-cut-rag-hallucinations-from-3", "markdown": "https://wpnews.pro/news/our-ai-support-bot-invented-a-refund-policy-how-we-cut-rag-hallucinations-from-3.md", "text": "https://wpnews.pro/news/our-ai-support-bot-invented-a-refund-policy-how-we-cut-rag-hallucinations-from-3.txt", "jsonld": "https://wpnews.pro/news/our-ai-support-bot-invented-a-refund-policy-how-we-cut-rag-hallucinations-from-3.jsonld"}}