Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

🛡️ ClinicalGuard AI

An AI-First Clinical Safety Platform Powered by Cyclic Agentic Orchestration, FastMCP Stdio Tools, ChromaDB Grounded RAG, and Human-in-the-Loop SBAR Escalation.

Evaluation Status Emergency Recall Tool Standard Architecture


📌 Executive Summary

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.


🏛️ Core Implementation Pillars

                       ┌──────────────────────────────┐
                       │   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   │
└──────────────────────────────┘                └──────────────────────────────┘

1. Cyclic Agentic Orchestration

  • Stateful Graph via LangGraph: Avoids naive linear prompt chains. Implements a stateful AgentState graph 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-anonymized Patient 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.

2. Standardized Tool Integration (FastMCP)

  • Model Context Protocol (MCP): Utilizes FastMCP exposing 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=True in 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).

3. Verifiable RAG Grounding & Provenance

  • 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.

4. Trust, Safety, Confidence & Human Escalation

  • 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.

5. Observability & Systematic Evaluation

  • 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)

6. Zero-Cost, Production-Ready Packaging

  • 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.

📊 Benchmark Scorecard

Run the automated test runner:

.venv/bin/python run_benchmark.py

Results Summary:

================================================================================
  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)
================================================================================

🚀 Quickstart & Usage

1. Environment Setup

# 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

2. Launch Dual-Panel Streamlit Application

.venv/bin/streamlit run app.py
  • Open http://localhost:8501 to access the interactive clinician order interface and the live auditor panel.

3. Run Automated Safety Benchmark

.venv/bin/python run_benchmark.py

🔒 Privacy & HIPAA Sovereignty

ClinicalGuard 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).

👨‍💻 Project Repository

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages