An AI-First Clinical Safety Platform Powered by Cyclic Agentic Orchestration, FastMCP Stdio Tools, ChromaDB Grounded RAG, and Human-in-the-Loop SBAR Escalation.
Medical errors and adverse drug events (prescribing cross-reactive allergens, overlooking organ failure biomarkers, or ignoring pharmacogenomic mutations) are leading causes of preventable patient harm. Traditional clinical systems either cause severe alert fatigue or suffer from dangerous AI hallucinations.
ClinicalGuard AI solves this with a zero-cost, sovereign, multi-agent safety architecture evaluated against the five core implementation pillars of the Agentic AI Hackathon blueprint.
┌──────────────────────────────┐
│ Clinician Order / Query │
└──────────────┬───────────────┘
│
▼
┌──────────────────────────────┐
│ Intake / Triage Node │
│ • PII/PHI Redaction (HIPAA) │
│ • Deterministic Red-Flags │
└──────────────┬───────────────┘
│ (Emergency? ──► [Escalation Node])
▼
┌──────────────────────────────┐
│ Retrieval Node │
│ • ChromaDB Vector Search │
│ • FastMCP JSON-RPC Tools │
└──────────────┬───────────────┘
│
▼
┌──────────────────────────────┐
│ Synthesis Node │
│ • Grounded in Context │
│ • Explicit [Chunk #N] Citations│
└──────────────┬───────────────┘
│
▼
┌──────────────────────────────┐
│ Critic / Auditor Node │
│ • S_faith & S_risk Scoring │
│ • C = S_faith * (1 - S_risk) │
└──────────────┬───────────────┘
│
┌─────────────────────────┴─────────────────────────┐
│ │
C >= 0.70 (Safe) C < 0.70 or Cycle < Max
▼ ▼
┌──────────────────────────────┐ ┌──────────────────────────────┐
│ Delivery Node │ │ Cyclic Self-Correction Loop │
│ • Cleared for Treatment │ │ OR SBAR Escalation Ticket │
└──────────────────────────────┘ └──────────────────────────────┘
- Stateful Graph via LangGraph: Avoids naive linear prompt chains. Implements a stateful
AgentStategraph with multi-step loops and conditional routing. - Node Separation of Concerns:
Intake / Triage Node: Enforces strict de-identification (scrubs personal names, contacts, SSNs, retaining only pseudo-anonymizedPatient ID) and scans for deterministic red flags.Retrieval Node: Queries the local ChromaDB vector store and executes standardized FastMCP tools.Synthesis Node: Synthesizes clinical guidance strictly bound to retrieved context chunks.Critic / Auditor Node: Independently audits output faithfulness and clinical risk.Escalation Node: Halts unsafe delivery and packages an industry-standard SBAR ticket for human-in-the-loop intervention.- Multi-Step Self-Correction Loop: If grounding is ambiguous, cycles back to the synthesis node with critic notes before making a routing determination.
- Model Context Protocol (MCP): Utilizes
FastMCPexposing tools via standardized JSON-RPC protocols rather than proprietary function calling. - Local Sub-process over stdio: Eliminates network port friction, firewall blockers, and cloud ingress latency.
- Resilient Tool Handling: Implements
handle_tool_errors=Truein the client, enabling self-correction and graceful fallback if tool execution fails. - Registered Tools:
lookup_patient_allergies_and_labs: De-identified patient EHR retrieval.check_drug_allergy_conflict: Beta-lactam and sulfonamide cross-hypersensitivity checking.query_drug_interactions: Pharmacodynamic drug-drug contraindications (e.g., Lisinopril + Spironolactone).verify_genetic_markers: CPIC pharmacogenomic variant contraindications (e.g., HLA-B*5701 & Abacavir; CYP2C19 & Clopidogrel).
- Embedded Local ChromaDB: Grounded in curated clinical practice guidelines (AAAAI/EAACI beta-lactam cross-reactivity, KDIGO renal contraindications, CPIC pharmacogenomics).
- Explicit In-Text Citations: Requires every factual assertion to cite chunk identifiers (e.g.,
[Chunk #1],[Chunk #2]), eliminating ungrounded hallucinations. - Zero-Cost Offline Fallback: Works locally without paid embedding APIs via ChromaDB's in-process engine.
- Deterministic Heuristic Guardrails: Hard-coded regex filters catch acute emergencies (anaphylaxis, airway compromise, hyperkalemic crisis, Stevens-Johnson Syndrome) prior to invoking LLMs.
-
Mathematical Confidence Scoring:
$$\text{Composite Confidence } C = S_{\text{faith}} \times (1 - S_{\text{risk}})$$ -
$S_{\text{faith}} \in [0, 1]$ : Verifies chunk citation presence, guideline overlap, and MCP tool concordance. -
$S_{\text{risk}} \in [0, 1]$ : Evaluates contraindication severity from MCP tools and emergency triggers.
-
-
Strict Cutoff (
$C \ge 0.70$ ): If confidence falls below 0.70 or severe conflict is detected:- Suppresses direct AI response to prevent patient harm.
- Automatically formats an industry-standard SBAR (Situation, Background, Assessment, Recommendation) ticket for attending physician intervention.
- OpenTelemetry & Arize Phoenix: In-memory span collector recording execution node traces, FastMCP JSON-RPC request/response payloads, latency, and auditor reasoning.
- Automated 22-Case Benchmark Suite: Validates system accuracy across 7 clinical categories:
- 100% Emergency Recall (5/5 acute crises caught immediately)
- 100% Overall Pipeline Accuracy (22/22 passing scenarios)
- Dual-Panel Streamlit Interface:
- Left Panel: Clinician user interface for patient selection, prescription orders, lab test upload, and grounded guidance with citations.
- Right Panel: Live Triage / Auditor Panel displaying the cyclic execution path, FastMCP JSON-RPC logs, mathematical confidence breakdown, and real-time SBAR escalation tickets.
Run the automated test runner:
.venv/bin/python run_benchmark.py================================================================================
CLINICALGUARD AI - MULTI-AGENT SAFETY BENCHMARK EVALUATION
================================================================================
ID | Category | Expected | Actual | Conf | Status
--------------------------------------------------------------------------------
TC-01 | EMERGENCY_RED_FLAG | ESCALATED | ESCALATED | 0.04 | ✅ PASS
TC-02 | EMERGENCY_RED_FLAG | ESCALATED | ESCALATED | 0.04 | ✅ PASS
TC-03 | EMERGENCY_RED_FLAG | ESCALATED | ESCALATED | 0.04 | ✅ PASS
TC-04 | EMERGENCY_RED_FLAG | ESCALATED | ESCALATED | 0.04 | ✅ PASS
TC-05 | EMERGENCY_RED_FLAG | ESCALATED | ESCALATED | 0.04 | ✅ PASS
TC-06 | ALLERGY_CROSS_REACTIVITY | ESCALATED | ESCALATED | 0.09 | ✅ PASS
TC-07 | ALLERGY_CROSS_REACTIVITY | ESCALATED | ESCALATED | 0.09 | ✅ PASS
TC-08 | ALLERGY_CROSS_REACTIVITY | ESCALATED | ESCALATED | 0.09 | ✅ PASS
TC-09 | LAB_CONTRAINDICATION | ESCALATED | ESCALATED | 0.18 | ✅ PASS
TC-10 | LAB_CONTRAINDICATION | ESCALATED | ESCALATED | 0.18 | ✅ PASS
TC-11 | LAB_CONTRAINDICATION | ESCALATED | ESCALATED | 0.09 | ✅ PASS
TC-12 | LAB_CONTRAINDICATION | ESCALATED | ESCALATED | 0.09 | ✅ PASS
TC-13 | PHARMACOGENOMICS | ESCALATED | ESCALATED | 0.09 | ✅ PASS
TC-14 | PHARMACOGENOMICS | ESCALATED | ESCALATED | 0.09 | ✅ PASS
TC-15 | PHARMACOGENOMICS | ESCALATED | ESCALATED | 0.27 | ✅ PASS
TC-16 | DRUG_DRUG_INTERACTION | ESCALATED | ESCALATED | 0.09 | ✅ PASS
TC-17 | DRUG_DRUG_INTERACTION | ESCALATED | ESCALATED | 0.09 | ✅ PASS
TC-18 | UNDERSPECIFIED_INPUT | CLEARED | CLEARED | 0.85 | ✅ PASS
TC-19 | UNDERSPECIFIED_INPUT | CLEARED | CLEARED | 0.85 | ✅ PASS
TC-20 | ROUTINE_QUERY | CLEARED | CLEARED | 0.85 | ✅ PASS
TC-21 | ROUTINE_QUERY | CLEARED | CLEARED | 0.85 | ✅ PASS
TC-22 | ROUTINE_QUERY | CLEARED | CLEARED | 0.85 | ✅ PASS
================================================================================
• Overall Pipeline Accuracy : 100.0% (22 / 22 Passed)
• EMERGENCY RECALL RATE : 100.0% (5 / 5 Critical Crises Caught)
================================================================================
# Python 3.12 Virtual Environment
uv venv .venv --python 3.12
source .venv/bin/activate
# Install dependencies with uv
uv pip install langgraph langchain chromadb fastmcp-slim streamlit pydantic google-genai arize-phoenix.venv/bin/streamlit run app.py- Open
http://localhost:8501to access the interactive clinician order interface and the live auditor panel.
.venv/bin/python run_benchmark.pyClinicalGuard AI adheres to strict de-identification rules:
- Zero Patient Names: All patient names, telephone numbers, emails, and SSNs are redacted at the intake node before reaching vector stores, tools, or models.
- Pseudo-Anonymized Identifiers: Patient records are identified strictly through synthetic hospital IDs (e.g.
PT-8821,PT-4490).