11. Security & Ethics
AI Hallucinations
AI hallucinations are fluent model outputs that are not grounded in provided evidence, tools, or reality — wrong facts, fake citations, invented APIs, or false “task done” claims. In agents, hallucinations are dangerous because they drive tool calls and user decisions with false confidence. Mitigate by grounding with RAG/tools, verifying citations, constraining schemas, allowing abstention, and evaluating faithfulness — not by hoping the model “tries harder.”
What you will learn
- Define hallucinations and why agents amplify their impact
- Recognize factual, citation, tool, and planning failure modes
- Apply ground-verify-constrain-abstain-eval mitigations
- Design refusal and citation rules for high-stakes answers
- Answer interview questions with short, solid answers
Definition
A hallucination is generated content presented as true or complete that is unsupported or contradicted by the available evidence — or by the real world when evidence was required. Models optimize for plausible continuation, not guaranteed truth.
For agents, include tool and plan hallucinations: inventing endpoints, misreading tool results, or declaring success when checks failed.
Introduction
This lesson (#6 in Security & Ethics) follows Tool Execution Security. Secure tools still execute wrong plans if the model invents state or facts.
Next: Responsible AI, Human Oversight and Governance — when humans must stay in the loop.
Why agents raise the stakes
- Wrong facts become CRM updates, emails, or tickets
- Fake citations create false audit trails
- Invented tool APIs waste budget or hit wrong systems
- False “done” stops retries and hides failures
- Users over-trust confident tone
Types
Name the failure so you can test for it.
- Factual - incorrect entities, dates, numbers, policies
- Citation - URLs/docs that do not exist or do not support the claim
- Tool - non-existent functions, wrong argument shapes, ignored errors
- Plan/state - believes a step succeeded; skips verification
- Attribution - mixes sources or invents quotes
Root causes (practical view)
- Gaps in training data and outdated knowledge
- Pressure to always answer (no abstain path)
- Weak or noisy retrieval in RAG
- Long contexts that bury the relevant evidence
- Decoding that favors fluency over precision
Mitigation stack
Stack grounding with verification and product rules.
- Ground - retrieve docs or call tools before answering
- Verify - require claim-to-span citations; re-check with tools
- Constrain - structured outputs and closed tool schemas
- Abstain - “insufficient evidence” as a first-class result
- Reflect - critic/tests before irreversible actions
- Eval - faithfulness and citation coverage on golden sets
Product patterns
- Show sources next to answers in the UX
- Separate “model opinion” from “tool-confirmed” fields
- Block send/update if required citations are missing
- Prefer calculate/query tools over mental math for numbers
- HITL when confidence or evidence score is low
Failure modes
- RAG with poor retrieval still sounds authoritative
- Asking the model to “self-check” without external evidence
- Accepting tool success from narrative, not return codes
- No eval suite — regressions ship unnoticed
- Punishing abstention so the model always guesses
Program / implementation notes
For Q&A: retrieve top-k, answer only with citations to chunk ids, refuse if none support. For agents: after each tool call, parse structured success flags before planning the next step. Add faithfulness tests to CI.
- Reward abstain in eval scoring for high-stakes domains
- Next: Responsible AI, Human Oversight and Governance
Advantages and limitations
- Advantage: grounding + verify cuts many factual errors
- Advantage: schemas reduce tool hallucinations
- Advantage: abstain improves user trust when honest
- Limitation: retrieval can still miss the right evidence
- Limitation: some creative tasks need controlled speculation
- Limitation: faithfulness metrics are imperfect proxies
Key points
- Hallucinations = ungrounded fluent claims (facts, cites, tools, plans).
- Agents amplify impact when tools and users act on them.
- Mitigate: ground, verify, constrain, abstain, evaluate.
- Require citations or tool confirmation for high-stakes fields.
- Parse tool success structurally — not from prose.
- Do not punish abstention in critical workflows.
FAQs
Are hallucinations bugs or expected behavior?
Expected without grounding constraints. Treat them as a product risk to engineer around, not a rare defect to wish away.
Does RAG eliminate hallucinations?
No. It reduces them when retrieval is relevant and answers are constrained to evidence — bad retrieval can still produce confident wrong answers.
Hallucination vs prompt injection?
Hallucination is ungrounded generation. Prompt injection is adversarial steering via untrusted text. Both can cause bad tool use; defenses overlap but are not identical.
When is speculation acceptable?
When labeled as uncertain brainstorming with no side effects. Never for citations, compliance answers, or irreversible actions.
Interview questions
- What is an AI hallucination?
Answer Fluent model output that is not supported by evidence or reality — including fake facts, citations, tools, or success claims.
- Why are hallucinations worse in agents?
Answer Because false beliefs can trigger tool side effects and user decisions, not just incorrect chat text.
- Name types of agent hallucinations.
Answer Factual errors, fabricated or mismatched citations, invented tool calls/APIs, and false plan/state completion claims.
- How do you mitigate them?
Answer Ground with retrieval/tools, verify with citations or checks, constrain schemas, allow abstain, and evaluate faithfulness continuously.
- Does a bigger model solve hallucinations?
Answer Larger models can help on some tasks but do not remove the need for grounding, verification, and product-level abstain rules.
- How do you evaluate hallucination rate?
Answer Use golden sets scoring factuality/faithfulness, citation validity, tool-arg correctness, and abstain quality on out-of-evidence questions.
Related topics
Practice task
Complete each numbered practice step in a notebook or doc before opening the next lesson.
- List three hallucination examples for your product (fact, citation, tool/plan).
- Write a citation rule: when answers must include source ids or refuse.
- Design a post-tool check that reads structured success before continuing.
- Add two eval cases: one grounded answer and one must-abstain question.
- Answer interview questions 1, 2, and 4 in two sentences each.