cd /news/artificial-intelligence/the-un-coded-allergy-why-ai-agents-m… Β· home β€Ί topics β€Ί artificial-intelligence β€Ί article
[ARTICLE Β· art-152145] src=pub.towardsai.net β†— pub= topic=artificial-intelligence verified=true sentiment=↓ negative

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.

by read6 min views2 publishedOct 18, 2026

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

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:

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 was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.

── more in #artificial-intelligence 4 stories Β· sorted by recency
── more on @augmentin 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain β€” perfect for shipping the agent you just read about.

$git push zahid main
β†’ Live at https://your-agent.zahid.host βœ“
Get free account β†’ Pricing
from €0/mo Β· no card required
LIVE [news/the-un-coded-allergy…] indexed:0 read:6min 2026-10-18 Β· β€”