MediTwin
An AI companion that checks any medication against your personal health profile, chronic conditions, allergies, current medications, and surfaces patient-specific interaction warnings.

The Problem
Drug labels are written for everyone, which means they're actionable for no one. A warning that matters enormously to someone with a heart condition is buried in the same wall of text shown to everyone else.
Research
The core design question was trust: an LLM alone will hallucinate drug facts, and raw FDA data alone is unreadable. The research phase was about finding the seam between them.
OpenFDA exposes the authoritative label, warnings, adverse reactions, drug interactions, usage, as structured fields. That became the ground truth. The LLM's job was narrowed to one thing it's genuinely good at: reading that ground truth against a specific person's health profile and explaining what applies to them.
The Solution
The pipeline is strictly sequential: fetch official FDA label data first, then pass it, together with the user's chronic conditions, allergies, and current medications, into a structured Gemini 1.5 Flash prompt. The model is never asked to recall drug facts, only to analyze provided ones.
The prompt enforces strict JSON across five analysis dimensions, and a regex-based fallback parser recovers structure when the model drifts, so the frontend never renders a malformed response.
The product spans four Next.js pages, landing, health profile, medication inquiry, results, with a Flask backend handling prompt orchestration and FDA retrieval.
- Sequential OpenFDA → Gemini pipeline; the LLM analyzes, never recalls
- Strict-JSON prompting with regex fallback parsing for resilience
- Five analysis dimensions rendered as scannable, personal guidance
- Four-page Next.js frontend, Flask REST backend
Technical Decisions
Ground the LLM in fetched FDA data instead of its own knowledge
In a health context, a hallucinated interaction is dangerous. Feeding the official label as context reduces the model's role to personalization and explanation, the part that's safe to delegate.
Trade-off: Two sequential API calls per query add latency versus a single LLM call; correctness won.
Strict JSON output contract with regex fallback
A structured five-dimension response lets the UI present guidance as scannable sections. The fallback parser handles the minority of responses where the model breaks format, instead of showing users an error.
Flask backend separate from the Next.js frontend
Prompt orchestration, FDA retrieval, and parsing are Python-shaped problems; keeping them behind a REST seam left the frontend simple and swappable.
What Didn't Go As Planned
Gemini intermittently wrapped its JSON in prose or markdown fences, breaking parsing.
Layered defenses: tightened the prompt contract, then added regex extraction that recovers the JSON payload from any wrapper, parse failures effectively disappeared.
OpenFDA label documents vary wildly, some drugs have rich structured fields, others near-empty ones.
Built the context assembler to degrade gracefully: it declares which sections were unavailable so the analysis is explicit about its own gaps rather than papering over them.
Outcome
MediTwin demonstrated the pattern I now reach for in every AI feature: authoritative data first, LLM as analyst rather than oracle, and a hard output contract between model and UI.
Reflection
I'd add a persistent profile store and medication history early, the profile currently lives per-session, which caps how personal the analysis can get. And I'd benchmark the pipeline against a pharmacist-reviewed test set to quantify, not just architect for, safety.