Safety Architecture
Defense in Depth: Multiple independent safety checks ensure errors are caught even if one layer fails.
Medical Error Prevention Panel
Purpose: Comprehensive medication safety review that runs on every case Source:backend/safety_panel/med_errors.py:49
Execution: Runs in parallel with the debate pipeline via asyncio.gather
Four Safety Domains
Drug-Drug Interactions
Check every medication pair for interactions (contraindicated, major, moderate, minor)
Drug-Disease Contraindications
Cross-reference each drug against patient conditions
Dosing Alerts
Renal/hepatic/weight/age-based dose adjustments
Population Flags
Pregnancy, pediatric, elderly, lactation concerns
Implementation
System Prompt
View Med Error System Prompt
View Med Error System Prompt
Output Schema
Example Output
Parallel Execution: The Med Error Panel runs simultaneously with the debate pipeline, adding zero latency to overall processing time.
PHI Anonymization
Purpose: Scrub Protected Health Information before LLM processing Technology: Microsoft Presidio + spaCy NLP Source:backend/input_layer/anonymizer.py:78
What Gets Anonymized
Direct Identifiers
- Patient names →
[PATIENT] - Phone numbers →
[PHONE] - Email addresses →
[EMAIL] - SSN →
[SSN] - MRN →
MRN: [REDACTED]
Dates (Targeted)
- Date of Birth (DOB) →
[DOB REDACTED] - Note: Generic
DATE_TIMEentity excluded to avoid false positives on med dosages
Locations (Filtered)
- Geographic locations →
[LOCATION] - Filtered: Clinical terms like “oral”, “IV”, “chest” are NOT anonymized
Implementation
Clinical Term Protection
Presidio sometimes flags clinical terms as PHI. We filter these:Output Guardrails
Multiple validation rules prevent unsafe/incomplete outputs:1. Pydantic Schema Validation
All models use strict typing:2. Minimum Differential Count
Implementation
Implementation
3. No Hallucinated Medications
Cross-reference all medications against DrugBank vocabulary:4. Safety Flag Enforcement
If Med Error Panel flags contraindicated interactions, they MUST appear in Plan:5. MUC Confidence Thresholds
Model Under Certainty (MUC) analysis flags low-confidence outputs:Human-in-the-Loop
When debate fails to reach consensus or confidence is low:External Safety Data Sources
FDA openFDA
Drug labels, adverse events, interactions via REST API
DrugBank (Open Data)
Drug vocabulary, interactions CSV (free tier)
RxNorm API
Normalized drug names, RxCUI lookups
Parallel Lookups
All external APIs are called in parallel:Safety Checklist (Every Case)
✓ PHI Scrubbed
✓ PHI Scrubbed
All inputs pass through Presidio before LLM processing
✓ Med Error Panel Run
✓ Med Error Panel Run
Drug interactions, contraindications, dosing alerts checked
✓ Pydantic Validation
✓ Pydantic Validation
All outputs conform to strict schemas
✓ Minimum 2 Differentials
✓ Minimum 2 Differentials
Prevents anchoring bias
✓ No Hallucinated Meds
✓ No Hallucinated Meds
Cross-referenced against DrugBank
✓ Safety Flags Enforced
✓ Safety Flags Enforced
Contraindicated interactions appear in Plan
✓ Confidence Thresholds
✓ Confidence Thresholds
Low-confidence outputs flagged for human review
HIPAA Compliance Considerations
Current anonymization is not sufficient for HIPAA compliance alone - it’s defense-in-depth.Emergency Mode Safety
Even in fast-path mode, safety checks run:Next Steps
Architecture
Layer-by-layer system overview
Agent Types
Clinical, Literature, Safety, Critic agents
Multi-Agent Debate
How debate drives consensus and refinement