This prompt is a privacy engineering tool for the detection stage of a data pipeline. Its job is to scan a block of unstructured text and return a structured set of boolean flags indicating the presence or absence of specific Personally Identifiable Information (PII) types. The ideal user is a backend engineer, data platform developer, or AI product builder who needs to programmatically decide what to do with a piece of text before it is logged, stored, or sent to a third-party model. It answers the question 'What is here?' so your application logic can enforce data handling policies, such as redaction, rejection, or routing to a high-security processing tier. This is a detection step, not a redaction step.
Prompt
PII Detection Flag Prompt Template

When to Use This Prompt
Defines the job-to-be-done, the ideal user, and the operational boundaries for the PII Detection Flag Prompt Template.
Use this prompt when you need a structured, machine-readable privacy signal to drive an automated workflow. Common integration points include: a pre-processing hook before an LLM call, a guardrail in a logging pipeline, or a filter before data enters a vector database. The prompt requires a clear [INPUT] text block and a predefined [PII_TYPES] list (e.g., name, email, phone, ssn, address). You must also provide an [OUTPUT_SCHEMA] that defines the exact boolean flag structure you expect. Do not use this prompt for direct user-facing redaction, as it does not return a sanitized string. Do not use it as a standalone compliance guarantee; its output is a probabilistic signal that should be paired with downstream validation and, for high-risk regulated data, a human review step.
Before implementing, define your tolerance for false positives and false negatives. A false positive (flagging non-PII as PII) might over-redact and degrade data utility, while a false negative (missing real PII) is a compliance risk. Your application logic should handle both cases. For example, a low_confidence flag in the output can trigger a review queue instead of an automated action. After reading this section, proceed to the prompt template to see the exact instruction structure, then review the implementation harness to understand how to wire this into a production system with validation, retries, and logging.
Use Case Fit
Where the PII Detection Flag prompt template works well, where it introduces risk, and the operational preconditions required before deployment.
Good Fit: Pre-Ingestion Redaction Pipelines
Use when: sanitizing text before it enters a vector database, log aggregator, or LLM context window. Guardrail: route flagged documents to a redaction microservice before any other processing stage.
Bad Fit: Real-Time User-Facing Chat
Avoid when: latency budget is under 200ms or when false positives would block legitimate user messages. Guardrail: use a lightweight regex pre-filter for obvious patterns and reserve the LLM call for ambiguous cases only.
Required Input: Unstructured Free-Text
Use when: the source is raw text from emails, tickets, transcripts, or documents. Guardrail: strip HTML, Markdown, and base64-encoded blobs before passing to the prompt to reduce token waste and false negatives.
Operational Risk: False Negatives on Obfuscated PII
Risk: the model misses PII split across tokens, written in leetspeak, or embedded in code comments. Guardrail: combine the LLM flag with a deterministic scanner for high-signal patterns (e.g., 9-digit numbers with valid SSN checksums).
Operational Risk: Over-Flagging in Dense Text
Risk: long documents with many names, dates, and IDs trigger all flags, causing downstream systems to reject or redact entire payloads. Guardrail: return per-type flags with character spans so the application can redact only confirmed spans instead of blocking the whole document.
Bad Fit: Structured Data Columns
Avoid when: input is already in typed columns (e.g., a CSV with a 'phone_number' field). Guardrail: use schema-aware validation on known columns and reserve the LLM prompt only for free-text comment fields.
Copy-Ready Prompt Template
A production-ready prompt template for detecting the presence of PII types in text and returning boolean flags.
This template is designed to be dropped directly into your application code. It instructs the model to act as a privacy-preserving PII detector that only returns boolean flags—never the PII values themselves. The prompt uses strict JSON output constraints, explicit definitions for each PII type, and a reasoning field to capture ambiguity. This design keeps sensitive data out of model responses and logs, which is critical for compliance with data handling policies.
textYou are a privacy-preserving PII detection system. Your task is to analyze the provided text and determine the presence of specific types of Personally Identifiable Information (PII). **CRITICAL RULES:** - Do NOT extract, redact, or repeat the actual PII values. - Return ONLY a JSON object with boolean flags for each PII type. - If a PII type is not found, its flag must be `false`. - If the text is ambiguous, set the flag to `true` and explain the ambiguity in the `reasoning` field. **PII Types to Detect:** - `person_name`: Full names (e.g., John Smith), including partial names if clearly referring to an individual. - `email_address`: Email addresses (e.g., user@domain.com). - `phone_number`: Phone numbers in any standard format, including country codes. - `ssn`: U.S. Social Security Numbers in XXX-XX-XXXX format or similar. - `physical_address`: Street addresses, city/state/zip combinations, or full postal addresses. - `ip_address`: IPv4 or IPv6 addresses. - `credit_card`: Credit card numbers matching common issuer patterns. - `date_of_birth`: Explicit birth dates or age references that could identify an individual. **Input Text:** [INPUT_TEXT] **Output Format:** Return ONLY a valid JSON object with this exact structure: { "person_name": boolean, "email_address": boolean, "phone_number": boolean, "ssn": boolean, "physical_address": boolean, "ip_address": boolean, "credit_card": boolean, "date_of_birth": boolean, "reasoning": "Brief explanation of any ambiguous detections or why all flags are false." }
To adapt this template, modify the PII types list to match your organization's data classification policy. You can add types like passport_number, driver_license, or bank_account by defining them clearly in the list and adding the corresponding boolean field to the output schema. If your use case requires detection of PII in specific formats (e.g., only validated email patterns), add those constraints to the type definitions. For high-risk production environments, pair this prompt with a post-processing validator that confirms the output JSON contains no extracted values—this is a critical safety check before the response enters your logging pipeline.
Prompt Variables
Inputs required for the PII Detection Flag prompt to produce reliable boolean flags per PII type. Each placeholder must be populated before the prompt is sent to the model. Validation notes describe how to check that the input is well-formed before execution.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[INPUT_TEXT] | The raw text to scan for PII. Must be a single string; multi-document batches should be split before calling this prompt. | Customer called from 555-123-4567 and left email jane@example.com regarding account #A-9982. | Check that string length is between 1 and the model's context limit minus prompt overhead. Reject empty or null inputs before model call. |
[PII_TYPES] | A JSON array of PII categories to detect. Each entry maps to a boolean flag in the output. Use the exact enum values the downstream system expects. | ["email_address", "phone_number", "ssn", "credit_card", "ip_address", "physical_address", "person_name"] | Validate that the array is non-empty and every value is a string matching the allowed enum set. Reject unknown type strings before model call to prevent silent misses. |
[CONFIDENCE_THRESHOLD] | A float between 0.0 and 1.0. The model should only return true for a PII type if its internal confidence exceeds this threshold. Lower values increase recall; higher values increase precision. | 0.85 | Parse as float and assert 0.0 <= value <= 1.0. If null or missing, default to 0.80 and log a warning. Values below 0.60 risk high false-positive rates in production. |
[OUTPUT_SCHEMA] | The exact JSON schema the model must return. Include field names, types, and the required array. This constrains the model to structured output and prevents free-text drift. | {"type": "object", "properties": {"flags": {"type": "object"}, "confidence_scores": {"type": "object"}, "ambiguous_spans": {"type": "array"}}, "required": ["flags", "confidence_scores"]} | Validate that the schema is valid JSON and includes a required field for every PII type in [PII_TYPES]. Schema mismatch between input types and output fields is a common silent failure. |
[FALSE_POSITIVE_EXAMPLES] | A list of strings that look like PII but are not, specific to the domain. Helps the model calibrate its boundary between real and spurious matches. | ["Call 555-HELP for support", "Reference ID: 123-45-6789-X", "Room 404, Building A"] | Check that the list contains at least 3 examples if the domain has known false-positive patterns. Empty list is allowed but increases false-positive risk. Each example should be a real pattern observed in production data. |
[AMBIGUITY_POLICY] | A string enum controlling how the model handles borderline cases. Options: 'flag_as_true', 'flag_as_false', 'mark_ambiguous'. Determines the default behavior when confidence is near the threshold. | mark_ambiguous | Validate that the value is one of the three allowed enums. If null or missing, default to 'mark_ambiguous' and log. 'flag_as_true' is risky in high-precision redaction pipelines. |
[LOCALE_HINTS] | An optional string or array of locale codes (e.g., 'en-US', 'de-DE') that helps the model interpret region-specific PII formats like phone numbers, postal codes, and ID numbers. | ["en-US", "en-CA"] | If provided, validate each entry against a known locale list. Null is allowed and means the model will use its default locale assumptions. Missing locale hints cause format mismatches for non-US PII. |
Implementation Harness Notes
How to wire the PII Detection Flag prompt into a production application with validation, retries, logging, and human review gates.
The PII Detection Flag prompt is a classification step, not a redaction step. Wire it into your pipeline before any text is stored, logged, or sent to external models. The prompt returns a structured JSON payload with boolean flags per PII type and a confidence score. Your application should treat this output as a decision signal: route flagged text to a review queue, block it from downstream processing, or trigger automated redaction. Never rely on the prompt alone for compliance; it is a detection layer that must be paired with deterministic validation and, for regulated data, human review.
Implement a validation wrapper around the model response. Parse the JSON output and check that all expected keys are present (name, email, phone, ssn, address, credit_card, ip_address, date_of_birth, overall_confidence). If the model returns malformed JSON, missing keys, or values that aren't booleans (for flags) or floats between 0 and 1 (for confidence), reject the response and retry with a stricter prompt that includes the raw parse error. Log every parse failure and retry attempt. For high-throughput pipelines, set a maximum of 2 retries before falling back to a conservative needs_review: true flag and routing to a human queue. Use a model with strong JSON mode support (GPT-4o, Claude 3.5 Sonnet, or equivalent) and set response_format to json_object where the API supports it.
Build a confidence threshold gate into your harness. The overall_confidence field reflects the model's certainty that its boolean flags are correct. For low-risk workflows (internal analytics on anonymized data), you might auto-approve text with confidence above 0.9. For high-risk workflows (customer PII in support tickets, healthcare text, financial documents), route anything below 0.95 to human review, and consider routing all flagged text to review regardless of confidence. Store the raw prompt response, the validation result, the retry count, and the final routing decision in your audit log. This traceability is essential for governance reviews and debugging false positives. If you observe a PII type that frequently produces false positives (e.g., address flagging on phrases like 'the office is located at'), add few-shot counterexamples to the prompt template or implement a post-processing regex denylist for known false-positive patterns.
Finally, treat this prompt as one component in a defense-in-depth privacy architecture. Before the prompt runs, apply deterministic regex and NER-based scanners for known PII formats (SSN patterns, email regex, phone number formats). Use the LLM prompt to catch ambiguous or unstructured PII that regex misses (e.g., 'my social is 123 45 6789' written in prose). After detection, redaction should happen in application code using the boolean flags and evidence spans, not by asking the model to rewrite the text. The model's job is to flag, not to redact. If you need the model to extract the specific PII values for redaction, use a separate extraction prompt with strict output schema and never log the extracted values in plaintext.
Expected Output Contract
Validation rules for the JSON response returned by the PII Detection Flag prompt. Use this contract to parse, validate, and route the model's output before downstream redaction or storage.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
pii_flags | object | Top-level object must be present. Reject response if missing or not a JSON object. | |
pii_flags.[PII_TYPE] | boolean | Each key in the [PII_TYPE_LIST] placeholder must map to a boolean value. Reject if any key is missing or value is not true/false. | |
pii_flags.overall_pii_detected | boolean | Must equal true if any pii_flags.[PII_TYPE] is true, else false. Reject on mismatch; this is a consistency check. | |
confidence | string | Must be one of the enum: high, medium, low. Reject any other value. If confidence is low, route output for human review regardless of flags. | |
rationale | string | If present, must be a non-empty string. Null allowed. If overall_pii_detected is true, rationale should reference the specific PII types found. | |
needs_human_review | boolean | Must be true if confidence is low or if any ambiguous format is detected. Downstream system must not auto-redact when this flag is true. | |
evidence_spans | array of objects | If present, each object must contain type (string), text (string), and start_char (integer). Validate that start_char is within [INPUT_TEXT] length bounds. Null allowed. |
Common Failure Modes
PII detection prompts fail in predictable ways. These are the most common production failure modes and the guardrails that catch them before they cause harm.
False Negatives on Ambiguous Formats
What to watch: The prompt misses PII when formats deviate from expected patterns—phone numbers with unusual separators, names with special characters, or addresses without standard postal codes. The model defaults to 'not detected' for anything that doesn't match its internal template. Guardrail: Include 3-5 ambiguous format examples in few-shot demonstrations. Add a post-processing rule that flags any text containing numeric sequences or @ symbols for human review if no PII was detected.
Over-Flagging Common Nouns as Names
What to watch: The model classifies common words, product names, or organizational terms as person names—'Apple', 'Amazon', 'Hope', 'Grace'. This inflates false positive rates and triggers unnecessary redaction. Guardrail: Maintain a domain-specific exclusion list (company names, product names, common terms in your corpus). Run a second-pass validator that checks flagged names against a known entity database before redaction.
Context Window Truncation Splitting PII
What to watch: Long documents split across context windows can break PII spans—a credit card number split across two chunks, or an address where the street is in one chunk and the city in another. Each chunk independently returns 'no PII detected.' Guardrail: Implement overlapping chunk windows with a minimum 50-token overlap. Add a chunk-boundary reconciliation step that re-scans text near chunk edges for partial PII patterns.
Confidence Drift on Edge-Case Inputs
What to watch: The model assigns high confidence to clear PII and low confidence to ambiguous cases, but the middle ground—moderately ambiguous formats—produces inconsistent confidence scores across similar inputs. This makes threshold-based automation unreliable. Guardrail: Calibrate confidence thresholds against a labeled golden dataset of 200+ edge cases. Route any detection with confidence between 0.4 and 0.7 to a human review queue rather than auto-redacting.
PII Leakage Through Reasoning Tokens
What to watch: When the prompt asks the model to 'explain your reasoning' or 'cite the evidence span,' the reasoning output itself contains the raw PII. If reasoning tokens are logged or stored, they become a secondary PII leak vector. Guardrail: Never request inline evidence spans that contain the PII value. Instead, ask for character offsets or anonymized span references. Strip reasoning tokens from all logs and storage before persistence.
Schema Drift When PII Types Evolve
What to watch: The prompt's PII type taxonomy is static, but your compliance requirements change—new regulations add biometric data, device IDs, or geolocation as PII categories. The prompt silently misses these new types because they aren't in the enum. Guardrail: Version your PII type schema alongside the prompt. Run a quarterly audit comparing your detection taxonomy against current regulatory requirements. Add a catch-all 'potential_pii_other' flag for types not yet in the schema.
Evaluation Rubric
Criteria for testing the PII Detection Flag prompt before deployment. Each row defines a pass standard, a failure signal, and a concrete test method.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Schema Compliance | Output is valid JSON matching the [OUTPUT_SCHEMA] exactly, with all required boolean fields present. | Missing fields, extra fields, or non-boolean values in flag fields. | Schema validation assertion in test suite against 50+ diverse text samples. |
True Positive Detection | Flags correctly return true for explicitly stated PII (e.g., 'John Smith' sets name_detected to true). | False negative: a clearly present PII type is flagged as false. | Curated dataset of 100 texts with known PII presence; assert flag match rate > 0.98. |
True Negative Detection | Flags correctly return false for text containing no PII of a given type. | False positive: a non-PII string triggers a flag (e.g., 'April' sets date_of_birth_detected to true). | Curated dataset of 100 PII-free texts; assert false positive rate < 0.02 per flag. |
Ambiguous Format Handling | Text with format-like patterns but no semantic PII (e.g., 'Call 555-HELP' or 'ID: 123-45-6789-00') is flagged as false or annotated with low confidence. | Pattern-only match without semantic check causes a false positive. | Adversarial test set of 20 ambiguous strings; manual review of flag correctness. |
Null Input Handling | Empty string or null [INPUT] returns all flags as false and no error. | Prompt errors, returns invalid JSON, or hallucinates flags for empty input. | Unit test with empty string and null input; assert valid schema and all flags false. |
Multi-Type PII Detection | Text containing multiple PII types (e.g., name, email, phone) returns true for all relevant flags and false for others. | Only one type detected when multiple are present, or cross-contamination between flag types. | Synthetic text with 3+ PII types combined; assert all expected flags are true and others false. |
Adjacent Non-PII Discrimination | Text with PII-adjacent content (e.g., 'the patient reported chest pain' without naming the patient) does not trigger false flags. | Contextual proximity to medical or personal topics triggers false positive PII flags. | Test set of 30 clinical/financial texts with all PII redacted; assert all flags false. |
Confidence Annotation Accuracy | When [INCLUDE_CONFIDENCE] is true, confidence scores are present, between 0.0 and 1.0, and low-confidence flags correlate with genuinely ambiguous spans. | Confidence scores missing, out of range, or high confidence assigned to clearly ambiguous cases. | Spot-check 50 outputs with confidence enabled; verify score range and correlation with human ambiguity judgment. |
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 prompt and a simple JSON schema. Use a single model call per text block. Skip confidence scoring and evidence spans initially—just return boolean flags per PII type. Test against a small set of known-clean and known-dirty samples.
codeReturn JSON with boolean flags for each PII type found in [TEXT]. Types: name, email, phone, ssn, address, credit_card, ip_address, dob. If a type is not present, return false.
Watch for
- False positives on number patterns that look like SSNs or phone numbers but aren't
- Over-flagging of business names as personal names
- No handling of ambiguous formats (e.g., 9-digit strings that could be SSN or ID)

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