Skip to content

pii

Creates a builder for PII (personal information) detection rules. Detects email addresses, phone numbers, credit card numbers, and more.

Signature

ts
const builder = pii(options?);

Parameters

ParameterTypeDescription
options.namestringRule name (auto-generated if omitted)

Methods

MethodReturnsDescription
.exclude(...types)DetectorBuilderExclude specified types from detection
.only(...types)DetectorBuilderDetect only specified types
.scope(...tools)DetectorBuilderLimit to specific tools (string | RegExp)
.block(message?)RuleBlock on violation (severity: "error")
.warn(message?)RuleWarn on violation (severity: "warn")
.log(message?)RuleLog violation (severity: "info")

Detection Types

TypeDetectsConfidence
emailEmail addresses0.95
phone_internationalInternational phone numbers (+1-555-123-4567)0.85
phone_jpJapanese phone numbers (03-1234-5678)0.80
credit_cardCredit card numbers0.90
my_numberJapanese My Number (12 digits)0.70
ssnUS Social Security Numbers (XXX-XX-XXXX)0.90
ip_addressIPv4 addresses0.75

Returns

DetectorBuilder — terminal methods (.block(), .warn(), .log()) return a Rule.

Examples

Basic

ts
import { pii } from "open-mcp-guardrails";

pii().block();

Exclude types

ts
pii().exclude("ip_address").block();

Only specific types

ts
pii().only("email", "credit_card").block();

Warn only

ts
pii().warn("PII detected");

Scope to specific tools

ts
pii().scope("filesystem__read_file").block();
pii().scope(/^filesystem__/).warn();

Derive from a common base

Builders are immutable, so you can safely derive rules from a shared base:

ts
const base = pii();
const strict = base.block();
const lenient = base.exclude("ip_address").warn();

JSON Config

Equivalent configurations using guardrails.json:

json
{ "type": "pii", "action": "block" }
json
{ "type": "pii", "action": "block", "exclude": ["ip_address"] }
json
{ "type": "pii", "action": "block", "only": ["email", "credit_card"] }
json
{ "type": "pii", "action": "warn", "message": "PII detected" }
json
{ "type": "pii", "action": "block", "scope": ["filesystem__read_file"] }
json
{ "type": "pii", "action": "warn", "scope": ["/^filesystem__/"] }