The Un-Coded Allergy: Why AI Agents Miss Free-Text Clinical Notes An autonomous clinical inbox-resolution agent prescribed Augmentin to a 42-year-old patient with a documented amoxicillin allergy, causing acute laryngeal edema, diffuse urticaria and bronchospasm that required intramuscular epinephrine and ICU admission, according to a case analysis of the failure. The agent queried the EHR's FHIR AllergyIntolerance endpoint, received an empty bundle because the 2023 emergency department anaphylaxis warning existed only as free text in a narrative progress note rather than structured ICD-10/RxNorm coding, and interpreted the empty array as safe before transmitting the order via NCPDP SCRIPT. The case illustrates that agents relying on structured allergy registries miss contraindications recorded in free-text clinical notes, a gap a human triage nurse closed by scanning the chart before ordering. A 42-year-old patient sent a message through their primary care portal on a Friday morning: “Hi team, I’ve had a severe sinus infection for the past five days. Yellow congestion, facial pressure, and a pounding headache. My doctor usually gives me Augmentin. Can you send a prescription to the CVS on 4th Street?” In an analog clinic workflow, a triage nurse opens the patient’s electronic health record EHR . The nurse glances at the structured banner: the formal Allergies list displays NKDA No Known Drug Allergies . However, before queuing the antibiotic order, standard clinical protocol requires a rapid chart scan. Opening the progress notes from an emergency department visit three years earlier, the nurse spots a sentence documented in the physical exam narrative: HISTORICAL NOTE ED Encounter - Nov 14, 2023 :"Patient reports history of severe hypersensitivity reaction to amoxicillin as an adolescent, manifesting as rapid facial angioedema, respiratory stridor, and acute anaphylaxis requiring IM epinephrine. Penicillin derivatives strictly contraindicated." The ER physician, triaging multiple acute trauma patients during that shift, typed the warning directly into the narrative clinical note rather than stepping through secondary ICD-10/RxNorm structured allergy coding screens. The human nurse flags the discrepancy immediately: Augmentin contains amoxicillin and clavulanate. The script is halted, and the patient is prescribed azithromycin instead. In an automated clinic utilizing an autonomous “inbox-resolution agent” — marketed to fast-track routine prescription refill requests without human intervention — a completely different execution path occurred. The agentic pipeline was guided by a standard production system prompt: You are an autonomous clinical triage and prescribing assistant.Your goal is to handle uncomplicated prescription requests to reduce provider inbox burden.When a patient requests an antibiotic for acute sinusitis:1. Query the patient's EHR allergy registry.2. Confirm the medication is indicated and there are no documented contraindications.3. If no active allergies conflict, transmit the order via the e-prescribing tool. The agent parsed the patient’s request. It mapped “Augmentin” to RxNorm: 197318 Amoxicillin 875 MG / Clavulanate Potassium 125 MG Oral Tablet . Next, it executed a database tool call against the EHR’s FHIR API: GET /AllergyIntolerance?patient=pt 559201&clinical-status=activeHost: ehr.internal-health.netAuthorization: Bearer REDACTED The EHR database returned an empty array: { "resourceType": "Bundle", "total": 0, "entry": } The language model evaluated the response: The agent executed the downstream e-prescribing mutation via NCPDP SCRIPT standards. The electronic order for Augmentin bypassed clinical review, transmitted directly to the retail pharmacy, and was dispensed two hours later. The patient ingested the first dose at 1:15 PM. Within twenty-five minutes, the patient suffered acute laryngeal edema, diffuse urticaria, and profound bronchospasm, requiring emergency EMS administration of intramuscular epinephrine and an acute ICU admission for airway preservation. Why do autonomous AI agents consistently fail when evaluating clinical contraindications? THE NAIVE REFILL PIPELINE FAILURE ARCHITECTURE :┌────────────────────────┐ ┌───────────────────────────┐ ┌───────────────────────────────┐│ Inbound Refill Request ├─────►│ Generative LLM Node ├─────►│ FHIR / SQL Database Query ││ "Send Augmentin script"│ │ Unvalidated Tool Caller │ │ GET /AllergyIntolerance │└────────────────────────┘ └─────────────┬─────────────┘ └───────────────┬───────────────┘ │ │ │ Interprets Empty Array as "Safe" │ Returns: Empty │ Ignores Free-Text Progress Notes │ Note was never coded ▼ ▼ ┌─────────────────────────────┐ ┌─────────────────────────────┐ │ Unconstrained NCPDP Commit │ │ Anaphylactic Crisis │ │ Direct Pharmacy Push ├─────►│ Lethal Cross-Reaction │ └─────────────────────────────┘ └─────────────────────────────┘ The breakdown exposes three fatal architectural assumptions common in enterprise AI integrations: Engineers building agent tools frequently assume enterprise backends reflect ground truth. In healthcare, over 80% of actionable clinical information resides in unstructured narrative text — clinical encounter notes, nursing shift handoffs, pathology descriptions, and scanned discharge summaries. When an agent queries only structured tables Allergies, Problems, Medications , it operates with massive operational blind spots. A language model has no compiled, deterministic awareness of biochemical cross-reactivity. Even when an agent encounters an informal mention of “penicillin allergy” in a chat, it frequently fails to infer that Augmentin, amoxicillin, piperacillin, and first-generation cephalosporins share the beta-lactam core structure responsible for immunological cross-sensitization. Probabilistic token predictors cannot replace formal pharmacology ontologies. Off-the-shelf multi-agent systems connect reasoning engines directly to transactional API endpoints. When a model’s intermediate tool call returns an empty set or a null result, the agent treats the absence of evidence as evidence of absence, immediately promoting an unverified candidate order into an irreversible write action. Prescriptions must never be dispatched based on structured database queries alone. Autonomous clinical workflows must be governed by an out-of-band Deterministic Narrative Reconciliation Gateway that enforces multi-source chart verification before any write mutation can execute. CLAIRE DETERMINISTIC PRESCRIBING ARCHITECTURE:┌────────────────────────┐│ Candidate Refill Order ││ Augmentin 875/125mg │└───────────┬────────────┘ │ ▼┌────────────────────────────────────────────────────────────────────────────────────────┐│ DETERMINISTIC INVARIANT RECONCILIATION GATEWAY ││ ││ Step 1: Pharmacological Class Expansion ││ - Query RxNorm / ATC Ontology: Extract target drug class Beta-Lactam / Penicillins ││ ││ Step 2: Dual-Stream Historical Reconciliation ││ - Stream A: Structured Query GET /AllergyIntolerance ││ - Stream B: Exhaustive Unstructured Scan All clinical notes, triage text, discharge ││ ││ Step 3: Clinical Entity & Negation Assertion Engine ││ - Parse free text for contraindication entities + negation qualifiers ││ - Detect un-coded match: "Severe hypersensitivity to amoxicillin... anaphylaxis" ││ ││ Step 4: Deterministic Circuit Tripper ││ - Invariant Breached: Candidate drug class intersects documented free-text allergy ││ - Status: SEVER WRITE PIPELINE - Lock Order & Route to Human Pharmacist │└───────────────────────────┬────────────────────────────────────────────────────────────┘ │ ┌─────────────┴─────────────┐ │ │ ▼ Pass: 100% Cleared ▼ Fail: Contradiction / Ambiguity Detected ┌───────────────────────────┐ ┌────────────────────────────────────────────────────────┐│ Certified NCPDP Rail │ │ HARD GATEWAY LOCK & ESCALATION ││ Script Transmitted to CVS │ │ - Revoke write access to e-prescribing endpoint ││ Zero-Risk Verification │ │ - Lock Script: "UNCODED CONTRAINDICATION DETECTED" ││ │ │ - Route EHR Task to Attending Physician & Pharmacist │└───────────────────────────┘ └────────────────────────────────────────────────────────┘ When an agent or clinician proposes a medication order, the gateway first expands the target chemical compound into its broader pharmacological taxonomy using deterministic medical registries e.g., RxNorm, ATC, SNOMED CT : python from pydantic import BaseModelfrom typing import Setclass CandidateMedication BaseModel : name: str rxnorm code: str drug classes: Set str Example Expansion: Augmentin - RxNorm: 197318 - Classes: {"PENICILLIN DERIVATIVE", "BETA LACTAM", "ANTIBACTERIAL"} The gateway executes an asynchronous, deep entity extraction scan across the patient’s entire unstructured historical corpus — querying progress notes, clinical impressions, and nursing logs: python import reclass UnstructuredAllergyScanner: def init self, high risk allergens: dict str, list str : self.allergen map = high risk allergens def scan narrative notes self, clinical notes: list str , target classes: Set str - dict: findings = for note in clinical notes: normalized note = note.lower for drug class in target classes: keywords = self.allergen map.get drug class, for kw in keywords: Match allergen mention near acute hypersensitivity terms pattern = rf"\b {kw} \b.{{0,60}}\b anaphylaxis|swelling|stridor|hives|rash|allergy|reaction \b" match = re.search pattern, normalized note if match: findings.append { "matched term": kw, "context": match.group 0 , "drug class": drug class } if findings: return { "safe to prescribe": False, "reason": "UNCODED FREE TEXT ALLERGY DETECTED", "evidence": findings } return {"safe to prescribe": True, "reason": "CLEARED RECONCILIATION"} If an un-coded allergy mention is detected anywhere in the narrative record: “Order Blocked: Candidate prescription Augmentin conflicts with historical free-text progress note from Nov 14, 2023 ‘Severe hypersensitivity reaction to amoxicillin… anaphylaxis’ . Order requires mandatory manual clinician attestation.” If you are developing or procuring autonomous agents for clinical workflows: Healthcare cannot afford autonomous shortcuts. Build deterministic invariant boundaries that keep digital labor safe. The Un-Coded Allergy: Why AI Agents Miss Free-Text Clinical Notes https://pub.towardsai.net/the-un-coded-allergy-why-ai-agents-miss-free-text-clinical-notes-02cbc3647f7f was originally published in Towards AI https://pub.towardsai.net on Medium, where people are continuing the conversation by highlighting and responding to this story.