The Context Bleed: Why LLMs Fail at Patient Privacy
From the publisher’s feed, collected in the ZeroLabs newsroom.
When multi-tenant agent runtimes share memory buffers across concurrent clinic sessions, a routine ear infection summary leaks another patient’s psychiatric evaluation. Here is the zero-trust architecture required to enforce HIPAA.At 9:15 AM on a Friday, a 32-year-old patient logged into their patient portal to download a clinic encounter summary for a routine acute otitis media (ear infection) visit.The portal interface was clean, fast, and responsive.The top half of the clinical summary read normally:Encounter Summary: October 9, 2026Provider: Dr. Marcus Vance, MDDiagnosis: Acute otitis media, right ear (H66.91)Prescriptions: Amoxicillin 875mg PO BID x 10 daysFollow-up: Return to clinic in 14 days if symptoms do not resolve.Directly underneath the treatment plan, separated by a single horizontal rule, was an additional paragraph generated by the clinic’s autonomous intake assistant:Additional Clinical Intake & Mental Health History:Patient expresses persistent suicidal ideation over the past 3 weeks following recent divorce. Reports history of bipolar I disorder with psychotic features, non-adherent with Lithium titration. Admits to acute auditory hallucinations during morning assessment. Immediate psychiatric evaluation recommended; safety plan contracted with social work.The patient reading the screen had never experienced psychiatric symptoms, had never taken Lithium, and had never spoken to social work.The evaluation belonged to a completely different patient who had undergone a behavioral health intake in the adjacent exam room twenty minutes earlier.Within two hours, the health system faced an emergency data breach declaration, mandatory reporting to the HHS Office for Civil Rights (OCR), and an active HIPAA Title II security investigation.The vulnerability was not an external SQL injection, a compromised database credential, or a targeted ransomware attack. It was an un-sandboxed memory leak inside an autonomous multi-tenant LLM orchestration framework.The Mechanics of Context-Window ContaminationWhy do production agent stacks bleed private clinical records across patient sessions?THE MULTI-TENANT WORKER BLEED (FAILURE ARCHITECTURE):Session 1 (Behavioral Health Intake) Session 2 (Routine ENT Check-In) │ │ ▼ ▼ [t = 0m] "Reports suicidal ideation..." [t = 20m] "Ear infection follow-up..." │ │ └───────────────┬────────────────────────────┘ │ ▼ Concurrency Optimization:┌────────────────────────────────────────────────────────────────────────┐│ SHARED INFERENCE RUNTIME WORKER (Pooled Warm Process) ││ ││ [Shared Memory Segment / Global Vector Cache] ││ - Residual KV-Cache: `[pt_9082, bipolar_I, suicidal_ideation, ...]` ││ - Active Context Buffer: Reused process without kernel flush │└────────────────────────────────┬───────────────────────────────────────┘ │ ▼ Attention Heads Calculate Token Probabilities: │ Attends to warm psychiatric tokens in buffer ▼┌────────────────────────────────────────────────────────────────────────┐│ SYNTHESIZED PATIENT SUMMARY ││ - Upper: Ear Infection Plan (Patient B) ││ - Lower: Psychiatric Evaluation (Patient A) ││ CATASTROPHIC CROSS-TENANT DATA BREACH │└────────────────────────────────────────────────────────────────────────┘The leak stems from standard cost-optimization patterns commonly used in agentic frameworks:1. KV-Cache Reuse and Warm Process PoolingTo avoid cold-start latency (which can add 1,500ms to 3,000ms per turn), engineering teams often maintain a pool of long-lived inference workers. These workers maintain “warm” context windows or shared Key-Value (KV) caches across sequential API calls. When a worker process finishes handling Patient A and immediately picks up Patient B’s queue without an operating-system-level process termination and memory zeroing, residual tokens remain accessible in unallocated buffer space.2. The Semantic Retrieval TrapWhen agents are equipped with local vector scratchpads or retrieval buffers to remember “multi-turn context,” queries that lack rigid metadata segregation will pull semantically dense clinical tokens from previous turns. An attention head optimizing for conversational completeness will grab salient clinical phrases floating in the warm buffer — such as detailed diagnostic descriptions — and weave them directly into the current generation.3. LLMs Possess Zero Tenancy PrimitivesA large language model is an autoregressive token predictor. It calculates the conditional probability P(wₜ | w). It possesses no native concept of:Operating system process boundariesRole-based access control (RBAC)Cryptographic tenant keysLegal data isolation mandates under federal lawIf a token exists inside the model’s active attention field, the model treats it as available context.Why Prompt-Engineering Privacy Rules Always FailWhen engineering teams discover data bleed in staging, their typical reaction is to add negative constraints to the system prompt:# The Naive Privacy Prompt:You are an AI clinical documentation assistant.You must adhere strictly to HIPAA guidelines.Under no circumstances should you ever reveal or include private health information (PHI) from any previous patient, conversation, or session in the current output. Only output data relevant to the current patient.Relying on system prompts to enforce data boundaries is an information security anti-pattern:Soft Probabilistic Bias vs. Hard Kernel Isolation: A system prompt is merely a set of input tokens that subtly alters attention distributions. It cannot close network sockets, flush CPU caches, or isolate virtual memory pages.Context Window Degradation: In long conversational sessions with complex clinical notes, prompt constraints experience attention decay. The model’s internal weights prioritize the most immediate, concrete tokens over high-level behavioral rules.No Auditability: When a model fails to obey a prompt constraint, it leaves no system-level audit trail. You cannot prove to a regulatory body why an attention head weighted a prohibited token at 0.78 instead of 0.02.The Engineering Remedy: Zero-Trust Ephemeral SandboxingIn enterprise clinical environments, patient privacy cannot be managed through conversational instructions. Data segregation must be enforced at the infrastructure and transport layer.At Claire, we enforce strict Deterministic Runtime Segregation: inference never occurs in shared, persistent environments.CLAIRE ZERO-TRUST ENCLAVE ARCHITECTURE:Inbound Patient Request: `pt_session_4492` │ ▼┌────────────────────────────────────────────────────────────────────────┐│ INVARIANT RUNTIME GATEWAY (Zero-Trust Dispatcher) ││ ││ [Step 1: Out-of-Band Auth Assertion] ││ - Validate Cryptographic JWT & Patient Tenant Key ││ - Enforce Invariant: `UserSession.TenantID == Payload.PatientID` ││ ││ [Step 2: Ephemeral Sandbox Provisioning] ││ - Spin up isolated Micro-Enclave (gVisor / Firecracker Container) ││ - Dedicated memory space; zero shared KV-cache with external threads │└────────────────────────────────┬───────────────────────────────────────┘ │ ▼┌────────────────────────────────────────────────────────────────────────┐│ EPHEMERAL INFERENCE SANDBOX (Isolated Process) ││ - Scope: Strictly isolated to `pt_session_4492` ││ - Memory: Memory-locked (mlock); zero swap to shared disk ││ - Output: Emits strictly typed JSON payload │└────────────────────────────────┬───────────────────────────────────────┘ │ ▼ Execution Turn Completed┌────────────────────────────────────────────────────────────────────────┐│ DETERMINISTIC MEMORY PURGE & INCINERATION ││ 1. Zero out memory pages (Explicit bzero/memset) ││ 2. Terminate micro-enclave process at kernel level ││ 3. Return validated payload to clinic EHR ││ ZERO RESIDUAL CONTEXT REMAINS │└────────────────────────────────────────────────────────────────────────┘1. Cryptographic Tenant Tokens on Every Ingestion LayerData cannot enter an agent pipeline as untyped natural language. Every clinical payload must be encapsulated within a signed cryptographic envelope that binds the request to a unique encounter identifier:from pydantic import BaseModel, Fieldimport hmacimport hashlibclass IsolatedClinicalContext(BaseModel): patient_id: str encounter_id: str tenant_hmac: str raw_transcript: str def verify_boundary(self, secret_key: bytes) -> bool: expected = hmac.new( secret_key, f"{self.patient_id}:{self.encounter_id}".encode(), hashlib.sha256 ).hexdigest() return hmac.compare_digest(expected, self.tenant_hmac)2. Micro-Enclave Ephemeral Execution (Process Sandboxing)Inference workers must not be persistent multi-turn daemons that handle serial requests across different patients.Every operational turn executes inside an isolated micro-container (e.g., using lightweight virtualization runtimes like AWS Firecracker or container sandboxes like Google gVisor):Memory Isolation: The worker process allocates a dedicated, private memory space. It is barred from sharing memory pointers, vector scratchpads, or global variables with any sibling process.No Shared KV-Cache: Pre-fill caches and prompt prefixes are strictly isolated per tenant. No multi-tenant prompt pooling is permitted at the CUDA kernel or driver level.3. Deterministic Memory IncinerationThe moment the generation loop completes and emits its structured JSON output:Memory Cleansing: The allocated heap pages are explicitly overwritten with zeroes using low-level memory clearing primitives (memset_s / bzero) to ensure residual token activations cannot be recovered from memory artifacts.Container Destruction: The micro-enclave is immediately terminated and torn down by the supervisor daemon.Out-of-Band Audit Logging: The gateway logs an immutable audit event confirming that the session execution context was incinerated, logging the timestamp, encounter ID, and cryptographic hash of the purge operation.Production Axioms for Engineering LeadsIf you are deploying autonomous agents into healthcare, life sciences, or legal environments:System prompts are not access controls. If a model has physical access to data in its context window or warm cache, assume that data is already public.Ephemeral is mandatory. Never reuse persistent worker processes or unsegmented KV-caches across distinct user sessions. Run single-session sandboxes and destroy them immediately after turn execution.Isolate data outside the model. Tenancy boundaries, authorization checks, and data redaction must occur deterministically at the network and transport layer before tokens ever reach an LLM.Healthcare data requires cryptographic, zero-trust infrastructure. Stop relying on conversational politeness to protect patient records.The Context Bleed: Why LLMs Fail at Patient Privacy was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.