@mlx-node/privacy

Find and mask personal data in text on your own machine.

Install

bash
npm install @mlx-node/privacy

Get a model

bash
mlx download model -m openai/privacy-filter

The package is a port of the openai/privacy-filter checkpoint. The folder needs config.json, model.safetensors, tokenizer.json and tokenizer_config.json.

Mask personal data

ts
import { homedir } from 'node:os';
import { join } from 'node:path';

import { PrivacyFilter } from '@mlx-node/privacy';

const models = join(homedir(), '.mlx-node', 'models');
const pf = await PrivacyFilter.load(join(models, 'privacy-filter'));
const { redacted } = await pf.redact('Email alice@example.com or call +1 555 0100.');
console.log(redacted); // labels like [private_email], [private_phone]

redact() returns { redacted, entities }: the text with each entity replaced by its label, and the list of entities. classify() returns { entities } without the redacted text. Each entity has label, start, end, score and text.

What it finds

Eight kinds of entity: account_number, private_address, private_date, private_email, private_person, private_phone, private_url and secret.

It is a model, so it can miss an entity or mark text that is not one. Check its output before you rely on it.

From the terminal

bash
mlx redact -m ~/.mlx-node/models/privacy-filter -i input.txt -o redacted.txt

--labels limits the kinds, --threshold sets the score cut (default 0.5), and --json also writes the entities as JSON, next to the output file when you pass -o.

Main exports

Name What it is
PrivacyFilter load, classify, redact

Go deeper