Cloud AI can turn a messy telehealth transcript into a clean SOAP note in 5 seconds.
So why arenβt doctors pasting patient notes straight into a cloud LLM?
Because a real clinical transcript has the patientβs full name, date of birth, medical record number (MRN), phone number, insurance ID, and even their motherβs name. Send that raw text to a third-party cloud server and you have an immediate privacy breach.
I built EchoGuard to stop that before a single byte leaves the browser.
Instead of asking clinicians to trust a remote server with raw patient records, EchoGuard enforces a zero-trust boundary locally on the device firstβso 0 bytes of raw PII ever cross the network.
Before diving into the architecture, letβs be clear about what this prototype does and where its boundaries are:
EchoGuard splits the workload across the browser boundary using the Firebase AI Logic SDK (firebase/ai):
[Live Mic / Transcript]
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β BROWSER (Zero-PII Boundary) β
β 1. Local PII Shield β
β β’ Gemini Nano (InferenceMode.ONLY_ON_DEVICE) β
β β’ Fail-closed deterministic local redactor β
βββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββ
β 0 Bytes of Raw PII Crosses Here
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FIREBASE (App Check + Remote Config) β
β 2. Cloud SOAP Synthesis (Cloud Gemini) β
β β’ Structured SOAP Note + ICD-10 + HL7 FHIR JSON β
β β
β 3. Multi-Speaker Shift Handoff (Gemini Flash TTS) β
β β’ Parallel Doctor & Nurse synthesis + 24kHz PCM β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
When a clinician dictates via Live Mic or pastes a transcript, nothing touches the network yet. Chromeβs built-in Gemini Nano (InferenceMode.ONLY_ON_DEVICE) pairs with a fail-closed deterministic redactor to scrub patient names, caregiver names (mother, father, guardian), spoken and numeric birthdates, MRNs, insurance IDs, and phone numbers inside the browser.
The UI renders a live audit receipt showing exactly how many entities were stripped locallyβand confirming 0 Bytes PII Sent to Cloud.
/**
* Redacts residual PII on-device using Gemini Nano via Firebase AI Logic.
*/
export async function redactPIIViaFirebaseNano(
rawTranscript: string,
onChunk?: (partialText: string) => void,
): Promise<string> {
const onDeviceModel = getGenerativeModel(ai, {
mode: InferenceMode.ONLY_ON_DEVICE,
onDeviceParams: {
createOptions: {
expectedOutputs: [{ type: "text", languages: ["en"] }],
initialPrompts: [
{
role: "system",
content: [
{
type: "text",
value:
"You are a strict PII redaction engine. Return ONLY the original text with any remaining personal identifiers (names, addresses, dates of birth, IDs, phone numbers) replaced by [REDACTED]. Do NOT add explanations, markdown, bullet points, or medical advice.",
},
],
},
],
},
},
});
// Stream redacted output locally β 0 bytes sent to cloud
// ...
}
Only the scrubbed clinical payload crosses into Cloud Gemini. Because the sensitive identifiers are already replaced with [REDACTED] tokens, the cloud model focuses purely on clinical reasoning: producing a structured SOAP note (Subjective, Objective, Assessment, Plan with ICD-10 codes) and a one-click HL7 FHIR JSON export.
Busy wards run on spoken handoffs, not walls of text. EchoGuard turns the care plan into a two-speaker Doctor & Nurse audio briefing using gemini-2.5-flash-preview-tts, complete with a readable dialogue script and instant .wav download.
Building a hybrid AI app sounds clean on a slide deck. In practice, four things broke during testing:
When I first asked TTS to generate both the Doctor and Nurse in a single request, the voices drifted away from the profiles selected in Settings.
The fix: I built a Split-and-Stitch pipeline. EchoGuard caps the handoff script at 2 turns, synthesizes the Doctor and Nurse lines in parallel using their exact voice profiles, and stitches the raw 24 kHz 16-bit mono PCM buffers together locally with a 350 ms natural .
Replaying a handoff or previewing voices in Settings burned API quota on every single click.
The fix: I replaced Blob URL state with a bounded FIFO Uint8Array PCM cache in memory (so React effect cleanups never revoke cached audio). Replaying a handoff or switching back to a previewed voice now costs 0 API calls.
During live microphone tests, natural speech like "brought in by mother Sarah Lynn, born September 18th 2020" slipped right past standard regex patterns.
The fix: I hardened the deterministic pre-filter with case-sensitive caregiver/family name matching and spoken date-of-birth patternsβwhile preserving legitimate clinical prose like "Mother reports fever" or "born at 38 weeks".
If a clinician accidentally clicked Live Mic or a sample transcript pill after finishing a note, new text would append onto the previous patient's chart.
The fix: EchoGuard locks down all input controls the moment an encounter completes. To start a new patient chart, the clinician has to explicitly click + New Encounter.
Even when a payload contains zero PII, an open cloud endpoint is still a target for quota abuse. EchoGuard locks down the cloud side using two more Firebase services:
default_cloud_model (gemini-3.1-flash-lite), tts_model, and soap_system_prompt dynamicallyβmeaning I can swap Gemini model versions or tighten clinical prompt instructions without redeploying the frontend.
Hybrid AI isnβt just about splitting compute between the client and the cloudβitβs about enforcing hard trust boundaries.
Pairing a deterministic local filter with on-device Gemini Nano gives clinicians predictable privacy guarantees regardless of what browser they use, while keeping Cloud Gemini focused on heavy clinical synthesis.
If you want to inspect the redactor rules, the 24 kHz PCM stitcher, or run it locally with Docker, check out the repo: github.com/afiqxeon/echoguard.