cd /news/ai-agents/i-built-an-ai-agent-for-nhs-cancer-w… · home topics ai-agents article
[ARTICLE · art-55348] src=pub.towardsai.net ↗ pub= topic=ai-agents verified=true sentiment=· neutral

I Built an AI Agent for NHS Cancer Waits. Its Best Feature Is the Question It Won’t Answer.

A developer built an AI agent for NHS cancer waiting times that refuses to predict individual wait times, instead providing honest historical odds for each trust. The agent uses a data pipeline to process NHS England's raw figures and presents the information in plain language, prioritizing transparency over false certainty.

read7 min views1 publishedJul 11, 2026

The idea didn’t come from a product meeting. It came while I was waiting for a coffee.

You order at Starbucks, and the app shows you where your drink is in the queue. Deliveroo draws a little map with your rider crawling towards your door. Even McDonald’s gives your order a number and a bar that slowly fills. Somewhere along the way we all quietly agreed that people deserve to know how long they’ll be waiting — for a flat white, a burger, a parcel.

Then I found myself thinking about the one wait that actually frightens people. You’re sitting in a hospital a few minutes after the word cancer has been said out loud, and there’s nothing. No bar filling up. No number. No little map. You wait, and nobody tells you for how long.

So I started wondering: what if you could look up your own hospital the way you check a takeaway — type in the name and see, honestly, how long people tend to wait there?

That question became my first AI agent. I went looking for the data to build it. And the most useful thing I learned was why I couldn’t.

The obvious version almost builds itself in your head. You type in your hospital and it tells you: your mum will wait about this many days.

The data won’t let you do that, and it took me a while to properly accept why. NHS England’s Cancer Waiting Times figures record patients who have already been treated — for each one, whether treatment started within 62 days of an urgent referral. It’s a rear-view mirror. A scoreboard of what already happened. There’s no personal forecast anywhere inside it.

To answer how long will she wait?, I’d have to invent a number. About someone’s cancer. At midnight, for a frightened person who’d take whatever I told them and hold on to it.

Because that’s the real user. Not an analyst — someone whose mum was urgently referred this afternoon, sitting up too late, typing how long will she wait at Shrewsbury? into a phone. Every decision in this thing traces back to that person.

So the agent refuses the forecast — out loud, not quietly. It says plainly that nobody can predict an individual’s wait. Then it gives the honest thing it can stand behind: the trust’s real track record, told as odds.

For Shrewsbury and Telford, on the 62-day standard, that’s roughly two in three — 65.2% of patients started treatment on time in September 2025. Below the 85% the NHS is meant to hit. A little below England’s 68.0%. But up from 56.4% two years earlier — a real improvement, honestly told. It says that in plain English, explains what the standard means, and links to the source so anyone can check it. It leads with “about two in three people” before it ever shows “65.2%”, because that’s how a worried person reads a number at midnight.

The refusal isn’t a limitation I’m apologising for. It’s the feature — the most honest thing the agent does is decline the one question everyone expects it to answer.

Curious how your local trust is doing? Explore the app.

https://nhs-cancer-waiting-times-pipeline-odkmcjhlgafcqtmo62ntmz.streamlit.app Say “AI agent” and most people picture the model doing the thinking. Mine is the opposite. The model is only the voice.

Underneath sits a proper pipeline. I take NHS England’s raw files — just over a million rows — and pull them through a Bronze, Silver and Gold refinement in pandas, cleaning and reshaping at each stage, until I’m left with one small, trustworthy table: one row per trust per month, covering two years and every trust in England.

Then comes the part that matters. When you name a hospital, plain Python — no model anywhere near it — works out every number and comparison in advance: the rounding, “below the 85% standard”, “slightly below England”, whether the trend is up or down, even which plain fraction to use for the odds.

Only after all that does the model get a look in. Claude Haiku — the smallest, cheapest one going — takes those finished facts and writes them into two to four plain sentences. It’s forbidden from introducing a single number of its own. The source line under every answer is stamped on by code, not the model.

That’s the whole philosophy in a sentence: my code computes every number; the AI only writes the sentence. The model can’t invent a statistic, because it never sees a raw one it has to work out. It’s handed the maths already done and asked only to say it kindly.

Hundreds of answers get regenerated every month, so I was never going to sit and proofread them. Instead of checking the output myself, I wrote something to check it for me — an automated test that reads every answer back against the data and against my own style rules before anything ships.

The first real run flagged dozens of hospitals, and the catches were fair. One answer said “about two in three people (100%)” — contradicting itself in five words. Another opened with “the good news is”, exactly the editorialising I’d banned. A third told people to “contact the trust directly”, advice I never wanted it giving. Good. That’s the checker doing its job.

Then the loop got stuck on a stubborn handful of hospitals, and this is the part I keep coming back to. The test wasn’t catching the model any more. It was catching bugs in my own code.

My logic had no plain-English phrase for a trust sitting at 0%, so it cheerfully told the model that a 0% trust was “one in ten”. My checker flagged a trust for mentioning GPs — it was literally named Gp Care Uk Limited. And in one case the test demanded the exact figure “0%” when the model’s own “none of the patients” was simply better English than the rule I’d written.

None of those were AI mistakes. They were mine. I fixed the three bugs and the loop went to zero. That lesson has stuck with me more than any clever part of the build: check your own machine, because the machine that most needs checking is usually the one you wrote. Months later I re-ran the whole thing on a fresh month of data — it passed all 362 answers first time. The fixes had held.

There’s no agent framework here. No vector database. No hosted database at all. Just a small file, some tidy Python, and the cheapest model tier — because phrasing facts that have already been decided is the easiest thing a language model ever does, and paying for more would have been paying for nothing.

Better still, those answers are generated once a month in a batch that costs pennies. The public app makes no live AI calls. It holds no API key. It runs for free. The biggest hosting risk — a leaked key — disappears, because there isn’t one.

And where I could have flattered the numbers, I didn’t. Shrewsbury’s improvement is measured from its true first month in the data, not from its lowest point, which would have made the climb look steeper. A smaller honest claim beats a bigger shaky one — especially when the entire promise of the tool is that you can trust what it tells you.

There’s one honesty problem I haven’t solved. The most recent month or two of NHS data is provisional — trusts revise it — and the smallest trusts treat so few patients that a single case can swing the percentage. Right now the agent reports those figures as confidently as any other, and it shouldn’t. The next version won’t: I’ve already left room for a confidence layer that flags a figure as provisional, or a trust as too small to read much into, in the same plain English as everything else. Being honest about what the data can’t tell you was the whole point — this just carries it one step further.

If you’d like to see the honest version of how is my hospital doing on cancer waits? it’s live — type in your local trust, or follow Shrewsbury and Telford from the example above. The code is on GitHub too, if you’d like to see exactly how the AI is kept on its leash. This began as a simple question about cancer waits. It’s left me with a harder one, and I don’t think it’s going away: how do you make a difficult public system legible to the people who depend on it?

I Built an AI Agent for NHS Cancer Waits. Its Best Feature Is the Question It Won’t Answer. was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.

── more in #ai-agents 4 stories · sorted by recency
── more on @nhs england 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/i-built-an-ai-agent-…] indexed:0 read:7min 2026-07-11 ·