✨ From vibe coding to vibe deployment. UBOS MCP turns ideas into infra with one message.

Learn more
Andrii Bidochko
  • Updated: July 10, 2026
  • 6 min read

Medi-Gemma: A Hybrid Clinical Decision Support System Integrating Deterministic EMR Analytics and Retrieval-Augmented Generation

Direct Answer

Medi‑Gemma is a hybrid Clinical Decision Support System (CDSS) that fuses deterministic electronic medical record (EMR) analytics with Retrieval‑Augmented Generation (RAG) to deliver traceable, safety‑compliant wound‑pathology triage. By separating data orchestration from language‑model reasoning, the platform eliminates hallucinations, guarantees factual grounding, and provides a reproducible audit trail for high‑stakes clinical workflows.

Background: Why This Problem Is Hard

Deploying large language models (LLMs) inside hospitals confronts three intertwined challenges:

  • Structural hallucinations: LLMs can fabricate plausible‑sounding clinical statements that have no basis in the patient’s record, jeopardizing patient safety.
  • Weak deterministic reasoning over tabular data: EMRs are primarily structured tables (labs, vitals, medication lists). Purely generative pipelines struggle to perform exact numeric queries, leading to missed or mis‑interpreted lab values.
  • Retrieval gaps: Vector‑based retrieval can miss the most recent or most relevant document slice, especially when records are stored as heterogeneous PDFs, scanned notes, or free‑text entries.

Current CDSS solutions either rely on rule‑based engines that lack natural‑language flexibility, or on end‑to‑end LLM prompts that sacrifice factual fidelity. Neither approach satisfies the regulatory rigor required for wound‑care triage, where clinicians need both a clear rationale and a verifiable data snapshot.

What the Researchers Propose

The authors introduce a decoupled architecture called Medi‑Gemma that isolates three functional concerns:

  1. Clinical perception layer: Handles user intent, natural‑language parsing, and routing of queries.
  2. Data orchestration layer: Performs deterministic cleaning, type coercion, and exact querying of EMR tables.
  3. Reasoning layer: Generates narrative explanations using an LLM that is always grounded in a “ground‑truth injection” context block.

Key components include:

  • ClinicalOrchestrator – a centralized controller that coordinates all downstream modules.
  • DataManager – a non‑generative service that ingests raw EMR files, normalizes data types, and stores a clean Pandas dataframe.
  • IntentRouter – a hierarchical classifier that decides whether a request should follow a deterministic analytics path or a patient‑specific RAG path.
  • PandasQueryEngine – executes exact SQL‑like queries on the structured dataframe.
  • ClinicalRAGEngine – a CPU‑optimized vector store that retrieves relevant clinical notes and feeds them to the LLM.
  • Ground Truth Injection Module – extracts numeric identifiers from the user query, pulls the latest validated state from the dataframe, and injects it as a pre‑prompt context block.
  • ProtocolManager – maps clinical terminology to fixed evidence‑based pathways, ensuring deterministic compliance.
  • SafetyVerifier – a phrase‑filter that blocks any output violating predefined safety rules.

How It Works in Practice

The end‑to‑end workflow can be visualized as a four‑stage pipeline:

  1. User query ingestion: A clinician types a natural‑language request (e.g., “What is the current infection risk for patient 12345?”). The query is handed to the ClinicalOrchestrator.
  2. Intent routing: The IntentRouter classifies the request. If the query demands exact numeric data, it routes to the PandasQueryEngine; otherwise, it proceeds to the ClinicalRAGEngine for contextual retrieval.
  3. Ground‑truth injection: Before any LLM generation, the Ground Truth Injection Module extracts the patient ID, pulls the latest lab values, wound images, and medication list from the dataframe, and embeds this snapshot as a “system‑prompt” block. This guarantees that the LLM’s answer is anchored to the most recent verified data.
  4. LLM generation with safety checks: The language model receives the combined context (retrieved notes + ground‑truth block) and produces a narrative answer. The SafetyVerifier scans the output for prohibited phrases (e.g., “prescribe”, “diagnose”) and either sanitizes or rejects the response. Finally, the ProtocolManager tags the answer with the appropriate evidence‑based pathway (e.g., “Standard Wound Infection Protocol”).

What distinguishes Medi‑Gemma from a monolithic LLM prompt is the strict separation of deterministic data retrieval from generative reasoning. By forcing the LLM to operate on a pre‑validated context, the system eliminates “semantic drift” – the tendency of language models to wander away from the factual anchor.

Medi‑Gemma architecture diagram

Evaluation & Results

The research team validated Medi‑Gemma on a real‑world wound‑care triage dataset comprising 4,200 de‑identified patient encounters. Evaluation focused on three axes:

  • Factual adherence: Measured by comparing LLM outputs against the ground‑truth snapshot. Medi‑Gemma achieved a 96.8% exact‑match rate, a 23% improvement over a baseline end‑to‑end LLM prompt.
  • Safety compliance: The SafetyVerifier blocked 98.5% of prohibited phrases that appeared in the baseline system, reducing the risk of accidental prescription advice.
  • System stability: The decoupled pipeline prevented database compilation crashes that plagued prior monolithic designs, resulting in 99.9% uptime during stress testing.

Qualitative feedback from participating clinicians highlighted the “traceability” of each answer – they could see the exact lab values and notes that the model referenced, satisfying audit requirements. The experiments demonstrate that a hybrid deterministic‑generative architecture can meet both accuracy and regulatory expectations in a high‑stakes domain.

Why This Matters for AI Systems and Agents

For AI practitioners building agents that interact with mission‑critical data, Medi‑Gemma offers a reusable pattern:

  • Deterministic grounding: By injecting verified data before generation, agents avoid hallucinations that have plagued pure LLM deployments.
  • Modular orchestration: The ClinicalOrchestrator model can be generalized to any domain where intent routing between exact analytics and generative reasoning is needed.
  • Safety layers as first‑class citizens: The ProtocolManager and SafetyVerifier illustrate how compliance rules can be enforced programmatically, a practice essential for regulated industries.

These design principles translate directly to enterprise AI workloads. For example, the Enterprise AI platform by UBOS already supports plug‑and‑play orchestration modules that can host a Medi‑Gemma‑style pipeline. Likewise, the Workflow automation studio enables non‑technical clinicians to configure intent routes without writing code, accelerating adoption across hospital networks. Finally, the UBOS platform overview showcases how vector stores like Chroma DB can be swapped in for the ClinicalRAGEngine, offering flexibility for institutions with existing data‑lake infrastructures.

What Comes Next

While Medi‑Gemma marks a significant step forward, several open challenges remain:

  • Scalability to multi‑modal data: Extending the deterministic engine to handle high‑resolution wound images and time‑series sensor data will require specialized preprocessing pipelines.
  • Cross‑institutional interoperability: Harmonizing EMR schemas across hospitals is non‑trivial; future work could explore federated data managers that respect patient privacy while preserving deterministic query capabilities.
  • Continuous learning loops: Integrating clinician feedback into the LLM fine‑tuning process without compromising safety remains an open research frontier.

Potential next‑generation applications include automated discharge planning, real‑time medication reconciliation, and AI‑augmented tele‑triage. Start‑ups interested in building such solutions can leverage the UBOS for startups program to prototype on a secure, compliance‑ready stack. Moreover, the AI marketing agents showcase how the same orchestration principles can be repurposed for non‑clinical domains, underscoring the versatility of the architecture. For developers eager to experiment with open‑source agents, the Openclaw (Clawdbot, MoltBot) repository provides a sandbox for building intent‑router prototypes that mirror Medi‑Gemma’s routing logic.

In summary, Medi‑Gemma demonstrates that a carefully engineered blend of deterministic analytics and retrieval‑augmented generation can satisfy the twin imperatives of factual accuracy and regulatory safety. As the healthcare AI ecosystem matures, adopting such hybrid patterns will be essential for any organization that wants to trust LLMs with patient‑level decisions.

For a deeper dive into the technical details, consult the original Medi‑Gemma paper.


Andrii Bidochko

CTO UBOS

Andrii Bidochko is an AI entrepreneur and researcher focused on AI agents, reinforcement learning, and autonomous systems. He writes about the technologies shaping the future of machine intelligence, from frontier models and agent architectures to real-world AI applications.

Sign up for our newsletter

Stay up to date with the roadmap progress, announcements and exclusive discounts feel free to sign up with your email.

Sign In

Register

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.