- The paper introduces Medi-Gemma, a system that integrates deterministic EMR analytics with retrieval-augmented generation to eliminate hallucination and ensure traceability.
- It decouples data orchestration and LLM-based reasoning through specialized modules like DataManager, IntentRouter, and ClinicalRAGEngine to enforce factual consistency and safety.
- Validation on wound care datasets demonstrated that Medi-Gemma reliably standardizes EMR data, isolates deterministic analytics, and maintains up-to-date patient-specific context.
Medi-Gemma: A Hybrid Architecture for Clinical Decision Support with Deterministic EMR Analytics and Retrieval-Augmented Generation
Introduction
The Medi-Gemma system addresses limitations of conventional LLM deployments in clinical settings, particularly the inability of generative models to maintain deterministic fidelity when reasoning over structured Electronic Medical Records (EMRs) and the susceptibility to semantic retrieval omissions inherent in standard Retrieval-Augmented Generation (RAG) systems. This architecture introduces a decoupled agentic framework in which deterministic analytics, retrieval pipelines, and rule-based safety modules operate in concert to ensure traceability, reproducibility, and adherence to current clinical state, thereby improving the reliability and safety of computational decision support in critical healthcare domains.
Hybrid System Architecture
Medi-Gemma's system design separates clinical perception from data orchestration, anchoring all patient-specific reasoning in the latest validated EMR data. The core computational workflow consists of several dedicated modules:
- DataManager: Preprocesses and normalizes heterogeneous EMR files through rigorous type coercion, schema unification, and null-value management, enabling consistent analytical operations on both structured and narrative data.
- IntentRouter: Employs hierarchical rule-based classification to direct incoming clinician queries to appropriate execution tracks—deterministic statistical analytics via the PandasQueryEngine or patient-specific clinical pipelines via the ClinicalOrchestrator and ClinicalRAGEngine.
- PandasQueryEngine: Executes exact analytics using programmatic code generation interpreted against the preprocessed EMR dataframes, eliminating hallucination-prone numerical reasoning by generative LLMs.
- ClinicalOrchestrator & Ground Truth State Injection: For patient-specific queries, the orchestrator extracts unique identifiers, retrieves the most recent validated clinical encounter from the structured data store, and injects this context as an immutable grounding block into the LLM prompt, explicitly instructing the model to treat these facts as authoritative.
- ClinicalRAGEngine: Policy-restricted vector retrieval, using patient identifiers as metadata filters, restricts semantic searches strictly to the relevant patient context, further safeguarding against cross-record hallucinations or contamination.
- ProtocolManager and SafetyVerifier: Layered deterministic safety enforcement maps recognized clinical entities to fixed risk pathways and filters model outputs for hazardous or noncompliant language, overriding unsafe generations with rule-compliant alerts.
This modular pipeline is orchestrated such that deterministic data flows and generative inference are maximally decoupled—with ground truth state always injected upstream of flexible LLM-based reasoning—thus supporting auditability and factual consistency throughout clinical workflows.
System Validation and Numerical Results
System validation was conducted on de-identified wound care datasets simulating diverse clinical scenarios. Key findings:
- Reliable ingestion and normalization: DataManager reliably mapped disparate patient records with varying schema, missingness, and unconventional values into a standardized EMR representation, enabling uninterrupted downstream analytics.
- Deterministic analytics isolation: IntentRouter successfully routed cohort-level statistical queries directly to PandasQueryEngine, guaranteeing mathematically precise responses without invoking text generation. This avoided fabrication of analytical outputs endemic to vanilla LLM approaches.
- Ground Truth Injection impact: All patient-specific tasks entailed extracting up-to-date wound metrics, encounter details, and clinical documentation for prompt enrichment. This mechanism eliminated temporal inconsistencies and ensured factual grounding, with system outputs always referencing the latest available patient data over potentially outdated retrieved context.
- Safety enforcement: ProtocolManager consistently mapped output recommendations to well-specified clinical severity tiers based on evidence-based criteria, and SafetyVerifier replaced unauthorized generative outputs with structured alerts.
These architectural decisions produced substantial improvements in semantic stability (elimination of context drift), prevention of execution failures (database compilation errors mitigated), and enhancement of factual adherence relative to conventional RAG and end-to-end LLM systems.
Implications and Theoretical Impact
The explicit modularization between deterministic analytics and generative reasoning in Medi-Gemma represents an operational paradigm likely to be essential for clinical AI. By integrating Ground Truth State Injection, the architecture enforces an invariance principle: all downstream reasoning is strictly conditioned on the most recent structured clinical facts, thus preventing sequence drift and model hallucination even in highly dynamic or longitudinal clinical domains.
Practically, this approach facilitates traceable clinical decision support, enabling high-confidence automation in risk stratification, data summarization, and patient triage. The safety layers enforce strict compliance with protocolized standards of care, supporting regulatory alignment and reduced risk of inappropriate recommendations.
On the theoretical plane, Medi-Gemma demonstrates that robust hybridization of deterministic computing with LLM-based semantic modeling can overcome the epistemic brittleness of foundation model architectures in contexts where recent, high-fidelity state awareness is non-negotiable.
Limitations and Directions for Future Work
The prototype is currently validated on simulated data and wound-care-specific workflows rather than live production environments. Clinical generalizability is presently limited by its protocol lexicon and ontological scope, requiring extension for domain-wide deployment. Additionally, the system's dependence on underlying EMR data completeness and quality means downstream recommendations are still limited by input fidelity, even with deterministic retrieval.
Future iterations will focus on integration with HL7 FHIR or analogous interoperability standards, incorporation of multimodal reasoning (merging EMR, imaging, and lab analytics), and extension to multi-agent pipelines allowing collaborative specialization among protocol agents. Adaptive intent routing using trained classifiers, with persistent separation of deterministic computation, is also foreseen.
Conclusion
Medi-Gemma presents a modular, agentic Clinical Decision Support System combining deterministic EMR analytics, retrieval-augmented LLM reasoning, and layered safety enforcement to achieve traceable, semantically grounded clinical recommendations. By decoupling quantitative analytics from generative inference and deterministically injecting the latest patient state, the architecture addresses key failure modes of conventional medical AI, especially hallucination and context drift. This design represents a rigorous blueprint for trustworthy AI-assisted healthcare computation, supporting both current clinical needs and future expansion toward multimodal, multi-agent reasoning environments.