{"slug": "shield-zero-dependency-pii-and-secret-masking-for-llms-mit", "title": "Shield – Zero-dependency PII and secret masking for LLMs (MIT", "summary": "PromptAudit released Shield, an MIT-licensed, zero-dependency TypeScript module that masks PII and secrets in prompts before they reach LLMs and restores the original values in the caller's process memory via shield(), unshield() and withShield(). Shield validates IBANs (ISO 7064 Mod 97), payment cards (Luhn plus brand prefix), US SSNs (SSA rules) and ABA routing numbers (3-7-1), and detects OpenAI/Anthropic sk- keys, AWS AKIA/ASIA keys, GitHub ghp_/github_pat_ tokens, Slack xox tokens, JWTs and PEM private keys, running in browsers, Node, Bun, Deno and edge workers with no network calls or telemetry. PromptAudit states the pattern-based tool does not detect names without a title, free-text addresses or medical terms, and that detection is best-effort rather than a guarantee that no personal data leaves a system.", "body_md": "**Zero-dependency, fast & reversible PII and secret masking for LLMs & AI agents.**\n\n```\nnpm install @promptaudit/shield\njs\nimport { withShield } from \"@promptaudit/shield\";\n\nconst answer = await withShield(userPrompt, (safe) => llm.complete(safe));\n// The model saw [API_KEY_1], [IBAN_1] … — your user gets the real values back.\nYou wrote:   Deploy with key sk-proj-AbC123…xyz and refund Mr. John Miller, IBAN CH93 0076 2011 6238 5295 7\nModel sees:  Deploy with key [API_KEY_1] and refund Mr. [NAME_1], IBAN [IBAN_1]\nYou get:     the model's answer with the original values restored in your process memory\n```\n\n- **Zero dependencies.** One small TypeScript module. Browser, Node, Bun, Deno, edge workers.\n- **Checksum-validated.** IBAN (ISO 7064 Mod 97), cards (Luhn + brand prefix), US SSN (SSA rules), ABA routing (3-7-1). Order and serial numbers are not masked by accident.\n- **Secrets included.** OpenAI/Anthropic`sk-…` , AWS`AKIA…` /`ASIA…` , GitHub`ghp_…` /`github_pat_…` , Slack`xox…-` , JWT and PEM private keys.\n- **Reversible.** Placeholders go out, the map stays in your process memory.\n- **Obfuscation-aware.** Zero-width characters and full-width digits are normalised first.\n- **No network, no telemetry.**\n\n|  | Typical Python NLP stack | Ad-hoc regex snippets | **@promptaudit/shield** | \n|---|---|---|---|\n| Runtime | Python server | varies | **Browser, Node, Bun, Deno, edge** | \n| Dependencies | NLP models and packages | varies | **0** | \n| Checksum validation | partial | rarely | **IBAN, cards, SSN, ABA** | \n| API keys / secrets | separate tooling | rarely | **built in** | \n| Restore originals | manual | usually one-way | **`unshield()` / `withShield()`** | \n\nNLP stacks (e.g. Microsoft Presidio) detect free-text names and addresses, which Shield does not. Choose by need; they can be combined.\n\n| Function | Purpose | \n|---|---|\n| `shield(text, detectors?)` | Returns `{ masked, map, counts }` | \n| `unshield(text, map)` | Restores originals in a model answer | \n| `withShield(prompt, call)` | Mask → call → restore in one step | \n| `DEFAULT_DETECTORS` | Extend with your own `{ category, pattern, validate? }` | \n\nIBAN · payment card · US SSN · US routing (with keyword) · e-mail · international phone (`+` prefix) · names after Mr./Mrs./Ms./Dr./Prof. · API keys · private keys\n\n- Pattern-based, not NER: names without a title, free-text addresses and medical terms are **not** detected.\n- Unknown key formats are not caught.\n- Detection is best-effort. It reduces exposure; it does not guarantee that no personal data leaves your system.\n- No audit trail.\n\nShield runs inside your code. Teams that must **prove** what was sent, by whom and when — with browser enforcement for every employee, append-only hash-chained logs and Swiss storage — use the [PromptAudit platform](https://promptaudit.ch).\n\nTry it live: [https://promptaudit.ch/shield](https://promptaudit.ch/shield) · MIT © PromptAudit", "url": "https://wpnews.pro/news/shield-zero-dependency-pii-and-secret-masking-for-llms-mit", "canonical_source": "https://github.com/PromptAudit-SaaS/shield", "published_at": "2026-11-22 16:27:59+00:00", "updated_at": "2026-11-22 16:42:04.889833+00:00", "lang": "en", "topics": ["ai-safety", "ai-agents", "ai-tools", "developer-tools", "large-language-models"], "entities": ["PromptAudit", "Shield", "@promptaudit/shield", "Microsoft Presidio", "OpenAI", "Anthropic", "AWS", "GitHub"], "also_reported_by": [], "takeaway": "Shield masks IBANs, cards, SSNs, ABA routing numbers and API keys into placeholders like [API_KEY_1] and restores originals in-process via unshield(), but it is pattern-based and will not catch untitled names, free-text addresses or unknown key formats.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/shield-zero-dependency-pii-and-secret-masking-for-llms-mit", "markdown": "https://wpnews.pro/news/shield-zero-dependency-pii-and-secret-masking-for-llms-mit.md", "text": "https://wpnews.pro/news/shield-zero-dependency-pii-and-secret-masking-for-llms-mit.txt", "jsonld": "https://wpnews.pro/news/shield-zero-dependency-pii-and-secret-masking-for-llms-mit.jsonld"}}