{"slug": "phi-leak-guard-a-practical-tutorial-for-phi-leak-detection", "title": "phi-leak-guard: A Practical Tutorial for PHI Leak Detection", "summary": "Developer Selvassn released phi-leak-guard, a zero-dependency TypeScript library that integrates with Vitest or Jest to detect Protected Health Information (PHI) leaks from large language models, using deterministic validation such as Modulus-11 checksums for NHS numbers and ISO-3779 check digits for vehicle VINs to reduce false positives. The library, which runs locally and covers 18 HIPAA Safe Harbor identifiers, achieves a 0.97 recall on synthetic benchmarks and is available under an MIT license.", "body_md": "# phi-leak-guard: A Practical Tutorial for PHI Leak Detection\n\nI needed a deterministic, local way to fail a build the second an LLM leaks a patient identifier, so I built `phi-leak-guard`\n\n. It's a zero-dependency TypeScript library that integrates directly into Vitest or Jest.\n\n## Integration and Usage\n\nSetting this up as a regression gate in your CI/CD pipeline is straightforward. Since it runs locally, no data ever leaves your process.\n\n``` js\nimport 'phi-leak-guard/vitest';\n\ntest('clinical summary never leaks PHI', () => {\n  expect(summarize(patientNote)).toContainNoPHI();\n});\n```\n\nWhen a leak is detected, the library specifies the identifier type and whether it was a pattern match or a validated hit (e.g., `[nhs-number] \"943 476 5919\" (validated)`\n\n).\n\n## Why Deterministic Validation Beats Naive Regex\n\nThe biggest pain point in PII/PHI detection is the false positive. A standard 10-digit regex will flag every single order number or timestamp as a sensitive ID. To solve this, the library uses validation logic rather than just pattern matching:\n\n**NHS Numbers:** Uses Modulus-11 checksums.**Vehicle VINs:** Implements ISO-3779 check digits.**IPv4:** Validates octet ranges.**SSN/NINO:** Applies structural and prefix rules.\n\nIf a number doesn't pass the checksum, it isn't flagged. This ensures the build only fails when there is a high probability of an actual leak.\n\n## Coverage and Limitations\n\nThis is a risk-reduction tool, not a full compliance certification. It focuses on the 18 HIPAA Safe Harbor identifiers. While it handles direct identifiers well, it cannot detect paraphrased re-identification or every possible name. For those needing deeper analysis, there is a pluggable seam to integrate a Named Entity Recognition (NER) model.\n\nTo see exactly what is being monitored, you can run `coverageReport()`\n\n, which explicitly lists what the library can and cannot detect (e.g., it won't pretend to detect biometrics in plain text).\n\n## Deployment\n\nFor anyone building a medical AI workflow, you can add this to your dev dependencies:\n\n`npm install --save-dev phi-leak-guard`\n\nThe library is MIT licensed, supports ESM/CJS, and hits a 0.97 recall on synthetic benchmarks.\n\n```\nhttps://github.com/selvassn/phi-leak-guard\n```\n\n[Next AgentWire: A Wireshark for AI Agents →](/en/threads/3674/)", "url": "https://wpnews.pro/news/phi-leak-guard-a-practical-tutorial-for-phi-leak-detection", "canonical_source": "https://promptcube3.com/en/threads/3691/", "published_at": "2026-07-26 13:02:10+00:00", "updated_at": "2026-07-26 13:08:43.433320+00:00", "lang": "en", "topics": ["ai-safety", "developer-tools", "ai-products"], "entities": ["Selvassn", "phi-leak-guard", "Vitest", "Jest", "HIPAA", "NHS"], "alternates": {"html": "https://wpnews.pro/news/phi-leak-guard-a-practical-tutorial-for-phi-leak-detection", "markdown": "https://wpnews.pro/news/phi-leak-guard-a-practical-tutorial-for-phi-leak-detection.md", "text": "https://wpnews.pro/news/phi-leak-guard-a-practical-tutorial-for-phi-leak-detection.txt", "jsonld": "https://wpnews.pro/news/phi-leak-guard-a-practical-tutorial-for-phi-leak-detection.jsonld"}}