Inspiration
Every year, 2 million people are hospitalized from adverse drug reactions. Around 100,000 die — not from their disease, but from the treatment.
Most of these reactions are predictable. They are written in the patient's genome. A CYP2D6 Ultra-Rapid Metabolizer converts codeine into morphine at 4× the normal rate. Prescribe standard codeine — you've ordered a fatal overdose. The doctor didn't know. Nobody checked the genome.
Pharmacogenomic tools exist. They live in separate systems, require manual lookup, and operate on a different timescale than a consultation. By the time the alert surfaces, the prescription is already signed.
The problem is not data. It is latency. We built PharmaShield to close that gap — in real-time, during the consultation, before the prescription is formed.
What it does
PharmaShield is a silent ambient sentinel. It listens to a doctor's consultation via Gemini Live, extracts the patient ID and drug name from the audio stream, and triggers a pharmacogenomic risk check against the patient's genetic profile in under 40 nanoseconds.
If a critical contraindication is detected, Gemini uses its native barge-in capability to interrupt the doctor with a voice alert — mid-sentence, before the prescription is signed.
The system covers:
- 9 CYP enzyme phenotypes — CYP2D6, CYP2C19, CYP2C9, CYP3A5, CYP2B6, UGT1A1, NAT2 and more
- HLA absolute contraindications — B*5701 (abacavir), B*1502 (carbamazepine), B*5801 (allopurinol), G6PD
- Phenoconversion — runtime override of genetic phenotype based on co-prescribed inhibitors and inducers
- Physiological deltas — renal severity, hepatic impairment, age >65 (Beers Criteria 2023), pregnancy, QTc prolongation
- 50 critical drug-drug interaction pairs from CPIC, FDA, and CredibleMeds
The most important design decision: Gemini makes zero clinical decisions. Every risk evaluation is delegated to a deterministic C++23 engine hardcoded from CPIC clinical guidelines. No inference. No probability. No hallucination.
How we built it
The architecture splits into two layers that never blur.
Gemini 2.5 Flash Live handles ambient listening, entity extraction, and voice barge-in. It extracts patient ID, drug name, current medications, and clinical context from the audio stream — and fires a tool call the moment it identifies both a patient and a drug. It does not evaluate risk. It extracts and delegates.
The C++23 Sentinel Core receives the tool call and runs a 5-step scoring pipeline:
- HLA / G6PD — absolute contraindications, early exit on match
- Phenoconversion — genetic → functional phenotype override via inhibitor/inducer tables
- PGx base score — CPIC-hardcoded rules per drug × phenotype
- Physiological deltas — renal, hepatic, age, pregnancy, QTc
- Drug-drug interactions — 50 critical pairs, bidirectional
The engine uses mmap + std::ranges::equal_range on a flat sorted binary file — 16 bytes per patient, alignas(16). The entire dataset fits in L3 cache. Clinical rules live in constexpr tables with compile-time FNV-1a hash collision detection via consteval. Software prefetching fires on every patient ID keystroke, warming L1 cache before Gemini fires the tool call.
The FastAPI orchestrator maintains a SessionContext per WebSocket session, accumulating clinical data across the consultation. Gemini Live audio is relayed at 256ms PCM16 chunks. Tool call responses are batched to prevent audio artifacts in the barge-in output.
On the data side: real pharmacogenomic records require strict institutional agreements. The demo runs on synthetic patients generated from gnomAD v4 allele frequencies via Hardy-Weinberg simulation. The science is real. The patients are not.
Challenges we ran into
GIL double-release SIGSEGV. The pybind11 binding released the GIL at the top of get_risks(), then called lookup() which released it again. py::list construction without the GIL caused a SIGSEGV on the first tool call. The fix was scoping the release strictly around C++ work, and reacquiring before touching any Python object.
Gemini tool call batching. Multiple simultaneous tool calls from a single turn caused fragmented FunctionResponse delivery, producing audio artifacts in the barge-in. Solved with a 400ms deferred batch flush before sending LiveClientToolResponse.
Phenoconversion branchless design. Modeling inhibitor stacking — two moderate inhibitors equaling one strong — required a carefully designed downgrade matrix with no runtime conditionals on the hot path. Getting the boundary cases right (EM + two moderate inhibitors → PM, not IM) required multiple iterations against CPIC documentation.
Clinical scope under time pressure. Implementing a medically defensible pharmacogenomic pipeline in a hackathon timeframe required a domain expert. Without Lilia's bioinformatics background, the star allele calling and CPIC rule implementations would not have been scientifically credible.
Accomplishments that we're proud of
Phenoconversion in real-time. No existing commercial PGx tool models phenoconversion at the point of prescription. We do — in a branchless C++ matrix lookup, evaluated in nanoseconds, on every single tool call. Patient 99999004 is genetically normal. Functionally lethal. Static tools miss it entirely.
The 40ns figure is not marketing. It is the steady-state cost of a warm-cache binary search on a properly structured dataset. The bottleneck is Gemini's TTFT. The safety layer never waits — and that asymmetry was a deliberate engineering statement.
Zero LLM clinical decisions. In a domain where hallucination is not a UX problem but a liability, we drew a hard boundary. Every clinical output is traceable to a specific CPIC guideline reference. No black box.
A genuinely useful demo. Eight hardcoded patients, each guaranteed to trigger a different class of alert — from HLA absolute contraindications to phenoconversion to triple drug-drug interaction hits. Judges can reproduce every scenario from a single voice sentence.
What's next for PharmaShield
Expand the drug database. The current pipeline covers ~50 critical drug-drug interaction pairs. A production-grade formulary requires integration with a licensed database — Micromedex or Lexicomp. That is the highest-priority clinical gap.
TPMT / NUDT15 full integration. The binary format has a reserved field for additional phenotypes. TPMT and NUDT15 — critical for thiopurine toxicity — are implemented in the Python pipeline but not yet fully wired into the runtime binary format.
Real patient data pipeline. The ETL pipeline (tools/data_transfo.py) is built and ready for MIMIC-IV + PharmGKB + NHLBI WGS data. The institutional access agreements are the bottleneck, not the engineering.
Regulatory pathway. PharmaShield is a research prototype. A production deployment requires FDA SaMD Class II clearance or CE MDR 2017/745 certification. The deterministic, auditable, guideline-hardcoded architecture was designed with that pathway in mind from day one.
EHR integration. The current system extracts clinical context from audio. Direct HL7 FHIR integration with the EHR would allow automatic patient context loading — eliminating the need for the doctor to mention age, renal function, or current medications verbally.
Built With
- c++23
- cmake
- fastapi
- gemini-2.5-flash
- googlecloudrun
- googlecloudstorage
- pybind11
- python
- uvloop
- vertexai
- webaudio
- websockets
Log in or sign up for Devpost to join the conversation.