Hallucinations erode user trust faster than almost any other failure mode. In a website‑grounded assistant the good news is most hallucinations are tractable: they stem from (a) missing or stale source content, (b) weak retrieval signals, (c) permissive or underspecified generation prompts, or (d) lack of post‑answer validation and feedback loops. This article breaks the problem down into layered controls so you can measure, mitigate, and steadily drive hallucination rates toward an acceptable baseline.
Taxonomy of Hallucinations
Before fixing, name the patterns:
- Fabricated Fact: The model asserts information not present in any indexed source (“Your plan renews every 45 days” when billing cycles are monthly).
- Outdated Fact: The answer once was true but underlying content changed (deprecated features, new pricing tiers).
- Scope Overreach: User asks outside supported domain; model improvises instead of declining.
- Unsupported Generalization: Correct snippets stitched into an incorrect higher‑level conclusion.
- Misattributed Source: Cites or implies authority from a page that does not contain the claim.
- Hallucinated Structure: Fabricated steps, parameters, or configuration names.
Each type maps to a control point (data, retrieval, generation, validation, or user feedback). Tagging issues during evaluation lets you prioritize root causes quantitatively.
Data Layer Controls
Garbage in → hallucinations out. Start with disciplined content curation:
| Control | Purpose | Implementation Notes |
|---|---|---|
| Explicit Scope List | Prevent latent inclusion of marketing fluff or low‑signal pages | Maintain allowlist patterns (regex / path prefixes) versioned in config |
| Freshness SLA | Reduce outdated fact drift | Compute last indexed age; alert when > threshold (e.g. 30d for pricing) |
| Boilerplate Stripping | Avoid duplicative nav/footer noise inflating irrelevant matches | DOM density + semantic tag filters |
| Canonical Deduplication | Remove near duplicates that dilute retrieval ranking | Shingle hash or SimHash with 0.9 similarity cutoff |
| Structured Metadata | Enable targeted retrieval & refusal logic | Tag pages with type (pricing, docs, legal) and locale |
Routine recrawl cadence + change detection (ETag / Last‑Modified / sitemaps) keeps the knowledge base synchronized with reality.
Retrieval Layer Controls
Low‑precision retrieval is the single greatest hallucination amplifier. Key tactics:
- Hybrid Retrieval: Blend vector similarity with lexical / field filters so essential short keywords (“VAT”) are not lost in dense embeddings.
- Score Thresholding: If top‑k relevance scores fall below a calibrated floor, prefer graceful refusal over guesswork.
- Minimum Evidence Count: Require N distinct chunks (e.g. ≥2) before synthesizing an answer for higher‑risk intents (pricing, legal).
- Diversity Constraint: Penalize chunks from the same page section to widen coverage.
- Freshness Bias: Boost newer content for volatile domains (release notes) while allowing stable docs to compete.
Log retrieval contexts for every answer; without that corpus you cannot audit hallucinations later.
Generation Layer Controls
Shaping the model’s behavior reduces improvisation:
| Technique | Effect | Prompt / Pattern |
|---|---|---|
| Explicit Role & Scope | Constrains domain | ”You are an assistant that ONLY answers using the provided website context.” |
| Answer Format Contract | Encourages structured, factual style | JSON or bullet template for certain intents |
| Citation Requirement | Forces grounding | Append [n] markers tied to retrieved chunk IDs |
| Refusal Clause | Channels out‑of‑scope queries | Provide fallback copy (“I don’t have that information.”) |
| Temperature Control | Lowers creative drift | Temp 0.1–0.3 for factual answers |
| Negative Instructions | Blocks speculation | ”Do not guess. If unsure, state that the answer isn’t available.” |
Short, deterministic prompts beat verbose, uncontrolled instruction dumps.
Post-Generation Validation
Add a lightweight safety net before surfacing an answer:
- Claim Grounding Check: Sample sentences and re‑ask a verifier model: “Is this sentence supported by any of these source snippets?” Reject unsupported claims.
- Entity Whitelist/Blacklist: Disallow unexpected product names or internal codewords from leaking.
- PII / Sensitive Scan: Regex + ML classification for emails, keys, tokens; redact or refuse.
- Toxicity & Compliance Filter: Particularly for user‑generated context or open inputs.
- Refusal Upgrade: If validation fails, return polite fallback with encouragement to rephrase.
Keep latency budget in mind: run cheap regex/keyword filters first, escalate to model validators only when needed.
Feedback & Continuous Learning
Deploy with instrumentation from Day 1:
| Signal | Capture Method | Use |
|---|---|---|
| Thumbs / Reaction | Widget UI events | Prioritize review queue |
| User Edits (Agent Assist) | Track corrected answers | Fine‑tune evaluation set |
| Escalations | Flag when human handoff required | Identify scope gaps |
| Search→No Answer Patterns | Query logs without answers | Content roadmap |
Integrate a lightweight review console so analysts can tag root cause categories quickly (retrieval miss, outdated content, prompt issue, etc.).
Evaluation Metrics
Move beyond subjective impressions. Suggested core dashboard:
| Metric | Definition | Target (Initial) |
|---|---|---|
| Hallucination Rate | % answers with ≥1 unsupported claim | <5% after month 1 |
| Unsupported Claim Density | Unsupported claims / 100 answers | Downward trend |
| Retrieval Precision@k | Relevant chunks in top‑k | >0.75 at k=5 |
| Coverage | % queries with at least one relevant chunk | >0.9 |
| Refusal Appropriateness | % refusals where scope truly absent | >0.95 |
| Freshness Lag | Median age (days) of sources used | Align with SLA |
Run periodic manual audits—e.g., weekly 50‑answer review—to calibrate automated signals.
Tooling Stack
Minimum viable stack:
- Retrieval Context Logger (JSON lines per answer)
- Evaluation Harness (offline queries + expected facts)
- Diff Viewer (before/after model/prompt change)
- Red Team Script (edge case / adversarial prompts)
- Metric Dashboard (hallucination rate, precision, refusal correctness)
Iterate toward automation: block deploys when hallucination rate regresses beyond a tolerance band.
Optimization Path
Suggested sequence to maximize impact:
- Fix Retrieval Precision (improve chunking, hybrid scoring)
- Add Refusal & Citation Prompting
- Layer Validation (claim grounding + PII scan)
- Establish Feedback Loop & Tagging
- Automate Evaluation & Regression Alerts
- Incrementally Tighten Thresholds (raise score floors, add diversity constraints)
Avoid premature micro‑optimizations (e.g., fancy re‑rankers) before you have baseline precision and refusal logic dialed in.
Key Takeaways
- Most hallucinations trace back to poor retrieval precision or stale content—fix those first.
- Calibrate a relevance score floor and prefer explicit refusal over guessing.
- Enforce citations; unsupported claims become visible and auditable.
- Add cheap validation (regex, blacklists) before expensive verifier calls.
- Build a tagging workflow—quantified root causes accelerate iteration.
- Treat hallucination reduction as continuous quality ops, not a one‑off project.