By Naman Gundaniya

HIPAA-Aware LLM Apps: Keeping PHI Out of the Prompt

A HIPAA-aware LLM app treats the model call as a boundary. Decide for each feature whether the model needs protected health information at all; if it does not, de-identify or tokenise before the prompt. If it does, send it only to a service covered by a business associate agreement, send the minimum necessary, and log every call. Your compliance team still decides what is permitted.

An isometric sorter takes health record cards from a conveyor, drops identifying details into a locked vault and passes clean cards to an AI chip.

US healthcare teams ask me a version of the same question: can we use an LLM on this data? The honest answer is "it depends on the architecture", and the architecture is mostly about where protected health information (PHI) flows. This post walks through the design I use, as general engineering guidance. It is not legal advice; your privacy officer and counsel decide what your organisation may do.

Which parts of an LLM app actually touch PHI?

Every component that receives, stores or transmits PHI is in scope, and in an LLM feature that list is longer than the model call. Draw the data flow before writing code and mark each hop.

The usual suspects:

  • The prompt builder, which pulls records and assembles context.
  • The model provider, which receives the prompt and returns a completion.
  • Retrieval stores: vector databases and the embeddings in them, which are derived from source text.
  • Logs and traces, which often capture full prompts and responses by default.
  • Caches, including prompt caches and your own response caches.
  • Evaluation datasets, which tend to get copied from production.
  • Third-party tools an agent can call.

The HIPAA Privacy Rule's minimum necessary standard says covered entities and business associates "must make reasonable efforts to limit protected health information to the minimum necessary" for the purpose. For an LLM feature, that translates into a design question at each hop: does this component need identifiable data to do its job?

Architecture diagram of a HIPAA-aware LLM feature. Step 1: the clinical app and its database sit inside the PHI zone. Step 2: a decision asks whether the model needs PHI for this feature. Step 3, if no: a redaction and tokenisation service strips identifiers and stores a token map inside the PHI zone. Step 4, if yes: the request is routed only to a BAA-covered model endpoint with minimum necessary fields. Step 5: the model returns output, which is validated and re-identified inside the PHI zone. Step 6: an audit log records who called what, with redacted payloads.
Two routes to the model: de-identified by default, BAA-covered only when the feature truly needs PHI.

Route one: de-identify before the prompt

The default route should keep PHI out of the prompt entirely. Many useful features, such as summarising a clinical guideline, drafting a template letter, or classifying an anonymised note, do not need to know who the patient is.

HIPAA defines two ways to de-identify. Under 45 CFR 164.514, the expert determination method has a qualified person document that re-identification risk is "very small"; the safe harbor method removes 18 listed categories of identifiers, including names, geographic units smaller than a state, all date elements except year, phone numbers, email addresses, medical record numbers and full-face photographs, plus "any other unique identifying number, characteristic, or code". Safe harbor also requires that you have no actual knowledge that what remains could identify someone.

In code, I build this as a separate redaction service that sits inside the PHI zone:

  • Detect identifiers with a combination of structured field mapping (you know which database columns are names and dates) and a text scanner for free-text notes.
  • Replace each identifier with a stable token, such as [PATIENT_1] or [DATE_3], and store the mapping inside the PHI zone, never alongside the prompt.
  • Send the tokenised text to the model.
  • Re-identify the response inside the PHI zone, if the user needs to see real names.

Two cautions. Free-text clinical notes are where detection fails, so test the scanner on realistic samples and measure what it misses. And tokenised output is not automatically de-identified in the legal sense; whether your process meets either method is a judgement for your compliance team, not the engineer.

Route two: when the model needs PHI, use a covered service

Some features cannot work without identifiable data, such as drafting a discharge summary for a named patient. For those, the provider becomes part of your PHI flow, and the Privacy Rule's business associate provisions require "satisfactory assurance that the business associate will appropriately safeguard the information" before disclosure. In practice that means a business associate agreement (BAA).

The detail that catches teams out is that a BAA covers specific services and configurations, not a vendor's whole product line. A few examples from pages I checked in November 2026:

Provider routeWhat the provider saysWhat to check
Anthropic first-party APIBAA covers HIPAA-ready services; the organisation must sign a BAA before PHI is enabled, and "not all API features are covered"Batch API, Files API, Skills, code execution and web fetch are listed as not covered
Amazon BedrockListed as HIPAA eligible; PHI must not be used without an AWS BAAConfigure the service consistent with HIPAA; check each model and feature you use
Any provider without a BAANo assurance for PHIDe-identified data only

Two engineering consequences follow. First, enforce the route in code: one gateway module knows which endpoints and features are covered, and anything else is rejected when a request is flagged as containing PHI. Second, re-check eligibility whenever you adopt a new feature. A team that starts using batch processing to save money, or a file upload API for convenience, can quietly move PHI onto an uncovered path.

Logs, retrieval and evals: the places PHI leaks

Most PHI leaks I would worry about in an LLM app are not in the model call; they are in the plumbing around it.

Logs and traces. Observability tools capture prompts by default, which is exactly what you want for debugging and exactly what you do not want for PHI. Log the redacted version, store a request ID that links back to the PHI zone, and keep the observability vendor outside your PHI flow unless it is covered too. I cover the general setup in LLM observability.

Retrieval. If you embed clinical documents for search, the vector store holds content derived from PHI and needs the same access controls as the source. Filter retrieval by the current user's permissions before results reach the prompt, not after.

Evaluation sets. Build them from de-identified or synthetic records. A spreadsheet of real prompts shared with a contractor is a disclosure.

Agents and tools. If an agent can call tools, each tool is another hop. Keep PHI-bearing tools read-only where you can, and put a human approval step on anything that sends, writes or shares, as I describe in human-in-the-loop AI agents. Treat retrieved documents as untrusted input, because prompt injection can try to make the model exfiltrate what it can see.

What I carried over from healthcare frontend work

I was frontend lead at Mediflow 360 on a personal-injury case platform used by healthcare providers and attorneys, covering patient records, imaging, and attorney and e-sign lien portals. The case study records the approach to sensitive data in the interface: no sensitive data cached in local storage, sessions and permissions enforced by the API rather than the UI, and screens designed so they never show more patient data than their task needs.

Those principles carry straight over to LLM features. The model is another consumer of data, so it gets what the task needs, through an API that enforces permissions, and nothing lingers in places nobody audits.

A build checklist

Use this as a starting point for the conversation with your compliance team:

  • A data flow diagram showing every component that touches PHI, including logs, caches and eval sets.
  • A per-feature decision: de-identified route or BAA-covered route, written down.
  • A redaction service with tests on realistic free text and a measured miss rate.
  • A gateway that rejects PHI-flagged requests to uncovered endpoints or features.
  • Redacted logging, with request IDs linking back to the PHI zone.
  • Retrieval filtered by user permissions before prompt assembly.
  • Synthetic or de-identified evaluation data.
  • Human approval for any action that sends or writes PHI.

Work with me

I build AI features into existing products, including the redaction, routing and logging layers that keep sensitive data where it belongs. See AI integration and full-stack development, browse my work, and book a scoping call. I work with your compliance team, not instead of it.

Frequently asked

Can I send PHI to an LLM API?

Only if the provider has signed a BAA with you that covers the specific service and features you use, and your organisation has decided the use is permitted. Otherwise, de-identify the data first. Check the provider's current eligibility list, because coverage is feature by feature.

Does a BAA make my LLM app HIPAA compliant?

No. A BAA covers the provider's obligations for the covered service. Your app still needs access controls, minimum necessary data, safe logging, retrieval permissions and the rest of your security programme. Compliance is a property of the whole system and your organisation's processes.

Is redacting names enough to de-identify data?

Usually not. HIPAA's safe harbor method lists 18 identifier categories, including dates, small geographic units, record numbers and any other unique identifying code, and requires no actual knowledge that the rest could identify someone. Free text often hides identifiers that simple name redaction misses.

Are embeddings of clinical notes PHI?

Treat them as sensitive. They are derived from the source text and stored next to it in most retrieval setups, so give the vector store the same access controls and coverage as the original records, and ask your compliance team how to classify them.

Sources

Related services

Building something like this?

Naman Gundaniya takes on full-stack and AI projects: fixed quote after a free 30-minute scoping call, replies within 24 hours.

Get in touch