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.

To Be Fair: What EchoGuard Is (and Isn’t)

Before diving into the architecture, let’s be clear about what this prototype does and where its boundaries are:

  • It is not a full EHR replacement. There is no central patient database—encounter history stays strictly in local browser storage with all PII already stripped.
  • On-device Gemini Nano only runs in Desktop Chrome right now. If a clinician opens EchoGuard in Firefox, Safari, or mobile, it falls back automatically to a local deterministic redactor so raw PII still stays on their machine.

The 3-Stage Hybrid Architecture

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 │ └──────────────────────────────────────────────────────────┘ 

Stage 1: Local PII Shield (On-Device)

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 // ... } 

Stage 2: Cloud SOAP Note & HL7 FHIR Export

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.

Stage 3: Multi-Speaker Shift Handoff (Doctor & Nurse)

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.

4 Real Problems I Hit (and How I Fixed Them)

Building a hybrid AI app sounds clean on a slide deck. In practice, four things broke during testing:

1. Single-request multi-speaker TTS mixed up the voices

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 pause.

2. Daily TTS quotas ran out fast during testing

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.

3. Spoken dictation broke naive PII regexes

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".

4. One stray click could mix two patients together

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.

Production Security & Governance

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:

  • Firebase App Check (reCAPTCHA Enterprise): Blocks unauthorized requests and automated scripts from hitting AI Logic or Remote Config endpoints in production.
  • Firebase Remote Config: Serves 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.

Takeaway

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.