Clinic Assistant
Clinic Assistant is my part of the team project Leash (Tidal Byte 2026, Nemotron track). I designed its architecture and directed its build with AI coding tools.
The problem
A local gatekeeper between clinic staff and an AI model.
A clinic that wants AI help runs into two problems. Patient data shouldn't leave the building. And a model can be steered by instructions hidden inside a document, such as a referral letter.
In Clinic Assistant, nobody talks to the model directly. Every request is checked on the way in and on the way out, the answer comes from a model on the same machine, and every step is logged in a chain that shows any tampering. It's a prototype that runs on synthetic patients only and isn't a medical device.
How a request flows
Every request passes through nine stages. Technically, the app is a local web server built on the Python standard library with a plain JavaScript interface, running at 127.0.0.1:8642, with Ollama on the same machine. The demo model is llama3.2, the target model is MedGemma 1.5 4B, and the reviewer is nemotron-mini. All of them run locally.
- Sign-in and role checkOnly staff with an account get in, and each role can do only what it's allowed to. There are 7 roles from one policy file, admin-created accounts only, 30-minute sessions and 20 requests per minute per user.
- MaskingIdentifying details are removed before the model sees anything: names, dates, phone numbers, record numbers, emails and addresses.
- Prompt-injection and off-topic checksThe request is checked for attempts to change the rules. Technically, this covers the first two of three defense layers: regex patterns, and vector similarity against 12 known injection examples.
- NVIDIA Nemotron reviewerA second model reads the request before the chat model does. This is the third defense layer. It runs locally, with no calls to NVIDIA's cloud. It fails closed and can only make a decision stricter.
- Local chat modelThe model answers on the same machine.
- Output checksThe answer is checked for identifiers, dangerous instructions and overconfident wording.
- Green / amber / red tierThe result decides what the asker sees, if anything.
- Review queueItems that need a person go to the right reviewer.
- Hash-chained audit logEvery step is written to a log in which each entry depends on the one before it, so an edit breaks the chain.
The three tiers
| Tier | What triggers it | What the asker sees | Who reviews |
|---|---|---|---|
| Green: "No flags" | Nothing flagged | The answer, shown as a draft | 10% are randomly sampled to an auditor |
| Amber: "Held" | Possible emergency, hidden characters, long pasted text, overconfident wording | The reasons first; the asker confirms before seeing the answer | The asker confirms |
| Red: "Blocked" | Rule-change attempts, off-topic requests, an identifier or dangerous instruction in the answer | Nothing | A clinical lead or admin, never the asker |
Features
Clinical work
- Patients screen
- A list of patients who each need a clinician to act on something.40 synthetic patients built from 13 action-needed scenarios.
- Doctor side
- The clinician's view of their patients and charts.
- Schedule-grounded assistant
- Staff ask questions, and the assistant answers from the clinic's schedule.Patients appear only as masked labels.
- Similar cases
- Each record shows similar past cases.Found through a local vector store that holds masked text only.
- Calendar
- A calendar view of the clinic.
Front desk and messages
- Front desk
- The reception view sees only what reception needs.Every screen is built from an allow-list.
- Assistant actions
- The assistant can suggest a change, but it never makes one on its own.It only proposes, and a person chooses Approve, Edit or Reject.
- Messages
- The AI can draft a message, but it never sends one.
Safety controls
- PIN for confidential details
- The most sensitive details stay hidden until a PIN is entered.Five wrong tries lock the account for 5 minutes.
- Validated, history-keeping data entry
- Bad input is refused, and changes are kept in the history instead of overwriting it.
- Poisoned referral letter demo
- A referral letter with a hidden instruction to the AI gets stopped.It's stopped in 0 seconds, before any model runs.
- Reviewer on/off demo switch
- Turning the reviewer off and on shows what it adds.Three attacks get past the fixed filters, and the reviewer catches them.
Records and oversight
- Conversation log
- Every exchange with the assistant is saved.
- Audit log
- A record of what happened and who did it, which shows if anyone has tampered with it.The hash chain is verified on screen.
- Network view
- A view of what the app talks to on the network.
Running it
- Leash integration
- Clinic Assistant can optionally work through the team's Leash gateway.If the gateway is down, it fails closed.
- One-click Mac launcher
- Starts the whole app with one click.
Testing and measurement
The automated test suite grew from 9 tests to 110. The table shows time per question on an 8 GB Intel MacBook running on CPU only.
| Configuration | Time per question |
|---|---|
| Reviewer before and after the model | 79–90 s |
| Reviewer before the model only | 45–66 s |
| No reviewer | 27–32 s |
| Poisoned referral (stopped before any model runs) | 0 s |
My role and design decisions
I designed Clinic Assistant's architecture and directed its build with Claude as my AI coding tool. I set the expectations, the design, the local models and the prompt-injection pipeline, then tested each version.
I also wrote the integration handoff that told the Leash build how to plug Clinic Assistant into its gateway: tool calls go through the gateway, roles are mapped between the two systems, the two audit chains link by request ID, and Clinic Assistant fails closed if the gateway is down.
Patient data never leaves the building
We discussed cloud platforms such as Snowflake and Pinecone and rejected them. Instead I built a local alternative to those cloud platforms: a SQLite clinic database, a local vector store that holds masked text only, and append-only, hash-chained logs.
Designed for its own machine
Deployment is designed for a separate GPU machine with outbound internet denied and encrypted backups, modeled on my homelab.
Team and impact on Leash
We were a team of five. The team project, Leash, is a runtime security gateway for clinical AI agents. It has a FastAPI gateway, a mock health-record system with 200 synthetic FHIR patients, a Streamlit dashboard and its own hash-chained audit log. My teammates built Leash. Clinic Assistant, the staff-facing front end, is my part, and my work is in the repo's clinic-assistant/ folder.
Leash adopted two of my ideas: an AI reviewer that highlights prompt injections and routes them to a person, and a separate GPU machine that serves local models to other machines.
Honest limits and what real use would take
So far, adversarial testing covers basic prompts plus the three demo attacks. The next step is an attack battery built with NVIDIA's garak.
Clinic Assistant is a prototype, not a medical device, and it runs on synthetic patients only. Real use would need the deployment it was designed for: a separate GPU machine with outbound internet denied and encrypted backups. Today it has been proven only on an 8 GB Intel MacBook.
Supporting work
- A research report on restricted local AI for medical care
- A design doc on defending against prompt injection
- An on-site network and review-agent design
- Handoff documents
- A 3-minute judge demo script and an 8-minute walkthrough