Data Protection
·IdenticAPI

What Is PII Detection?

PII detection identifies personally identifiable information in text — emails, phone numbers, government IDs, and more. Learn what it covers and where it fits in AI pipelines.

PII detection is the process of automatically finding personally identifiable information—such as email addresses, phone numbers, government IDs, and payment card numbers—in unstructured text before that text is logged, stored, indexed, or sent to a third-party service like an LLM. For AI applications, PII detection is a practical control you place at the boundary between user-generated content and systems that may retain, replay, or transmit that content outside your intended data boundary.

Why PII detection matters for AI applications

LLM pipelines ingest text from many sources: chat messages, uploaded documents, retrieved web pages, support tickets, and tool outputs. Each of those inputs may contain data your privacy policy, contracts, or regulations treat as sensitive. Once text enters a prompt, it can appear in:

  • Provider-side logs and training pipelines (depending on provider settings)
  • Your own application logs and error traces
  • Vector databases used for retrieval-augmented generation (RAG)
  • Model responses echoed back to other users in multi-tenant setups

PII detection does not replace a full privacy program, but it gives developers a concrete gate: scan text, classify findings, and decide whether to redact, block, or route for review before the data crosses a trust boundary.

Common categories detected in production scanners include:

CategoryExample (synthetic)Typical use case
Emailuser@example.comContact info in support chats
Phone555-010-0200Callback numbers in tickets
SSN123-45-6789HR or benefits documents
Credit card4111111111111111Billing snippets pasted into chat
IPv4192.0.2.10Infrastructure details in logs

Secrets such as API keys are a related but distinct class; see Secrets Detection for LLM Applications for credential-specific patterns.

How PII detection works

Most API-based PII detectors combine pattern matching with validation rules:

  1. Pattern matching — Regular expressions or similar rules locate candidate substrings (emails, phone formats, card-like digit groups).
  2. Validation — Additional checks reduce false positives. Credit card candidates often require a Luhn checksum; IBAN-like strings may check structure.
  3. Classification — Each match receives a category label, confidence score, and character offsets in the source text.
  4. Verdict aggregation — The scanner returns an overall verdict (safe, suspicious, or unsafe when secrets are present) so your application can branch consistently.

IdenticAPI's PII & Secrets Detection API follows this model. Send a POST request to /api/v1/security/pii-secrets with a JSON body:

{
  "text": "Please email user@example.com about order 12345.",
  "redact": false
}

A typical response includes verdict, findings (with category, reason, confidence, start, and end), and optional redacted_text when redact is true:

{
  "request_id": "req_abc123",
  "api": "pii-secrets-detection",
  "verdict": "suspicious",
  "risk": "medium",
  "confidence": 0.95,
  "findings": [
    {
      "category": "email",
      "reason": "Detected email (pii)",
      "confidence": 0.95,
      "start": 12,
      "end": 28
    }
  ],
  "reasons": ["Detected email (pii)"],
  "usage_units": 1,
  "processing_time_ms": 4,
  "detector_version": "1.0.0"
}

You can try sample text interactively with the PII Checker tool before wiring the API into your pipeline. Full request and response semantics are documented in the PII & Secrets Detection docs.

Where to place PII detection in an LLM pipeline

Effective placement depends on your architecture, but these integration points cover most applications:

Before the LLM call — Scan user messages, retrieved chunks, and system-assembled context. If findings exceed your policy, redact placeholders or reject the request. This is the highest-leverage location for preventing leakage into model providers. See How to Redact PII Before Sending Data to an LLM.

Before logging — Application and infrastructure logs frequently capture raw user input. Scan or redact before writing to log aggregators.

Before indexing (RAG) — Embeddings persist for a long time. Scan document chunks during ingestion so sensitive values do not enter your vector store.

On model output (selective) — Models can regurgitate training data or repeat context. Output scanning helps when the model might surface PII from prior turns or retrieved documents. Pair with input controls for defense in depth.

Before external tool calls — Agents that send email, create tickets, or post to Slack should not forward unreviewed PII unless the action is explicitly intended.

PII detection vs other privacy controls

PII detection focuses on finding sensitive substrings in text. It complements—not replaces—broader controls:

  • Access control limits who can read stored data.
  • Encryption protects data at rest and in transit.
  • Data minimization reduces what you collect in the first place.
  • DLP (Data Loss Prevention) often spans email gateways, endpoints, and enterprise policy engines at organization scale. Compare scopes in PII Detection vs Data Loss Prevention.

For LLM-specific architecture, a dedicated LLM privacy filter orchestrates scanning, redaction, blocking, and audit logging in one pre-model step.

Practical example: support chat preprocessing

Imagine a customer pastes this message:

My account email is user@example.com and my phone is 555-010-0200.
Can you reset my password?

A preprocessing step calls the API with "redact": true:

{
  "text": "My account email is user@example.com and my phone is 555-010-0200. Can you reset my password?",
  "redact": true
}

The response may include:

My account email is [EMAIL] and my phone is [PHONE]. Can you reset my password?

Your application forwards the redacted string to the LLM while storing the original only in systems authorized to handle PII. The model still understands the intent; the sensitive literals never enter the provider context.

Choosing a detection strategy

StrategyWhen it fitsTrade-off
Detect onlyAuditing, alerting, metricsRaw values may still flow downstream
Detect + redactLLM prompts, logs, RAG ingestionModel loses exact values; may affect answers
Detect + blockHigh-risk channels, zero-tolerance policiesMore user friction
Detect + review queueRegulated workflows with human oversightAdds latency and operational cost

Start with detect-and-redact on LLM inputs if your product must handle personal data occasionally but should not transmit it to third parties. Escalate to block for channels where any PII is prohibited.

Limitations

PII detection based on patterns and heuristics has inherent limits:

  • False positives — Formatted numbers, product SKUs, or version strings may resemble phone numbers or card numbers.
  • False negatives — Obfuscated text (user [at] example dot com), images of IDs, or non-English formats may evade regex detectors.
  • Context blindness — A detector knows a string looks like an email; it does not know whether that email is public business contact information or a private medical record.
  • No compliance guarantee — Passing a scan does not mean you meet GDPR, HIPAA, PCI-DSS, or other frameworks. Legal review remains your responsibility.

Treat detection as one layer in a broader data protection strategy. Re-scan after transformations (URL decoding, base64 expansion, PDF text extraction) because encoding can hide or reveal sensitive substrings.

Next steps

Frequently asked questions

What is PII detection?

PII detection is automated identification of personally identifiable information—such as emails, phone numbers, government IDs, and payment card numbers—in unstructured text. In AI applications it is used to scan user input, logs, and LLM context before sensitive literals cross a trust boundary.

What types of data does IdenticAPI PII detection cover?

The PII & Secrets Detection API detects emails, US-format phone numbers, credit card numbers (with Luhn validation), IBAN-like strings, IPv4 addresses, and US SSN patterns. It also detects secrets including API keys, private keys, bearer tokens, and credential pairs in the same scan.

Where should PII detection run in an LLM pipeline?

Run detection server-side before the LLM provider call, and also before logging, RAG indexing, and tool output re-entry. Scan the full assembled prompt—including chat history and retrieved chunks—not only the latest user message.

Does PII detection guarantee regulatory compliance?

No. Detection helps reduce accidental exposure but does not by itself satisfy GDPR, HIPAA, PCI-DSS, or other frameworks. Combine scanning with data minimization, access control, retention policies, and legal review.

What verdict does PII trigger in IdenticAPI?

PII findings typically produce a suspicious verdict with medium risk. Secrets produce an unsafe verdict with high risk. A safe verdict means no PII or secrets were detected in the scanned text.

Related reading