Stop Leaking PII! Local Data Masking with Transformers.js and WASM A developer demonstrates how to build a client-side 'Privacy Shield' using Transformers.js and WebAssembly to mask personally identifiable information (PII) directly in the browser before data reaches cloud APIs. The approach leverages Named Entity Recognition (NER) with a BERT-based model to detect and redact names, locations, and organizations, ensuring compliance with regulations like GDPR and HIPAA while maintaining near-native performance. In an era where data privacy is no longer a "nice-to-have" but a legal mandate looking at you, GDPR and HIPAA , sending raw user data to the cloud is like playing with fire. If you are building health-tech or fintech apps, the risk of exposing Personally Identifiable Information PII is a constant headache. But what if the data never leaves the user's browser in its raw form? Enter Edge AI and Privacy-preserving AI . By leveraging Transformers.js and WebAssembly WASM , we can perform complex Named Entity Recognition NER to de-identify sensitive information directly on the client side. In this tutorial, we’ll build a "Privacy Shield" that detects and masks names, locations, and health identifiers before they ever hit your API. The traditional approach involves sending raw text to a server-side LLM or NLP service. Our approach intercepts the data at the "Edge" the browser . php graph TD A User Inputs Sensitive Health Data -- B{Browser-side Privacy Shield} B -- C Transformers.js / WASM C -- D NER Model Analysis D -- E Data Masking / Redaction E -- F Clean Data F -- G Cloud Storage / Analytics G -.- H Compliance & Security ✅ style B fill: f9f,stroke: 333,stroke-width:2px style C fill: bbf,stroke: 333,stroke-width:2px By using WebAssembly , we get near-native performance for running BERT-based models in the browser, ensuring the UI remains snappy while keeping the data 100% local. To follow along, you'll need: First, let's install the library: npm install @xenova/transformers Now, let's create our PrivacyShield service. We will use a lightweight NER model like Xenova/bert-base-NER that has been optimized for the web. js // src/services/privacyShield.ts import { pipeline, env } from '@xenova/transformers'; // Optimization for browser environment env.allowLocalModels = false; env.useBrowserCache = true; export class PrivacyShield { private classifier: any = null; async init { // Initialize the Token Classification pipeline NER this.classifier = await pipeline 'token-classification', 'Xenova/bert-base-NER' ; console.log "🚀 Privacy Engine Ready " ; } async maskPII text: string : Promise