newmean-pii

Mask PII before calling OpenAI in Node.js and TypeScript

Find names, emails, phone numbers and other personal information in the prompt inside your own Node.js process, send OpenAI the placeholders, and put the real values back in the answer.

Install

npm install @newmean-ai/pii openai

The package ships its TypeScript types. Apache-2.0.

Mask, call, restore

import OpenAI from "openai";
import { createRedactor, createVault } from "@newmean-ai/pii";

const openai = new OpenAI();                 // reads OPENAI_API_KEY
const redactor = await createRedactor();     // medium; create once, reuse
const vault = createVault();                 // one per user or conversation

const prompt = "Draft a reply to Kim Minsu (kim@example.com) about the refund.";
const { text } = await redactor.redact(prompt, { vault });
// "Draft a reply to [PERSON_1] ([EMAIL_1]) about the refund."

const response = await openai.responses.create({
  model: "gpt-6.1",
  instructions: "Copy text in square brackets, such as [PERSON_1], exactly as written.",
  input: text,
});
console.log(vault.restore(response.output_text)); // [PERSON_1] → Kim Minsu

Save it as app.ts and run node app.ts (we ran it on Node.js 25.9, which strips the types), or as app.mjs: the code has no type annotations, so it is plain JavaScript too.

What OpenAI receives

Detection runs in your process. The request body holds the masked text, not the name or the email address:

"input": "Draft a reply to [PERSON_1] ([EMAIL_1]) about the refund."

Captured from the code above, run against a local stand-in for the API (OPENAI_BASE_URL).

Putting the values back

Limits