This prompt is designed for security engineers building automated data sanitization pipelines. Its primary job is to act as an ingress-layer control, scanning unstructured text for Personally Identifiable Information (PII) such as Social Security Numbers, email addresses, phone numbers, physical addresses, and dates of birth before that data reaches downstream models, application logs, or long-term storage. The ideal user is someone who needs a programmatic, structured JSON output with confidence scores to make a deterministic routing decision—redact the fields, quarantine the entire record for human review, or allow the data to proceed. This is not a general-purpose data exploration tool; it is a production safeguard.
Prompt
PII and Personal Data Detection Prompt Template

When to Use This Prompt
Understand the ideal use cases, required context, and critical limitations for deploying the PII detection prompt in a production data sanitization pipeline.
Use this prompt when you need to enforce a data handling policy at the boundary of an AI system. For example, you might integrate it into an API middleware layer that inspects every user input to a chatbot, or into an ETL pipeline that processes customer feedback before it's stored in a data warehouse. The prompt is most effective when combined with a strict [OUTPUT_SCHEMA] that defines the exact JSON structure your downstream code expects, including fields for entity_type, matched_text, confidence_score, and char_offset. You should also provide a [CONSTRAINTS] block specifying your organization's definition of PII, such as whether you need to flag partial matches or obfuscated data (e.g., jane [dot] doe [at] email [dot] com). The confidence score is your primary lever for routing: a high-confidence SSN match can be automatically redacted, while a low-confidence address match might be routed to a manual review queue.
Do not use this prompt as a standalone compliance solution. It is a probabilistic detection layer, not a guarantee. It will fail on novel obfuscation techniques and can produce false positives on non-PII numeric patterns like order IDs or invoice numbers that resemble SSNs. Never use it to make automated decisions that have a legal or financial impact on an individual without a human-in-the-loop review step for flagged content. Before deploying, you must establish a robust evaluation harness using a golden dataset that includes both obvious PII and tricky negative cases. Your next step should be to copy the prompt template, define your strict output schema, and run it against your eval set to calibrate the confidence threshold that balances your risk tolerance against the operational cost of false alarms.
Use Case Fit
Where the PII and Personal Data Detection prompt works and where it does not. Use these cards to decide if this prompt fits your pipeline before you integrate it.
Good Fit: Unstructured Text Sanitization
Use when: you need to scan free-text fields, chat logs, support tickets, or documents for common PII types (SSN, email, phone, address, DOB) before they enter a model or a log. Guardrail: Pair the prompt with a strict output schema and a post-processing validator that confirms extracted entities match expected formats.
Bad Fit: Obfuscated or Encoded Data
Avoid when: PII is deliberately obfuscated (e.g., 'five five five, one two three four'), base64-encoded, or split across multiple messages. Guardrail: This prompt is a text classifier, not a cryptanalyst. Route suspected obfuscated inputs to a dedicated manual review queue instead of relying on automated detection.
Required Inputs
What you need: raw unstructured text, a defined PII taxonomy (which types to detect), and a confidence threshold for flagging. Guardrail: Without a clear taxonomy, the model will over-detect or miss critical types. Define the exact PII categories in the prompt's [PII_CATEGORIES] variable and enforce them in your eval suite.
Operational Risk: False Negatives on Non-Standard Formats
What to watch: phone numbers with unusual formatting, international addresses, or SSNs written with dots instead of dashes can be missed. Guardrail: Run a pre-processing normalization step (regex for common patterns) before the LLM call, and use the LLM as a secondary, context-aware detector for what regex cannot catch.
Operational Risk: False Positives on Numeric Patterns
What to watch: order numbers, product IDs, or timestamps can be misclassified as SSNs or phone numbers. Guardrail: Implement a confidence score threshold in the output schema. Route low-confidence detections for human review or suppress them if they match known non-PII patterns in your system.
Not a Replacement for DLP
Avoid when: you need real-time, sub-millisecond blocking of PII at the network perimeter. Guardrail: This prompt is for content-aware detection in an AI pipeline, not a substitute for a Data Loss Prevention (DLP) system. Use it as a complementary, context-rich layer behind your existing DLP and regex scanners.
Copy-Ready Prompt Template
A production-ready prompt for extracting PII from unstructured text with a strict JSON output contract.
This template is the core instruction set for a PII detection model. It is designed to be dropped directly into your application's prompt layer. The prompt enforces a strict JSON-only output, which is critical for preventing the model from adding conversational filler that would break a downstream parser. The schema includes character-level indices, allowing your application to redact or mask the original text programmatically without relying on the model to perform the redaction itself.
textYou are a PII detection system. Analyze the text provided below. Your task is to detect and extract any instances of Personally Identifiable Information (PII). You must return ONLY a valid JSON object conforming to the specified schema. Do not include any explanatory text outside the JSON object. PII types to detect: - SSN (US Social Security Number) - EMAIL (Email Address) - PHONE (Phone Number, any international format) - ADDRESS (Physical Street Address) - DOB (Date of Birth) For each detected instance, provide: - The exact text match. - The character start and end index of the match in the original text. - A confidence score between 0.0 and 1.0. - A brief reason for the confidence score if it is below 0.9. If no PII is detected, return an empty findings array. Text to analyze: """ [INPUT_TEXT] """ Output JSON Schema: { "findings": [ { "type": "string", "match": "string", "start_char": "integer", "end_char": "integer", "confidence": "number", "reason": "string" } ] }
To adapt this template, replace the [INPUT_TEXT] placeholder with the actual user-generated or system-generated text you need to scan. If your use case requires additional PII types, such as credit card numbers or driver's license IDs, add them to the bulleted list and ensure your downstream validation logic can handle the new type strings. For high-risk domains like healthcare or finance, you should increase the strictness by adding a [CONSTRAINTS] section that explicitly instructs the model to flag borderline cases for human review and to never guess on ambiguous numeric patterns.
Before deploying, you must pair this prompt with a JSON validation harness. The model may occasionally return malformed JSON, especially for very long inputs or edge cases with special characters. Your application logic should validate the output against the schema, retry with an error message if parsing fails, and log any instance where the start_char and end_char indices do not correctly map back to the expected match in the source text. This index verification is a critical eval step to prevent silent data corruption during redaction.
Prompt Variables
Required inputs for the PII and Personal Data Detection prompt. Each placeholder must be populated before the prompt is sent to the model. Validation notes describe how to verify the input is well-formed before execution.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[INPUT_TEXT] | Unstructured text to scan for PII | Customer email: john.doe@example.com, SSN 123-45-6789 | Non-empty string required. Reject null or whitespace-only input. Max 32K characters unless chunking is applied upstream. |
[PII_TYPES] | Comma-separated list of PII categories to detect | SSN, EMAIL, PHONE, ADDRESS, DOB, CREDIT_CARD | Must match allowed enum values. Reject unknown types. Validate against approved taxonomy before prompt assembly. |
[CONFIDENCE_THRESHOLD] | Minimum confidence score for a detection to be included in output | 0.85 | Float between 0.0 and 1.0. Values below 0.7 increase false positives; values above 0.95 increase false negatives. Default 0.85 if not specified. |
[INCLUDE_OBFUSCATED] | Whether to attempt detection of obfuscated PII patterns | Boolean: true or false. When true, prompt includes instructions for detecting spaced, hyphenated, or partially masked PII. Increases false positive risk. | |
[OUTPUT_SCHEMA] | JSON schema describing the expected output structure | {"type": "object", "properties": {"detections": {"type": "array"}}} | Must be valid JSON Schema. Validate with a schema parser before injection. Reject schemas that lack required 'detections' array field. |
[LOCALE] | Regional context for phone, address, and ID format validation | US | ISO 3166-1 alpha-2 country code. Affects phone regex, postal code patterns, and ID format expectations. Default 'US' if not provided. |
[MAX_DETECTIONS] | Upper bound on number of PII findings returned | 50 | Positive integer. Prevents unbounded output on large documents. Set based on downstream processing capacity. Null allowed for no limit but discouraged for production. |
Implementation Harness Notes
Wire the PII detection prompt into a production application with validation, retries, logging, and human review for high-risk findings.
Integrate this prompt as a synchronous pre-processing step within your application's middleware or API gateway. Before any user-generated text reaches a model, database, or logging pipeline, it should pass through this detection layer. The prompt expects a single [INPUT_TEXT] and returns a JSON object containing detected PII types, their values, and confidence scores. Your application must treat this as a blocking step: the downstream workflow should not proceed until the detection response is received and validated. For high-throughput systems, consider deploying this prompt against a fast, cost-efficient model like GPT-4o-mini or Claude Haiku, reserving more powerful models only for ambiguous cases that require re-evaluation.
On receiving the model's response, always validate the JSON structure against your expected schema before acting on any findings. A retry loop with a maximum of 2 attempts is recommended for handling malformed JSON or schema violations. If the model fails to return valid JSON after 2 retries, log the failure, flag the input for manual review, and block downstream processing. For high-confidence SSN or email matches (confidence >= 0.85), consider immediate redaction or tokenization before the text moves further through your system. For low-confidence matches or ambiguous PII types like dates of birth that could be benign, route the original text and the model's findings to a human review queue. This prevents over-redaction that could strip useful context while still catching clear violations.
Logging requires careful design. Never log the raw [INPUT_TEXT] alongside PII findings in plaintext. Instead, log a SHA-256 hash of the original text, the detected PII types, their confidence scores, and the action taken (redacted, queued, passed). This creates an audit trail that proves due diligence without creating a secondary PII store in your logs. If your application processes data subject to GDPR, HIPAA, or PCI-DSS, ensure your logging pipeline is covered by your existing data protection agreements and retention policies. For regulated environments, the human review queue should operate within the same compliance boundary as the original data processing, and reviewers should have clear instructions on when to redact, escalate, or clear a finding.
Expected Output Contract
Defines the exact JSON schema, field types, and validation rules for the PII detection prompt output. Use this contract to build a parser and validator before integrating the prompt into a data sanitization pipeline.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
pii_detected | boolean | Must be true if any PII entity is found; otherwise false. | |
entities | array of objects | Must be a valid JSON array. If empty, pii_detected must be false. | |
entities[].type | string (enum) | Must match one of the allowed PII types: [SSN, EMAIL, PHONE, ADDRESS, DOB, CREDIT_CARD, PASSPORT, DRIVERS_LICENSE]. | |
entities[].value | string | The exact substring from [INPUT_TEXT] that matched the PII pattern. Must not be empty. | |
entities[].confidence | number | Float between 0.0 and 1.0. Values below 0.7 should trigger a human review flag in the application layer. | |
entities[].char_offset | object | If present, must contain start and end integer keys representing the index in the original string. Null allowed. | |
entities[].redaction_suggestion | string | Must be one of: [REDACT, MASK, HASH, NONE]. NONE is only valid if confidence < 0.5. | |
error | string or null | If the model cannot parse the input, this field should contain a machine-readable error code (e.g., UNPARSEABLE_INPUT). Null if no error. |
Common Failure Modes
PII detection prompts fail in predictable ways that create regulatory exposure and broken data handling pipelines. These are the most common failure modes and how to guard against them before they reach production.
False Negatives on Obfuscated Data
What to watch: Users deliberately mask PII using spaces, special characters, or partial redaction (e.g., SSN: 123 45 6789, email at domain dot com). The model treats these as non-PII because they don't match standard format expectations. Guardrail: Include obfuscated examples in few-shot prompts and add a post-processing regex sweep for known obfuscation patterns before final classification.
False Positives on Numeric Patterns
What to watch: Non-PII numeric strings like order IDs, product SKUs, version numbers, or hex color codes trigger SSN, credit card, or phone number detection. This floods downstream quarantine queues with noise and erodes operator trust. Guardrail: Require contextual validation—a 9-digit number alone is not an SSN unless surrounded by identity language. Add a secondary context check before flagging.
Context Window Truncation
What to watch: Long documents exceed the model's context window, causing PII at the end of the input to be silently ignored. The model returns a clean classification while sensitive data passes through unexamined. Guardrail: Chunk inputs with overlap and run detection on each chunk independently. Aggregate results and flag any chunk-level positive, even if the full-document classification appears clean.
Multilingual PII Misses
What to watch: PII embedded in non-English text—addresses in CJK scripts, names in Arabic, phone numbers with non-US formatting—goes undetected because the prompt examples and format expectations are English-centric. Guardrail: Include locale-diverse few-shot examples and specify that PII detection must be language-agnostic. Test against a multilingual golden set before deployment.
Confidence Score Calibration Drift
What to watch: The model returns high confidence for obvious PII but also returns high confidence for borderline cases, making the confidence score useless for routing decisions. Operators can't distinguish clear hits from ambiguous ones. Guardrail: Require the model to output a confidence rationale alongside the score. Calibrate thresholds against a labeled dataset and route low-confidence detections to human review instead of automated redaction.
Structured Field Extraction Inconsistency
What to watch: The same PII entity is extracted with different field names or formats across runs—email vs email_address, phone vs phone_number, partial vs full extraction. Downstream systems break on schema mismatch. Guardrail: Enforce a strict output schema with required fields and format constraints. Validate output against the schema before accepting it, and retry with explicit format correction instructions on mismatch.
Evaluation Rubric
Use this rubric to test the PII detection prompt before production deployment. Each row defines a pass standard, a failure signal, and a concrete test method.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Standard PII Recall | All instances of SSN, email, phone, and address in the [GOLDEN_SET] are detected with a confidence score >= 0.90. | A known PII entity is missed (false negative) or scored below the threshold. | Run prompt against a curated dataset of 50 samples containing explicit PII. Assert recall >= 0.98. |
Non-PII Numeric Precision | Numeric patterns like order IDs, invoice numbers, and product codes are NOT flagged as PII. | A 9-digit order number is misclassified as an SSN (false positive). | Run prompt against a dataset of 50 samples containing only business identifiers. Assert precision >= 0.99. |
Obfuscated PII Detection | PII separated by spaces, special characters, or encoded in base64 is detected. | A social security number written as '123 45 6789' or 'MTIzLTQ1LTY3ODk=' is missed. | Run prompt against a dataset of 20 samples with obfuscated PII. Assert recall >= 0.95. |
Output Schema Compliance | The output is valid JSON matching the [OUTPUT_SCHEMA] for every test case. | The model returns plain text, a truncated JSON object, or an extra field not in the schema. | Validate output with a JSON Schema validator after each test run. Assert 100% structural validity. |
Confidence Score Calibration | Confidence scores for false positives are < 0.60, and for true positives are > 0.90. | A false positive has a confidence score of 0.95, or a true positive has a score of 0.40. | Plot a histogram of confidence scores for all test results. Assert a clear bimodal distribution separating correct and incorrect classifications. |
Empty Input Handling | The prompt returns an empty findings array | The model hallucinates PII or throws a tool-use error on empty input. | Pass an empty string and a string of 100 spaces. Assert output is |
Adjacency Boundary Handling | PII adjacent to punctuation or line breaks is correctly extracted without clipping. | An email like 'user@domain.com.' is extracted as 'user@domain.com' or missed entirely. | Run prompt against 20 samples with PII at the start, end, and middle of sentences with punctuation. Assert extracted value matches the ground truth exactly. |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Adapt This Prompt
How to adapt
Start with the base PII detection prompt and a simple JSON output schema. Use a frontier model (GPT-4o, Claude 3.5 Sonnet) with default temperature. Focus on the core PII types: SSN, email, phone, credit card, and address. Skip confidence scoring initially—just return found: true/false and the extracted value.
codeSystem: You are a PII detector. Analyze [INPUT_TEXT] and return JSON with detected PII. Output schema: { "pii_detected": boolean, "findings": [ { "type": "ssn|email|phone|credit_card|address", "value": "string", "position": {"start": number, "end": number} } ] }
Watch for
- Missing schema checks on malformed JSON
- Overly broad instructions that flag non-PII numeric patterns (invoice numbers, product codes)
- No handling of obfuscated data (e.g., "SSN: *--1234")
- False positives on sample/test data like "123-45-6789" in documentation

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us