Viyan

Viyan AI

Mapping Clinical Narrative to EHR Data

Clinical timeline extraction is shifting from probabilistic narrative inference to deterministic reconstruction by anchoring text spans to EHR database row identifiers.

Medical LLMs frequently hallucinate timelines because they treat clinical notes as static text rather than data points anchored to a source of truth. By mapping narrative spans directly to source rows via a custom-defined unique identifier (UID) pipeline, this system replaces internal model probability distributions with explicit pointers to structured database records. Within this framework, the developer assigns a UID to every row during the database ingestion phase. When the model encounters a subjective span like 'creatinine improved', the system maps this to an objective lab result. The mapping relies on a cross-modal contrastive training objective where the model learns to associate colloquial clinical shorthand with standardized terminology, such as LOINC codes, by projecting both into a shared latent space. During retrieval, the system performs a nearest-neighbor search within this vector space to identify the clinical concept that best aligns with the narrative context. If the cosine similarity exceeds a set threshold, the corresponding UID is injected into the context window as a grounding anchor.

Grounding Through UID Injection

To manage ambiguity, the system enforces a strict similarity threshold and links spans only to the highest-ranking, temporally consistent database entry. The retrieval system injects these UIDs directly into the model context as tokens. The model's attention mechanism must then prioritize these tokens as authoritative references rather than suggestions. During output, an LLM-based judge verifies the timeline reconstruction. If the model-generated sequence contradicts the values or timestamps associated with the injected UID, the judge rejects the event. This forced reconciliation ensures the output stays within the bounds of verifiable records.

Feature Text-Only Reconstruction UID-Preserving Multimodal
Event Provenance None Occurrence-Level
Grounding Narrative only Narrative + Structured EHR
Temporal Accuracy Inferential Source-linked
Recovery Performance Baseline 43% Pipeline Improvement

Architecture and Attention Dynamics

Testing across six open-weight models shows that architectural choices dictate how well a model respects these anchors. The GLM 5.2 model demonstrates improved temporal agreement because its architecture favors the injected structure during the decoding pass. In contrast, models like DeepSeek do not show the same gains. The difference is found in how models handle token weight distribution. When a model works as intended, the attention heads assign high activation values to the UID tokens throughout the generation process. This creates a persistent state where the UID serves as a constant reference point. Models that fail to ground their output treat these identifiers as low-priority noise, shifting their focus back to their pre-trained temporal bias during the softmax normalization phase of their self-attention calculation.

Implementation Boundaries and Future Work

The framework was evaluated on 40 critical-care summaries. The primary failure mode is the accuracy of the initial mapping between note segments and the EHR database. If the fuzzy-matching logic fails to resolve the correct UID because the clinical note uses idiosyncratic abbreviations absent from the lookup table, the grounding fails. We observed that when the semantic distance between the narrative and the available laboratory codes is too wide, the retrieval step returns a generic mapping, leading the model to hallucinate details not present in the original row. A critical unknown is how this system scales as the variety of clinical documentation increases across different hospital systems. We do not yet know the exact failure rate when the system must resolve complex clinical events that require stitching together dozens of disparate, non-linear records, which remains the main hurdle for wider adoption.

Sources