pii-detection
Published
Public
in @structured-extraction

Detect and redact personally identifiable information (PII) — emails, phone numbers, names, addresses, card and account numbers, and more. Returns each detected span plus a fully redacted copy of the text. Optionally restrict to a caller-supplied set of PII types.

pii-detection

Detect and redact personally identifiable information in free text. Returns a decision flag, every detected span (typed, with a placeholder), and a fully redacted copy of the text — ready to log, store, or forward safely.

Entrypoints

EntrypointRendersInputs
systemPromptInstructions, the PII taxonomy, optional type filter + embedded schemaoptional piiTypes
userPromptThe delimited text to scantext

Variables

  • text (string, required) — the text to scan for PII.
  • piiTypes (array of string, optional) — restrict detection to these types only, e.g. ["email","phone"]. Omit to detect every type.

Output

{
  "contains_pii": true,
  "entities": [
    { "text": "[email protected]", "occurrence": 1, "type": "email", "redacted_as": "[EMAIL]" },
    { "text": "(415) 555-0132", "occurrence": 1, "type": "phone", "redacted_as": "[PHONE]" }
  ],
  "redacted_text": "Contact me at [EMAIL] or [PHONE]."
}
  • contains_pii comes first — a cheap boolean gate for routing or blocking before you read the details.
  • redacted_text is the input with every span swapped for its placeholder ([EMAIL], [PHONE], numbered when repeated). Non-PII text is left byte-for-byte unchanged; it equals the input when nothing is found.
  • Spans use the same matched-text + 1-based occurrence convention as entity-extraction (no character offsets).

⚠️ Scope & accuracy

This is an LLM-based detector — excellent recall on natural-language PII, but it is not a compliance guarantee. Don't treat contains_pii: false as proof a document is clean for GDPR/HIPAA purposes. For regulated pipelines, pair it with deterministic detectors (regex for card/SSN formats) and human review. redacted_text is a convenience, not a certified anonymization.

House conventions

  • Triple-mustache for text so the scanned content is never HTML-escaped.
  • No hallucinated PII — only what's present; redacted_text equals input when none found.
  • Strict schema — closed enum on type, additionalProperties: false.

Notes

Verified by local render with and without a piiTypes filter. Suggested default claude-sonnet-4-6 at temperature: 0.

@sufleur/