# 0 Bytes of Patient PII Sent to the Cloud: Building a Zero-Trust Telehealth Scribe with Gemini Nano & Firebase

> Source: <https://dev.to/afiqxeon/0-bytes-of-patient-pii-sent-to-the-cloud-building-a-zero-trust-telehealth-scribe-with-gemini-nano-2j5e>
> Published: 2026-12-05 07:40:49+00:00

**Recommendation:** Redact PII on-device with a fail-closed local model and deterministic fallback before sending any transcript to a cloud LLM, and surface an audit receipt confirming zero raw PII crossed the network.
More in the playbook "Securing agents and AI tools": <https://wpnews.pro/playbooks/agent-security>

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

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](https://github.com/afiqxeon/echoguard).
