npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

pii-firewall

v0.2.6

Published

Open-source PII firewall for LLM apps. Detect, anonymize and rehydrate sensitive data before it reaches any LLM provider.

Readme

pii-firewall

Open-source PII firewall for LLM apps. Detect, anonymize, and rehydrate sensitive data before it reaches any LLM provider — with zero runtime dependencies.

Installation

npm install pii-firewall

Quick start

import { PrivacyFirewallSDK } from "pii-firewall";

const sdk = PrivacyFirewallSDK.create({ domain: "generic" });

const context = {
  tenant_id: "acme",
  case_id:   "support-123",
  thread_id: "thread-1",
  actor_id:  "agent-1",
};

// 1. Anonymize before sending to the LLM
const { sanitizedText, trace } = sdk.anonymizeText(
  "Call Alice at [email protected] or 555-123-4567",
  context,
);
// sanitizedText → "Call [PERSON_001] at [EMAIL_001] or [PHONE_NUMBER_001]"

// 2. Send sanitizedText to your LLM …
const modelReply = "[PERSON_001] has been contacted at [EMAIL_001]";

// 3. Rehydrate the LLM response
const finalReply = sdk.rehydrateText(modelReply, context);
// finalReply → "Alice has been contacted at [email protected]"

Secure LLM call (one-liner)

import { PrivacyFirewallSDK, MockLLMClient } from "pii-firewall";

const sdk = PrivacyFirewallSDK.create({ domain: "generic" });
const llm = new MockLLMClient(); // replace with your real client

const result = await sdk.secureCall(
  "My SSN is 123-45-6789, what should I do?",
  context,
  llm,
);

console.log(result.sanitizedText); // sent to LLM  → "My SSN is [SSN_001], what should I do?"
console.log(result.finalText);     // back to user → original values restored

Domain profiles

Choose a built-in profile or create a custom one:

// Built-in: "generic" | "healthcare" | "finance" | "legal"
const sdk = PrivacyFirewallSDK.create({ domain: "healthcare" });

// Custom profile
import { createCustomProfile, getPresetProfile, DispositionAction, createDisposition } from "pii-firewall";

const myProfile = createCustomProfile("my-app", {
  baseProfile: getPresetProfile("generic"),
  dispositions: {
    EMPLOYEE_ID: createDisposition({
      entityType: "EMPLOYEE_ID",
      action: DispositionAction.PSEUDONYMIZE,
    }),
  },
});

const sdk = PrivacyFirewallSDK.create({ profile: myProfile });

Anonymize nested payloads

Sanitize entire JSON request bodies before sending to an LLM API:

const payload = {
  messages: [
    { role: "user", content: "My email is [email protected]" },
    { role: "user", content: "My card is 4111111111111111" },
  ],
};

const sanitized = sdk.anonymizePayload(payload, context);
const restored  = sdk.rehydratePayload(sanitized, context);

Streaming support

for await (const chunk of sdk.secureCallStream(prompt, context, llmClient)) {
  process.stdout.write(chunk); // tokens are rehydrated on the fly
}

Custom patterns

Add your own regex patterns at runtime:

import { createFirewall, createPattern } from "pii-firewall";

const fw = createFirewall({ domain: "generic" });

// Via helper (also registers disposition automatically)
fw.addCustomRegex({
  entityType: "EMPLOYEE_ID",
  regex: "\\bEMP-\\d{6}\\b",
  locales: ["US"],
  dispositionAction: "pseudonymize",
});

// Or via full EntityPattern object
fw.addCustomPattern(
  createPattern({ entityType: "BADGE_ID", locale: "GLOBAL", pattern: /BADGE-\d{4}/ })
);

Supported PII types

| Entity type | Example | |---|---| | EMAIL | [email protected] | | PHONE_NUMBER | +1 555-123-4567 | | NATIONAL_ID | 12345678Z (DNI), RSSMRA80A01H501U (Codice Fiscale) | | SSN | 123-45-6789 | | IBAN | ES9121000418450200051332 | | CREDIT_CARD | 4111 1111 1111 1111 | | IP_ADDRESS | 192.168.1.1, 2001:db8::1 | | URL | https://example.com | | PASSPORT | — | | DRIVERS_LICENSE | — | | POSTAL_CODE | 28001, 10115, 75001 | | TAX_ID | NIF, EIN, Steuer-ID | | DATE / AGE | generalized to year / decade | | MAC_ADDRESS | 00:1A:2B:3C:4D:5E | | DOI / PMID | academic references |

Supported languages & locales

| Language | Locale patterns | |---|---| | English | US (SSN, ZIP, DL, MRN, …) | | Spanish | ES (DNI, NIE, IBAN, …) | | French | FR (INSEE, IBAN, …) | | German | DE (Steuer-ID, IBAN, …) | | Italian | IT (Codice Fiscale, Partita IVA, …) | | Portuguese | PT (NIF, CPF, …) |

Language is auto-detected from the input text, or you can set it explicitly:

const sdk = PrivacyFirewallSDK.create({ manualLanguage: "es" });

Anonymization actions

| Action | Description | |---|---| | PSEUDONYMIZE | Replace with reversible token [TYPE_001] | | GENERALIZE | Reduce precision (age → decade, date → year) | | MASK | Partially obscure (****1234) | | HASH | Replace with SHA-256 hash token | | REDACT | Remove completely | | KEEP | Leave unchanged (used in domain profiles) |

Forget / right to erasure

sdk.forget(tenant_id, case_id, thread_id);
// Removes all vault mappings for that conversation

Zero runtime dependencies

This package uses only Node.js built-ins (crypto). No external dependencies are required.

License

Apache-2.0