Inferensys

Prompt

PII Redaction Prompt Before Tool Dispatch

A practical prompt playbook for security engineers building agent gateways. Produces a sanitized tool input with PII replaced by typed placeholders before external API calls. Includes eval checks for recall against known PII patterns and false-positive suppression on non-sensitive terms.
Developer demonstrating multi-agent tool use, agent tool selection interface on laptop, casual tech demo moment.
PROMPT PLAYBOOK

When to Use This Prompt

Define the job, reader, and constraints for a pre-flight PII redaction prompt that scrubs agent-generated tool arguments before they leave a trusted boundary.

This prompt is for security engineers building an agent gateway that must intercept and sanitize tool calls in real time. The job-to-be-done is a pre-flight redaction step: an AI agent has generated tool arguments that may contain live personally identifiable information (PII) from user sessions, and those arguments must be scrubbed before the payload is dispatched to a downstream API, database, or third-party service. The reader is responsible for preventing data exfiltration at the tool interface layer, not for cleaning up logs after the fact. This prompt assumes the agent's generated JSON or string arguments are structurally valid but may contain names, email addresses, phone numbers, government identifiers, or financial account numbers that must be replaced with typed placeholders while preserving the exact structure the receiving tool expects.

Use this prompt when the agent operates inside a trusted boundary with access to raw user data, but the tool it calls sits outside that boundary and should only receive de-identified payloads. The prompt is designed to be wired into a dispatch middleware that intercepts every tool call, applies the redaction, and then forwards the sanitized arguments. It is not a general-purpose PII scanner for free-text documents, nor is it a post-hoc log scrubber for audit trails. The prompt expects a structured input containing the original tool arguments and a configurable list of PII categories to redact, and it must return a structurally identical payload with detected entities replaced by typed placeholders such as [EMAIL_ADDRESS] or [PHONE_NUMBER]. The redaction must be deterministic enough to pass automated validation checks that compare the output schema against the input schema and verify that no known PII patterns remain.

Do not use this prompt when the tool itself requires real PII to function—for example, when calling a payment processor that needs a real credit card number or an identity verification service that requires a government ID. In those cases, the tool boundary is the compliance boundary, and redaction would break functionality. Do not use this prompt as a replacement for proper data access controls, encryption in transit, or API-level authentication. It is a defense-in-depth measure, not a primary security control. Before deploying, validate the prompt against a golden dataset of tool arguments containing known PII across multiple categories, measure both recall (did it catch all PII?) and false-positive suppression (did it leave non-sensitive terms alone?), and implement a human review step for any redacted payloads that fail structural integrity checks before they are released to production.

PRACTICAL GUARDRAILS

Use Case Fit

Where this prompt works, where it fails, and the operational conditions required before you wire it into a production agent gateway.

01

Good Fit: Pre-Dispatch Sanitization in Agent Gateways

Use when: an agent is about to call an external API, log a user message, or write to a shared store. Guardrail: place this prompt as a synchronous pre-flight step in the tool dispatch pipeline, blocking the call until sanitization succeeds.

02

Bad Fit: Free-Text Chat Without Tool Boundaries

Avoid when: the model is generating conversational text for a user-facing chat with no downstream API call. Guardrail: use output-side PII detection prompts instead; this prompt is designed for structured tool argument cleaning, not open-ended prose filtering.

03

Required Input: Typed PII Pattern Catalog

Risk: without a defined taxonomy of PII types (email, SSN, phone, credit card, etc.), the prompt will miss domain-specific identifiers. Guardrail: supply a configurable [PII_PATTERNS] block with regex patterns, context keywords, and entity types mapped to placeholder formats like <EMAIL> or <PHONE>.

04

Operational Risk: False Positives on Non-Sensitive Terms

Risk: aggressive redaction can strip product codes, UUIDs, or version strings that look like PII, breaking downstream tool calls. Guardrail: implement a pre-screen allowlist for known non-sensitive patterns and log every redaction decision with the matched pattern for audit and tuning.

05

Operational Risk: Redaction Bypass via Encoding or Concatenation

Risk: attackers or buggy upstream systems may split PII across fields, Base64-encode values, or use homoglyphs to evade regex-based detection. Guardrail: add a normalization step before redaction that decodes common encodings and normalizes Unicode, then re-scan the normalized form.

06

Operational Risk: Latency Budget Blowout at Dispatch Time

Risk: running a full PII scan on every tool call adds latency to every agent action, which compounds in multi-step workflows. Guardrail: set a strict timeout per redaction call, cache sanitized inputs when the same payload repeats, and escalate to a human review queue if the prompt exceeds the latency budget.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A stateless redaction engine prompt that sanitizes tool inputs by replacing PII with typed placeholders before external dispatch.

This prompt template instructs the model to act as a stateless PII redaction engine. It receives a raw tool input payload and a configurable list of PII categories to detect. The model must output only a valid JSON object containing the sanitized payload and a redaction map—no explanations, no conversational text. The template uses square-bracket placeholders for all variable inputs, making it ready to drop into an agent gateway or pre-dispatch middleware layer.

text
SYSTEM:
You are a stateless PII redaction engine. Your only job is to sanitize tool inputs before they are sent to external APIs.

INPUT:
- RAW_PAYLOAD: [RAW_PAYLOAD]
- PII_CATEGORIES_TO_REDACT: [PII_CATEGORIES]
- REDACTION_STYLE: [REDACTION_STYLE]
- EXEMPTION_LIST: [EXEMPTION_LIST]

RULES:
1. Scan every string field in RAW_PAYLOAD for PII matching the specified categories.
2. Replace each detected PII instance with a typed placeholder using the format: <[CATEGORY]_[INDEX]>.
3. Do NOT redact terms on the EXEMPTION_LIST, even if they match a PII pattern.
4. Preserve all JSON structure, keys, numbers, booleans, and nulls exactly as received.
5. Output ONLY a valid JSON object with two fields: "sanitized_payload" and "redaction_map".
6. The "redaction_map" must map each placeholder to its original value.
7. If no PII is found, return the original payload unchanged and an empty redaction map.

OUTPUT_SCHEMA:
{
  "sanitized_payload": <original JSON structure with PII replaced>,
  "redaction_map": {
    "<PLACEHOLDER>": "<original_value>",
    ...
  }
}

CONSTRAINTS:
- Do not add, remove, or reorder keys.
- Do not alter non-string values.
- Do not explain your decisions.
- Do not wrap the output in markdown fences.

To adapt this template, replace the square-bracket placeholders with your runtime values. [RAW_PAYLOAD] should be the serialized JSON string of the tool's input arguments. [PII_CATEGORIES] is a comma-separated list such as EMAIL, PHONE, SSN, CREDIT_CARD, IP_ADDRESS. [REDACTION_STYLE] controls the placeholder format—options include TYPED (e.g., <EMAIL_1>), HASHED (e.g., sha256::abc123), or MASKED (e.g., j***@domain.com). [EXEMPTION_LIST] is a JSON array of terms that should never be redacted, such as test email addresses or internal identifiers. For high-risk production use, always validate the output against the expected schema before forwarding the sanitized payload to the downstream tool.

Before deploying this prompt, implement a post-processing validator that confirms the sanitized_payload is valid JSON, structurally identical to the input, and contains no unreplaced PII patterns. Run regression tests with a golden dataset of known PII payloads and measure recall (did we catch all PII?) and false-positive rate (did we redact non-PII terms?). For regulated data, route any payload where the redaction map is non-empty to a human review queue before tool dispatch. Never rely solely on the model's redaction decision for compliance-critical workflows.

IMPLEMENTATION TABLE

Prompt Variables

Required inputs for the PII redaction prompt. Each placeholder must be populated before the prompt is dispatched to the model. Validation notes describe how to verify the input is well-formed before execution.

PlaceholderPurposeExampleValidation Notes

[RAW_USER_INPUT]

The original text or tool parameter string that may contain PII before redaction

Must be a non-empty string. Reject null or whitespace-only inputs before prompt assembly.

[PII_PATTERN_CATALOG]

A structured list of PII entity types to detect, each with a regex or description and a placeholder template

[{"type": "EMAIL", "pattern": "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}", "placeholder": "[EMAIL_REDACTED]"}]

Must be a valid JSON array. Each entry requires non-empty type, pattern, and placeholder fields. Validate with JSON schema before use.

[REDACTION_STRATEGY]

The replacement method: placeholder substitution, character masking, or full removal

placeholder_substitution

Must be one of: placeholder_substitution, character_masking, full_removal. Reject unknown values.

[OUTPUT_SCHEMA]

The expected JSON structure for the redacted output, including original text, redacted text, and a findings array

{"original": "...", "redacted": "...", "findings": [{"type": "EMAIL", "original_value": "...", "placeholder": "[EMAIL_REDACTED]", "start": 12, "end": 34}]}

Must be a valid JSON Schema object. Validate parseability. Findings array must include start and end character offsets.

[FALSE_POSITIVE_ALLOWLIST]

Terms or patterns that match PII regex but should not be redacted, such as example domains or test values

Must be a JSON array of strings. Each entry is case-insensitive matched. Empty array is allowed.

[CONFIDENCE_THRESHOLD]

Minimum confidence score (0.0-1.0) for a PII match to be included in the findings array

0.85

Must be a float between 0.0 and 1.0. Values below 0.7 may increase false positives; values above 0.95 may miss valid PII.

[MAX_REDACTION_LENGTH]

Maximum character length of the input string this prompt will process in a single call

10000

Must be a positive integer. Inputs exceeding this length should be chunked with overlap to avoid boundary-missed PII. Validate before dispatch.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the PII redaction prompt into a secure agent gateway with validation, retries, and audit logging.

This prompt is designed to sit inside a gateway middleware function that intercepts every tool call an agent attempts to make. The flow is: agent generates tool call → gateway intercepts → prompt redacts → gateway dispatches sanitized payload → gateway logs the mapping of placeholders to original values in a secure audit store. This architecture ensures that raw PII never leaves the trusted execution boundary and never appears in general-purpose logging systems like stdout, CloudWatch, or Datadog. The prompt itself is a secondary defense layer for context-aware PII detection that regex-based redaction misses, such as names embedded in unstructured text, addresses in non-standard formats, or PII disguised through natural language phrasing.

Validation and Retry Logic. Implement a strict JSON schema validator on the model's output to ensure it returns exactly {"tool_name": "...", "arguments": "..."}. The tool_name must match the intercepted call's original tool name, and arguments must be a valid JSON string containing the sanitized payload. If validation fails, retry the prompt once with a stronger instruction appended to the system message, such as 'Your previous output failed schema validation. Return ONLY the JSON object with tool_name and arguments fields.' If the second attempt also fails validation, block the tool call entirely and alert a human operator through your incident management pipeline. Do not fall through to the original unsanitized payload under any circumstances.

Audit Trail Requirements. The gateway must persist a mapping record for every redaction operation. Store the original value, the assigned placeholder (e.g., [PERSON_NAME_1]), the PII type detected, and a timestamp in a dedicated audit database with strict access controls. This mapping is essential for debugging, compliance, and data subject access requests. Never log this mapping to general logging systems. The audit store should be append-only with immutable records, and access should require a break-glass procedure with approval. For high-throughput systems, consider batching audit writes asynchronously but never drop a record on failure—buffer and retry until persistence succeeds.

Model Selection and Latency Budget. This prompt adds a full model inference round-trip to every tool call, so latency is a primary design constraint. Use a small, fast model optimized for classification and extraction tasks rather than a large general-purpose model. Models in the 1-8B parameter range with strong JSON mode support are appropriate. Set a strict timeout (e.g., 500ms) on the redaction call. If the model times out, treat it as a validation failure and follow the retry-then-block escalation path. For non-sensitive tool calls that don't involve user data, consider bypassing this prompt entirely based on a tool-level sensitivity classification to avoid unnecessary latency.

What to Avoid. Do not use this prompt as your only PII defense. It is a secondary, context-aware layer that complements deterministic regex-based redaction, not a replacement for it. Regex catches structured patterns like email addresses, phone numbers, and credit card numbers with near-perfect recall and zero latency. Run regex first, then pass the partially redacted text to this prompt to catch what regex missed. Also, never send the original unsanitized payload as a fallback—if the redaction pipeline fails, the tool call must be blocked, not degraded. Finally, test this prompt regularly against your organization's specific PII patterns, because general-purpose PII detection models may miss domain-specific identifiers like internal customer IDs, project codes that embed personal data, or industry-specific regulated fields.

IMPLEMENTATION TABLE

Expected Output Contract

The sanitized JSON object the prompt must return. Validate this schema before forwarding to any downstream tool.

Field or ElementType or FormatRequiredValidation Rule

sanitized_input

object

Must be valid JSON. Must contain all original keys from [RAW_TOOL_INPUT] with no additions or omissions.

sanitized_input.<field>

string

If original value contained PII, must be replaced with typed placeholder like [EMAIL_REDACTED] or [PHONE_REDACTED]. If no PII, must match original value exactly.

redaction_map

array of objects

Each object must have keys: 'field' (string), 'original_type' (string from [PII_TYPE_LIST]), 'placeholder' (string), 'confidence' (number 0-1). Array may be empty if no PII found.

redaction_map[].field

string

Must be a valid JSON path to the redacted field within sanitized_input. Must match exactly one field.

redaction_map[].original_type

string

Must be one of the types defined in [PII_TYPE_LIST]. No custom types allowed.

redaction_map[].placeholder

string

Must match the value in sanitized_input at the specified field. Must follow pattern [TYPE_REDACTED].

redaction_map[].confidence

number

Must be between 0.0 and 1.0 inclusive. Values below [CONFIDENCE_THRESHOLD] should still be included but flagged for review.

audit_trail

object

Must contain 'redaction_timestamp' (ISO 8601), 'prompt_version' (string), 'total_fields_checked' (integer), 'total_redactions' (integer).

PRACTICAL GUARDRAILS

Common Failure Modes

PII redaction prompts fail in predictable ways. These are the most common failure modes observed in production agent gateways, along with concrete guardrails to prevent them.

01

False Negatives on Non-Standard PII Formats

What to watch: The prompt misses PII in unusual formats—email addresses with obfuscation like user[at]domain[dot]com, phone numbers with letter mnemonics, or national IDs with non-standard separators. The model treats these as benign text and passes them through to external APIs. Guardrail: Include 5-10 counterexamples of non-standard PII formats in the few-shot examples. Add a post-redaction regex sweep for known pattern variants as a second-pass safety net before tool dispatch.

02

False Positives on Business Identifiers

What to watch: The prompt over-redacts legitimate business data—company registration numbers, public support ticket IDs, generic department email aliases like support@company.com, or API endpoint URLs containing org slugs. This breaks downstream tool calls that need these identifiers to function. Guardrail: Provide explicit allowlist examples in the system prompt for business identifiers that must pass through. Add eval test cases that measure false-positive rates on a golden set of benign business strings and tune the prompt until the rate drops below 2%.

03

Placeholder Collision and Loss of Entity Distinction

What to watch: The prompt replaces all detected PII with generic placeholders like [REDACTED] or [PII], destroying the distinction between different entities. A tool call that needs to differentiate between two people in the same input receives [REDACTED] for both and produces incorrect results. Guardrail: Require typed placeholders in the output schema—[PERSON_NAME_1], [EMAIL_ADDRESS_1], [PHONE_1]—with consistent numbering across the redacted output. Validate placeholder uniqueness and type consistency in post-processing before tool dispatch.

04

Contextual PII Leakage Through Surrounding Text

What to watch: The prompt redacts the explicit PII field but leaves surrounding context that enables re-identification—a redacted name next to a unique job title, location, and recent event that together identify the individual. The sanitized output still leaks personally identifiable information through inference. Guardrail: Add a secondary check instruction that flags combinations of quasi-identifiers. Use k-anonymity thresholds: if fewer than K individuals could match the remaining attributes, escalate for human review or apply broader redaction to the surrounding context.

05

Structured Field Bypass in Nested JSON

What to watch: The prompt successfully redacts PII in flat text but misses PII buried in nested JSON structures, escaped strings, or base64-encoded payloads within the tool input. The model treats the structured wrapper as opaque and passes the inner PII through unredacted. Guardrail: Include explicit instructions to recursively traverse all JSON keys and string values. Add pre-processing that decodes common encodings (base64, URL-encoding) before the redaction prompt runs. Validate with test cases containing PII at multiple nesting depths and inside encoded fields.

06

Redaction Drift Under High Token Pressure

What to watch: When the input is near the context window limit, the model skips or truncates redaction to stay within token bounds. PII near the end of long documents or in large tool payloads passes through unredacted because the model prioritizes output completion over safety. Guardrail: Chunk large inputs before redaction and process each chunk independently with the full redaction prompt. Set a hard token budget for each chunk that leaves room for the redaction instructions. Add an end-to-end test that verifies redaction completeness on inputs at 90%+ of the context window.

IMPLEMENTATION TABLE

Evaluation Rubric

Use this rubric to test the PII redaction prompt before deploying it in a production agent gateway. Each criterion defines a pass standard, a failure signal, and a concrete test method.

CriterionPass StandardFailure SignalTest Method

PII Recall

All instances of [PII_PATTERNS] in the input are replaced with typed placeholders (e.g., [EMAIL_ADDRESS_1]).

Original PII value appears unredacted in the output.

Run against a golden dataset of 100 inputs with known PII. Assert 100% recall; any miss is a failure.

False-Positive Suppression

Non-sensitive terms that match PII-like patterns (e.g., 'test@example') are not redacted.

A benign term like a sample API key or placeholder is incorrectly redacted.

Run against a curated list of 50 false-positive triggers. Assert fewer than 2% false-positive rate.

Placeholder Consistency

The same PII value in a single input always maps to the same placeholder (e.g., [PHONE_1]).

The same email address is replaced with [EMAIL_1] in one place and [EMAIL_2] in another.

Parse the output. For each unique PII value in the input, verify exactly one placeholder label is used.

Structural Integrity

The output preserves all non-PII text, JSON keys, and formatting exactly as in the input.

A JSON key is dropped, a line break is removed, or a non-PII word is altered.

Perform a character-level diff between the input and output, ignoring only the redacted spans. Assert zero differences.

Schema Preservation

If [INPUT] is valid JSON, the output is valid JSON with the same structure.

The output is unparseable JSON or has a different key structure.

Run json.loads() on the output. Assert no parse error and that output.keys() == input.keys().

Tool Argument Safety

The redacted output is safe to pass to the target tool without leaking PII to an external API.

A redacted placeholder still contains a recognizable PII substring (e.g., [EMAIL_john.doe@...]).

Scan all placeholder values with the same PII regex patterns used for detection. Assert zero matches.

Latency Budget

Redaction completes within [MAX_LATENCY_MS] for inputs up to [MAX_INPUT_LENGTH] characters.

The prompt call exceeds the latency budget, blocking the tool dispatch path.

Measure end-to-end prompt latency over 100 calls. Assert p99 latency is below the threshold.

Refusal Handling

If the input contains no PII, the output is identical to the input with no added commentary.

The model adds an explanation like 'No PII found' or wraps the output in a markdown block.

Run on 20 clean inputs. Assert the output string is byte-for-byte identical to the input.

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Use the base prompt with a simple list of PII categories and placeholder types. Focus on recall over precision. Accept the default output format without strict schema enforcement.

code
Redact all PII in [INPUT_TEXT] before sending to [TOOL_NAME].
Replace with typed placeholders like [EMAIL], [PHONE], [SSN].
Return the sanitized text and a list of redactions.

Watch for

  • False positives on non-sensitive terms like product codes or version strings
  • Missing schema checks leading to inconsistent placeholder formats
  • Overly broad instructions that redact business-necessary identifiers
Prasad Kumkar

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.