Deep dive 24 of 27: Engineering Fix: Strict RAG and Citation Enforcement
Nov 19, 2026 · Michael Chang · Status in NurseOps Now: ✅ built
Show definitions in ( ) · hover a highlighted word for its meaning, click it for details · open with ?defs=1 to show definitions
Part of: Remembering the right things: state management in NurseOps Now, section Preventing Drift and Hallucinations in Long-Running Agents (7.4) · All 27 solutions · ← Engineering Fix: Recursive Goal Injection · Input Filtering: Relevance Pruning →
Read in this order
- In plain words: what it is, without jargon
- The problem it solves: the problem, and the standard approach in my words
- How to implement it (ServiceApps): scenario, steps, code and real output
- In NurseOps Now: built or not, and where
- Trade-offs and Interview answer
In plain words
Strict RAG (retrieval-augmented generation: the AI looks things up before it answers) means the AI may only answer factual questions from retrieved sources, and must cite them. If the source isn't there, it says so ("MISSING_INFO") instead of guessing. A check then confirms every quote really appears in its source.
In plain terms: no claim without a page number, and someone checks the page.
The problem it solves
Hallucination (The Grounding Failure) (the AI stating made-up facts when the answer isn't in front of it): when the answer isn't in the context, the model fills the gap with something plausible and wrong.
The standard approach (in my words): the agent (an AI that chooses which tools to use to answer) can't answer factual questions unless it cites a retrieved chunk (a small piece of a document; here, one policy rule); otherwise it outputs a predefined marker such as MISSING_INFO.
How to implement it (ServiceApps)
Illustrative example: no ServiceApps (a company platform for IT tickets, HR requests and help-center articles) instance is connected, so the scenario and data are made up. The code is a self-contained sketch; it was run on that made-up data on Nov 19, 2026, and the output below is from that run.
The setting. ServiceApps (a company platform for IT tickets, HR requests and help-center articles) Assist, an AI helper inside a company's ServiceApps (a company platform for IT tickets, HR requests and help-center articles) portal. Employees ask it IT and HR questions; it answers from knowledge-base (KB (knowledge base: a library of help articles)) articles, looks up the employee's own tickets (incidents (a ServiceApps ticket for something broken) like INC0012345) and requests, and keeps one conversation per employee and ticket.
The scenario. ServiceApps (a company platform for IT tickets, HR requests and help-center articles) Assist answers four questions; some answers cite correctly, one misquotes, one cites nothing, one honestly says it can't find the information.
Steps.
- Tell the model: answer only from the retrieved chunks (small pieces of a document; here, one policy rule each), cite them as [ID] "quote", else say MISSING_INFO.
- After the answer, check each citation (a pointer to the exact page and quote that supports a claim): the source exists and the quote is in it.
- Block or flag answers that fail.
- Count MISSING_INFO answers; they show gaps in the knowledge base (a library of help articles; in ServiceApps, a named group of KB articles).
The code (Python):
import re
CHUNKS = {"KB0010234#errors": "Error 809 means the VPN can't reach the server. Avoid guest Wi-Fi and restart the client.",
"KB0020311#4": "Employees may work from another country for up to 10 working days a year."}
def check(answer):
if answer.startswith("MISSING_INFO"):
return "OK (honest MISSING_INFO)"
m = re.search(r'\[(KB\d+#\w+)\]\s*"([^"]+)"', answer)
if not m:
return "BLOCKED: no citation"
cid, quote = m.groups()
if cid not in CHUNKS:
return f"BLOCKED: unknown source {cid}"
if quote not in CHUNKS[cid]:
return f"BLOCKED: quote not in {cid}"
return "OK"
answers = ['Avoid guest Wi-Fi. [KB0010234#errors] "Avoid guest Wi-Fi and restart the client."',
'You can work abroad for 30 days. [KB0020311#4] "up to 30 working days a year"',
'Your laptop is probably fine.',
"MISSING_INFO: I can't find your laptop's warranty in the knowledge base."]
for a in answers:
print(f"{check(a):28s} <- {a[:58]}")
Output (from running the code above):
OK <- Avoid guest Wi-Fi. [KB0010234#errors] "Avoid guest Wi-Fi a BLOCKED: quote not in KB0020311#4 <- You can work abroad for 30 days. [KB0020311#4] "up to 30 w BLOCKED: no citation <- Your laptop is probably fine. OK (honest MISSING_INFO) <- MISSING_INFO: I can't find your laptop's warranty in the k
What to watch for.
- Check quotes in code; don't trust the model's own claim that it cited.
- Allow honest "I don't know" answers; punishing them encourages guessing.
- Quote checks need exact text; normalize spaces and punctuation consistently.
In plain terms: every answer must point to the KB (knowledge base: a library of help articles) line it came from, and a checker reads that line to confirm.
In NurseOps Now
Built: AI Assist (the app's chat helper for staff questions)'s prompt (the instructions and text given to the AI) says answer only from tools (a function the AI can call, such as policy search) and say "I don't know" otherwise; the check node adds a "please check" note to answers without sources; and every case review quote must match the PDF (a fixed-layout document file) exactly, or the review is sent back once. See Step 11.
Trade-offs
- More "I don't know" answers, which is the honest cost of fewer made-up ones.
- Exact quote checks can fail on harmless formatting differences.
Interview answer
"Factual answers must cite a retrieved chunk (a small piece of a document; here, one policy rule) with an exact quote, and code checks that the quote is really in that chunk (a small piece of a document; here, one policy rule). No source means an explicit MISSING_INFO, not a guess. That turns hallucination (the AI stating something that isn't in the sources) from a silent failure into a visible, countable one."
All data in this post is made up. No real people, tickets or patient data.
← Back to all 27 solutions in the state management blog
Key terms
Every highlighted word in this post links here. Click ↩ Back to return to the spot you came from.
- agent
- An AI that chooses which tools to use to answer.Used in: The problem it solves↩ Back to where you were
- AI Assist
- The app's chat helper for staff questions.Used in: In NurseOps Now↩ Back to where you were
- chunk
- A small piece of a document; here, one policy rule.Used in: The problem it solves, Interview answer↩ Back to where you were
- chunks
- Small pieces of a document; here, one policy rule each.Used in: How to implement it (ServiceApps)↩ Back to where you were
- citation
- A pointer to the exact page and quote that supports a claim.Used in: How to implement it (ServiceApps)↩ Back to where you were
- hallucination
- The AI stating something that isn't in the sources.Used in: Interview answer↩ Back to where you were
- hallucination (the grounding failure)
- The AI stating made-up facts when the answer isn't in front of it.Used in: The problem it solves↩ Back to where you were
- incident
- A ServiceApps ticket for something broken.Used in: How to implement it (ServiceApps)↩ Back to where you were
- KB
- Knowledge base: a library of help articles.Used in: How to implement it (ServiceApps)↩ Back to where you were
- knowledge base
- A library of help articles; in ServiceApps, a named group of KB articles.Used in: How to implement it (ServiceApps)↩ Back to where you were
- A fixed-layout document file.Used in: In NurseOps Now↩ Back to where you were
- prompt
- The instructions and text given to the AI.Used in: In NurseOps Now↩ Back to where you were
- RAG
- Retrieval-augmented generation: the AI looks things up before it answers.Used in: In plain words↩ Back to where you were
- ServiceApps
- A company platform for IT tickets, HR requests and help-center articles.Used in: How to implement it (ServiceApps)↩ Back to where you were
- tool
- A function the AI can call, such as policy search.Used in: In NurseOps Now↩ Back to where you were