Designing a Safe Patient-Facing Medical QA Assistant
Machine LearningModel answerLast updated
Design the data pipeline, grounding architecture, hallucination and safety evaluation, and fairness controls for a clinical Q&A assistant that must never diagnose.
Context
A hospital wants a conversational assistant embedded in its patient portal. Patients will use it to ask general health questions and to get plain-language explanations of their own lab results. The assistant must give educational information only: it must never issue a diagnosis, never recommend a dose, and never stand in for a clinician. Emergencies must be routed to humans immediately.
You have three kinds of material available:
- A very large archive of clinical notes from the hospital's records system.
- A curated library of clinical guidelines and reference summaries.
- A small set of Q&A pairs written and reviewed by clinicians.
What to Deliver
Work through the design as you would in a technical screen, covering:
- Data plan. What role does each source play — training, retrieval, or evaluation? How do you de-identify records, and how do you stop the model from memorizing or leaking patient-specific details?
- Architecture trade-off. Compare fine-tuning a language model on clinical notes against retrieval-augmented generation over the guideline library. Make a recommendation and justify it.
- Evaluation protocol. How do you operationalize "hallucination" and "safety"? Name concrete automated metrics, describe the human review process, and state launch gates.
- Risk controls. How do you detect and reduce performance differences across patient subgroups, and how do you handle queries whose style or vocabulary drifts away from the clinical training distribution?
State your assumptions about users, scale, latency, and regulatory constraints before you design.
Hints
Hint 1
Decide early what each data source is *for* — notes and guidelines are not interchangeable, and the tiny expert Q&A set is worth more as a test set than as training data.
Hint 2
Grounding beats memorization in medicine: if every claim must point at a retrieved passage, hallucination becomes a measurable, checkable property rather than a vibe.
Hint 3
Grade answers claim by claim, not with BLEU or ROUGE — a fluent wrong answer scores well on surface overlap and can still harm someone.
Hint 4
Refusal is a feature in both directions: track unsafe answers *and* over-refusals, because an assistant that says no to everything is also a failure.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Framing and assumptions
Treat this as a safety-critical system, not a modeling exercise. Before designing, pin down:
- Audience: patients writing in lay language, with typos and possibly a second language. Not clinicians.
- Scope: health education plus explanations of the patient's own results. No diagnosis, no dosing, no interpretation presented as medical advice.
- Scale: roughly 200k portal users, ~10k queries/day, ~5 QPS peak, p95 latency under 5 seconds.
- Compliance: HIPAA. Record access is scoped to the authenticated patient, with audit logs on every retrieval and generation.
- Inventory: millions of notes, ~50k guideline documents, ~2k expert Q&A pairs. The Q&A set is small, so its highest-value use is evaluation.
1. Data strategy: give each source one job
| Source | Role | Deliberately not used for |
|---|---|---|
| Guidelines / reference summaries | The retrieval corpus. Chunked, versioned, tagged with source, publication date, evidence level, and applicable population. | — (this is the trusted knowledge base) |
| EHR notes | De-identified; used to model the distribution of patient questions, to build realistic eval cases, and to train PHI and safety classifiers. | Generative pretraining or fine-tuning |
| Patient's own labs | Retrieved at inference through a scoped tool call; patient ID comes from the session, never from the prompt text. | Indexing into any shared corpus |
| Expert Q&A pairs | Mostly held out as a gold eval set; a slice used for few-shot examples and light instruction tuning of tone and refusal behavior. | — |
De-identification. Follow HIPAA Safe Harbor's 18 identifier categories with layers: regex for record numbers, phone numbers, and dates; a clinical NER model for names, locations, and rare conditions; surrogate substitution rather than blanking, so text stays fluent; and per-patient date shifting that preserves intervals. Measure de-id recall on a hand-annotated sample — missed PHI is the expensive error — targeting >99% for direct identifiers. For rare diseases and tiny cohorts, check quasi-identifiers (k-anonymity style) because a "de-identified" note can still re-identify one patient.
Preventing leakage. Split by patient, never by note, and deduplicate templated "copy-forward" text that appears in many records. The strongest control is architectural: keep raw note text out of model weights entirely, since memorized content cannot be reliably unlearned. If any fine-tuning touches clinical text, use DP-SGD, embed canary strings, and run extraction and membership-inference probes before release. Add an output-side PHI filter as a final backstop.
2. Architecture: fine-tuning vs. RAG
| Dimension | Fine-tune on clinical notes | RAG over guidelines |
|---|---|---|
| PHI risk | High — memorization, hard to remove | Low — no PHI in weights |
| Freshness | Stale until retrained | Reindex when guidance changes |
| Traceability | None | Every claim can cite a passage |
| Register | Learns clinician shorthand — wrong for patients | Base model + prompting yields lay language |
| Failure mode | Confident fabrication | Retrieval miss or conflicting sources |
Recommendation: RAG, plus light instruction tuning on de-identified expert Q&A for tone and refusal behavior. The traceability and PHI story dominate in this setting.
Request flow:
- Input triage classifier — route to emergency escalation (chest pain, self-harm), to "ask your care team" (diagnosis or dosing requests), out-of-scope, or in-scope.
- Query rewriting — map lay terms to clinical terms ("sugar test" → HbA1c).
- Hybrid retrieval + rerank — BM25 fused with a medical embedding model, then a cross-encoder reranker; filter by recency and population.
- Grounded generation — inline citations required; answers constrained to retrieved context.
- Claim verifier — an NLI model or LLM judge checks each atomic claim for entailment; unsupported claims are dropped or trigger abstention.
- Output safety classifier + PHI filter, then a disclaimer and a link to the care team.
3. Evaluation
Surface-overlap metrics (BLEU/ROUGE) are the wrong tool: a fluent answer can score well and still be harmful. Instead:
- Retrieval: recall@k against expert-marked relevant passages.
- Faithfulness: split answers into atomic claims, test each for entailment against context; hallucination rate = unsupported claims / total claims.
- Correctness: claim-level agreement with gold expert answers.
- Citations: precision (does the cited passage support the claim?) and coverage.
- Safety: a red-team suite covering diagnosis-seeking, dosing, self-harm, emergencies, prompt injection, and attempts to read another patient's data.
- Refusal calibration: track both unsafe-answer rate and over-refusal rate.
- Readability: roughly grade 8 or below.
Human-in-the-loop. Clinicians grade blinded answers on factual accuracy, completeness, harm likelihood × severity (AHRQ-style categories), and lay appropriateness. Double-rate items and report Cohen's kappa. Use those labels to calibrate an LLM judge, and trust the judge only on dimensions where it agrees with clinicians. Launch gates: zero severe-harm answers in a 1,000-answer review (which bounds the true rate below roughly 0.3% at 95% confidence) and hallucination below an agreed threshold. Roll out in shadow mode — clinicians see drafts — before patients do.
4. Risk mitigation
Subgroup bias. Stratify every metric by age, sex, race/ethnicity, language, reading level, and condition, with confidence intervals so small slices aren't over-interpreted. Run counterfactual tests: swap demographic attributes in a query and require the answer to stay the same unless a difference is clinically justified. If a slice underperforms, fix it with targeted retrieval and evaluation data, not just more training.
Distribution shift. Patient phrasing differs sharply from clinical text, so monitor live traffic for vocabulary and intent drift, sample queries for weekly human review, and maintain a regression suite of real lay-language questions. Add out-of-distribution detection to route uncertain queries to abstention or a human. Retrain triage and safety classifiers on freshly labeled patient language, and version every prompt, index, and model so any regression can be rolled back.
Common mistakes to avoid: splitting eval data by note instead of by patient, quoting a single accuracy number instead of a claim-level hallucination rate, rewarding refusal without penalizing over-refusal, and treating de-identification as a preprocessing checkbox rather than a measured, audited property.