Inspiration

Medical misinformation is one of the most dangerous failure modes of AI. When someone asks ChatGPT about drug interactions or symptoms, they get a confident answer but no way to know if it's actually correct. Studies show LLMs hallucinate medical facts at alarming rates, citing nonexistent studies and recommending withdrawn drugs. I built MedGuard because I believe medical AI shouldn't just sound right, it should prove it's right.

What it does

MedGuard is a medical Q&A system that runs every AI-generated answer through 8 independent verification layers before presenting it to the user. Each claim gets a confidence score backed by NLI entailment checking, entity verification, self-consistency sampling, source attribution, temporal validity, cross-claim contradiction detection, RAGAS-style atomic faithfulness scoring, and retrieval precision/recall analysis.

The composite confidence score is computed as:

\( C = 0.20 \cdot E_{nli} + 0.10 \cdot E_{ent} + 0.15 \cdot S_{cons} + 0.15 \cdot A_{src} + 0.05 \cdot T_{temp} + 0.05 \cdot X_{cross} + 0.20 \cdot F_{atom} + 0.10 \cdot R_{util} \)

Claims below the safety threshold get flagged and hedged automatically. Users can expand any claim to see exactly why it was scored the way it was, full transparency, no black boxes.

The app also features voice accessibility. You can ask questions by voice using the Web Speech API and listen to verified answers through ElevenLabs text-to-speech.

How I built it

The backend is a LangGraph multi-agent pipeline with 5 specialized agents. The Retrieval Agent fetches relevant medical sources via RAG. The Reasoning Agent generates answers using Gemini 2.5 Flash Lite with temperature set to 0.0 for determinism. The Hallucination Detector runs all 8 verification checks per claim. The Safety Agent computes composite scores and flags or hedges low-confidence claims. Finally, the Output Agent structures the final response with citations and scores.

The frontend is a React app that streams results in real-time, showing a thinking animation as each verification layer runs. Claim cards are expandable to reveal individual check scores with progress bars.

For atomic faithfulness, I decompose each claim into atomic facts and verify each one individually against source text, inspired by the RAGAS evaluation framework. For retrieval utilization, I structurally measure what fraction of retrieved documents were actually used (precision) and what fraction of claims have supporting sources (recall).

Challenges I ran into

Getting 8 verification checks to run efficiently was the biggest engineering challenge. Naive sequential execution made response times unacceptable. I also had to carefully tune the composite score weights so that no single check could dominate the final confidence score. Balancing sensitivity (catching real hallucinations) against specificity (not flagging correct claims) required a lot of iteration.

Integrating voice I/O without adding latency to the core verification pipeline meant I had to run TTS asynchronously and only on verified answers.

What I learned

LLM hallucinations in medicine aren't random. They follow patterns like outdated guidelines, citation fabrication, and entity confusion, and those patterns can be systematically detected. I also learned that no single verification method catches everything, so layered defense is essential. Most importantly, transparency matters more than accuracy scores. Users trust systems they can actually inspect.

What's next for MedGuard

I want to fine-tune medical NLI models for higher entailment accuracy, integrate real-time PubMed and clinical trial databases, build a provider-facing dashboard for clinical decision support, and add multilingual verification for global accessibility.

Built With

Share this project:

Updates

Submission history