Skip to main content

From PDFs to Plain Language: Building an AI Medical Report Simplifier

Updated 7 min readMarkdown
From PDFs to Plain Language: Building an AI Medical Report Simplifier

Introduction

I had just finished building a mental health text classifier and wanted to build something completely different. Not another model. Something more practical.

I had never worked with PDF documents programmatically before, and that gap bothered me. Almost every hospital gives patients their lab reports as PDFs. They're easy to download and share, but most people can't make sense of what's actually written inside them.

I wanted to understand how applications read PDFs. So I picked a project that would force me to learn.

The result was an AI-powered web application that takes a digitally generated medical report, extracts its contents, and explains the results in plain language using Google's Gemini API.

It started as an excuse to learn PDF parsing. It ended up teaching me quite a bit more.

Why This Project

Medical reports are interesting documents.

Unlike essays or articles, they're packed with structured information: test names, measured values, reference ranges, units, and patient details. To a person without a medical background, most of it looks intimidating. To a computer, it's simply text inside a PDF.

I wasn't trying to build a medical product or solve healthcare problems. I simply wanted a real-world problem that would push me to learn document processing, REST APIs, and AI integration.

Medical reports turned out to be a perfect fit. Structured, real-world, and actually useful to people.

What the Application Does

The application accepts a digitally generated PDF lab report uploaded by the user.

The backend extracts the report text using PyMuPDF, sends that text to Google Gemini, and asks the model to return a structured JSON response instead of a paragraph. The frontend then presents that information in a cleaner format, highlighting abnormal values, displaying gender-appropriate reference ranges where applicable, explaining each parameter in plain language, and suggesting a few questions the patient could discuss with their doctor.

It isn't designed to diagnose conditions or replace medical advice. The goal is simply to make medical reports easier to understand.

Learning Objective: PDF Parsing

Before starting this project, PDF parsing felt almost magical.

You upload a document, call a library function, and somehow all the text appears.

I quickly learned it isn't that simple.

The biggest realization was that not all PDFs are actually text documents.

Digitally generated PDFs contain selectable text, which libraries like PyMuPDF can extract quite reliably.

Scanned reports are completely different.

They're just images embedded inside a PDF file. There's no text to extract, which means OCR becomes a completely separate problem.

That single distinction ended up defining the scope of the project. Rather than trying to solve both problems at once, I decided to support only digitally generated reports and mention that limitation clearly in the README.

Sometimes understanding what not to build is just as useful as understanding what to build.

How Everything Fits Together

The overall architecture stayed surprisingly simple.

User uploads PDF  →  FastAPI receives the file  →  PyMuPDF extracts text → Gemini analyzes the report  → Returns structured JSON → React renders the results

Each part has one responsibility.

FastAPI handles the upload.

PyMuPDF extracts the raw report text.

Gemini converts that text into structured information that the frontend can easily display.

React simply focuses on presenting the results in a readable way.

Keeping each component responsible for one job made debugging much easier later on.

I chose Gemini because it offered a free tier. Most other options required payment upfront, which wasn't practical for a learning project.

The Debugging

Like every project I've built so far, the interesting part wasn't writing the code.

It was figuring out why the code wasn't working.

The Wrong Model

The first API call returned a 404 error.

At first I assumed something was wrong with authentication or my request format. After checking the documentation more carefully, I realized I was trying to use a model that wasn't actually available for the API version I was calling.

The fix took seconds.

Finding the real cause took much longer.

The Free Tier Reminder

Once the requests finally started working, I immediately ran into another error.

429 : Resource Exhausted.

I'd simply reached the free-tier quota.

There wasn't a clever engineering solution here.

I had to wait for the quota to reset before continuing development.

It was a useful reminder that building with cloud AI APIs also means understanding their usage limits.

JSON That Wasn't Really JSON

The last issue was probably my favorite.

I asked Gemini to return JSON.

It did.

Sort of.

Instead of returning raw JSON, it wrapped everything inside markdown code fences.

Perfectly readable for a human.

Not valid input for json.loads().

The backend kept failing until I stripped those wrappers before parsing the response.

It was a small bug, but one that taught me an important lesson: when another system generates your data, never assume the format is exactly what you requested.

Prompt Engineering Was More Important Than I Expected

Initially, I wrote prompts the way I would talk to ChatGPT.

"Explain this medical report."

The responses were well written.

They were also completely unusable.

Every response had a different structure, different formatting, and different wording. That made building the frontend almost impossible.

The project became much simpler once I stopped asking for explanations and started asking for structured data.

Instead of requesting a paragraph, I asked Gemini to return only valid JSON matching a predefined schema.

That single change made the entire application much more reliable.

It also changed how I think about prompt engineering. Good prompts aren't just about getting better answers. Sometimes they're about getting answers your software can actually work with.

Small Design Decisions That Mattered

There are a few features I'm particularly happy with, not because they're complicated, but because they were intentional.

Rather than simply labeling values as "normal" or "abnormal," I highlighted abnormal parameters visually so they stand out immediately. Where medical reference ranges differ by gender, I asked the model to account for that instead of assuming one universal range.

One feature I especially liked was generating a few suggested questions patients could ask their doctor. The application shouldn't replace professional advice, but helping someone understand what they might want to ask felt genuinely useful without crossing that line.

Responsible AI, Again

If you've read my previous post about the Mental Health Classifier, this section will probably sound familiar.

Whenever I build something involving health-related information, I try to be explicit about what the application is and what it isn't.

This project simplifies reports.

It does not diagnose illnesses.

It does not replace a doctor.

It does not provide medical advice.

That disclaimer isn't there because it looks professional.

It's there because I think setting the right expectations is part of building software responsibly, especially in domains where incorrect information could affect someone's health.

What I Learned

This project started because I wanted to learn PDF parsing, but that's only a small part of what I ended up taking away from it.

I learned that extracting text is usually the easy part; getting reliable, structured information from that text takes much more thought. I learned that prompt engineering often has more to do with software design than with writing clever prompts. I also realized that integrating an LLM into an application isn't really about AI , it's about building a reliable pipeline around it, handling unexpected outputs, validating responses, and making sure every component has a single responsibility.

Perhaps the biggest lesson, though, is that projects become much more enjoyable when they're driven by curiosity rather than by trying to build the biggest thing possible. I started this project because I wanted to understand how PDFs work. Everything else grew naturally from that.

Where It Lives Now

The application is deployed with a React frontend on Vercel and a FastAPI backend on Render.

At the moment, it supports only digitally generated PDFs. Supporting scanned reports would require adding an OCR pipeline, which is something I'd like to explore in a future version.

Like my previous projects, it's not perfect.

But it's deployed, it works, and it taught me far more than I expected when I first decided to learn how to read a PDF.

Frontend: https://medical-report-simplifier-eta.vercel.app

GitHub: https://github.com/ishwarimulye/medical-report-simplifier

If you're also building ML projects as a student and want to talk about it, find me on GitHub or LinkedIn.

No comments yet. Be the first to comment.