<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Selva</title>
    <description>The latest articles on DEV Community by Selva (@selvakg).</description>
    <link>https://dev.to/selvakg</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4047864%2F930b4a2c-3aad-49f4-ba2d-841c8692324c.jpeg</url>
      <title>DEV Community: Selva</title>
      <link>https://dev.to/selvakg</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/selvakg"/>
    <language>en</language>
    <item>
      <title>I shipped an npm package that fails your build when an LLM leaks PHI</title>
      <dc:creator>Selva</dc:creator>
      <pubDate>Sun, 26 Jul 2026 11:40:37 +0000</pubDate>
      <link>https://dev.to/selvakg/i-shipped-an-npm-package-that-fails-your-build-when-an-llm-leaks-phi-1a65</link>
      <guid>https://dev.to/selvakg/i-shipped-an-npm-package-that-fails-your-build-when-an-llm-leaks-phi-1a65</guid>
      <description>&lt;h2&gt;
  
  
  The problem nobody had a clean answer to
&lt;/h2&gt;

&lt;p&gt;I build LLM features over clinical text. Before shipping any of them, I wanted one boring guarantee: if the model ever puts a patient identifier in its output, the build fails.&lt;/p&gt;

&lt;p&gt;I went looking for a tool. Every LLM-eval library I found (autoevals, promptfoo, vitest-evals, evalite) fell into one of two camps: no concept of PHI at all, or it graded output by sending it to a hosted API. The second is a non-starter — when the thing you're evaluating is patient data, mailing it to a third party is the exact risk you're trying to avoid.&lt;/p&gt;

&lt;p&gt;So I built phi-leak-guard.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it is
&lt;/h2&gt;

&lt;p&gt;A zero-dependency TypeScript library that detects PHI/PII in text and fails your test suite when it finds any. It runs locally in Vitest/Jest — no network, no model, nothing leaves the process.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;phi-leak-guard/vitest&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

 &lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;clinical summary never leaks PHI&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;summarize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;patientNote&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;toContainNoPHI&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When it fails, it tells you exactly what leaked:&lt;/p&gt;

&lt;p&gt;Expected output to contain no PHI, but found 2:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[name] "John Smith" (pattern)&lt;/li&gt;
&lt;li&gt;[nhs-number] "943 476 5919" (validated)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The interesting part: precision without a model&lt;/p&gt;

&lt;p&gt;The hard problem with deterministic PHI detection is false positives. A naive \d{10} regex flags every order number as an NHS number and gets disabled within a day. The trick is to validate, not just pattern-match:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;NHS numbers → Modulus-11 checksum&lt;/li&gt;
&lt;li&gt;Vehicle VINs → ISO-3779 check digit&lt;/li&gt;
&lt;li&gt;IPv4 → octet range validation&lt;/li&gt;
&lt;li&gt;SSN / NINO → structural + prefix rules&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A random 10-digit number fails the checksum, so it isn't flagged. Matches are tagged validated (checksum-backed) or pattern (regex/context) so you can see how much to trust each hit.&lt;/p&gt;

&lt;p&gt;Staying honest about coverage&lt;/p&gt;

&lt;p&gt;HIPAA Safe Harbor is a finite list of 18 identifier categories — a completable target. UK GDPR "personal data" is open-ended, so the library covers common direct identifiers, not "everything." A coverageReport() prints exactly what is and isn't checked per standard, and three categories (biometrics, photos, "any other identifier") are reported as not detectable in text rather than pretended-covered.&lt;/p&gt;

&lt;p&gt;It's not a compliance certification — it's a regression gate that reduces risk. And deterministic matching can't catch paraphrased re-identification or every name, so there's a pluggable seam to drop in an NER model.&lt;/p&gt;

&lt;p&gt;Try it&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install --save-dev phi-leak-guard&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It's MIT, ships ESM + CJS + types, and has a synthetic benchmark (precision 1.00, recall 0.97). Repo: &lt;a href="https://github.com/selvassn/phi-leak-guard" rel="noopener noreferrer"&gt;https://github.com/selvassn/phi-leak-guard&lt;/a&gt; — I'd genuinely love feedback on which identifiers to add next.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>phi</category>
      <category>typescript</category>
      <category>hippa</category>
    </item>
  </channel>
</rss>
