Skip to content

PII redaction for LLM prompts: removing Aadhaar, PAN, card numbers and secrets before they leave your network

PII redaction for LLM prompts, step by step: detect Aadhaar, PAN, card numbers and secrets, choose block, redact or alert, and test rules before go-live.

Ayati Cytech ResearchPublished 7 min read

PII redaction for LLM prompts means finding personal and sensitive data in a prompt — Aadhaar, PAN, card numbers, passwords and API keys — and removing or blocking it before the request leaves your network for an AI model provider. Done well, people keep using AI for real work and the model never sees the values that matter.

This how-to covers what to detect, how to detect it accurately, how to decide between block, redact and alert, and how to test rules before you switch them on. The examples use Indian identifiers because those are the ones most generic tools handle worst.

Why redact prompts at all?

Prompts are where sensitive data leaks into AI. A support agent asks a model to draft a reply and pastes the customer’s complaint, PAN included. A developer pastes a stack trace that contains a database connection string. A finance analyst pastes a list of card transactions to categorise.

OWASP’s 2025 Top 10 for LLM applications lists sensitive information disclosure as the second risk and recommends detecting and redacting sensitive content before it is processed. In India, the Digital Personal Data Protection Act, 2023 requires reasonable security safeguards for personal data. Redacting identifiers before they reach a third-party model is one of the clearest safeguards you can demonstrate.

What should you detect?

Start with structured identifiers — they are high-risk and can be detected precisely.

Data type Format How to validate Typical action
Aadhaar number 12 digits, often written in groups of four Final digit is a Verhoeff check digit Redact
PAN 10 characters: five letters, four digits, one letter Fourth letter indicates holder type (P for individual, C for company and so on) Redact
Payment card number Usually 15–16 digits, sometimes up to 19 Luhn checksum Redact or block
Private keys -----BEGIN … PRIVATE KEY----- blocks Header and footer match Block
API keys and tokens Vendor-specific prefixes and lengths Prefix plus length and character set Block
Passwords and connection strings password=, pwd=, URIs with credentials Key–value context Block or redact

Then add business-specific terms: internal project code names, client names under NDA, or document classification labels such as “Strictly Confidential”. These are usually keyword or category rules rather than pattern rules.

How do you detect Indian identifiers accurately?

The biggest problem with naive pattern matching is false positives. Twelve-digit numbers appear everywhere — order IDs, reference numbers, timestamps. A rule that redacts all of them makes prompts useless and teaches people to work around the tool.

Three techniques make detection precise:

  1. Validate check digits. An Aadhaar number’s final digit is a Verhoeff check digit, and card numbers carry a Luhn checksum. A random 12-digit order number passes the Verhoeff check only about one time in ten, so validation removes most false matches.
  2. Allow for real-world formatting. People write 2345 6789 0123, 2345-6789-0123 and 234567890123. Match all three, and the masked form UIDAI uses (XXXX XXXX 0123) should be recognised as already safe. UIDAI’s own masked Aadhaar shows only the last four digits.
  3. Use context words. “Aadhaar”, “UID”, “PAN”, “card ending” or “CVV” near a match raises confidence. A match with no context and a failed checksum can be ignored.

PAN is easier: the five-letters, four-digits, one-letter structure is distinctive, and the fourth character must be one of the defined holder-type letters. Uppercase normalisation catches people who type it in lower case.

Block, redact or alert: how do you choose?

Every rule needs an action. The choice depends on whether the task still makes sense without the data.

  • Redact replaces the value with a placeholder such as [PAN] or [AADHAAR] and lets the request continue. Use it when the model needs the surrounding text but not the identifier itself — summarising a complaint, drafting a reply, classifying a document.
  • Block stops the request and tells the user why. Use it for content that must never leave: private keys, passwords, production connection strings, documents marked with your highest classification.
  • Alert lets the request through and records it. Use it while tuning a new rule, or for lower-risk categories where you want visibility but not friction.

A practical default for a regulated enterprise:

Category Default action Notes
Aadhaar, PAN Redact Placeholders keep the prompt useful
Card numbers Redact Block for teams that should never handle card data
Private keys, passwords Block Explain to the user how to remove them
Cloud and API keys Block Also rotate the key; it was exposed on the user’s screen
Client names under NDA Alert, then redact Tune with the business owner

Rules should be scoped. A fraud analytics team may legitimately work with card data in an approved internal model, while the same data from the marketing team should be redacted. Scoping rules to groups, people, models or tools avoids one-size-fits-all friction.

Where should redaction happen?

At a single control point that every AI request passes through — an AI gateway inside your network. The alternatives each leave gaps:

  • A browser extension misses coding assistants in the terminal or IDE, scripts and internal applications.
  • Redaction inside each application means implementing and maintaining the same rules many times.
  • Trusting the model provider to discard data does not stop the data leaving your network.

A gateway sees chat apps, coding assistants such as Claude Code, Codex and Cursor, and your own applications in the same way. It also writes the audit record of what was redacted or blocked, which is the evidence you will need later.

A worked example

A relationship manager at contoso.in asks an AI assistant to draft a reply:

Customer Ravi Kumar, PAN ABCPK1234Q, Aadhaar 2345 6789 0124, says his card ending 4321 was charged twice on 12 May. Draft a polite reply confirming we are investigating.

After redaction at the gateway, the model receives:

Customer Ravi Kumar, PAN [PAN], Aadhaar [AADHAAR], says his card ending 4321 was charged twice on 12 May. Draft a polite reply confirming we are investigating.

The reply is just as good. The last four digits of the card are left alone because they are not a full card number and the customer will recognise them. The audit trail records that two identifiers were redacted, for which user, through which app, to which model. (The numbers above are illustrative, not real identifiers.)

How to roll out prompt redaction in six steps

  1. Route AI traffic through the gateway. Configure approved chat and coding tools to use it, with per-user identity.
  2. Enable the built-in identifier rules in alert-only mode. Run for two to four weeks.
  3. Review what fires. Look for false positives (order numbers flagged as Aadhaar) and false negatives (formats you missed).
  4. Switch Aadhaar, PAN and card rules to redact; secrets to block. Write a short, helpful block message that tells people what to remove.
  5. Add business rules for client names, project code names and classification labels, scoped to the right groups.
  6. Review monthly. Track redaction volume by team; a sudden rise usually means a new workflow that deserves a proper solution.

A prompt redaction checklist

  • All AI traffic — chat, coding assistants, internal apps — passes through one gateway
  • Aadhaar detection validates the Verhoeff check digit and handles spaces and hyphens
  • PAN detection checks structure and holder-type letter, case-insensitive
  • Card detection validates with Luhn
  • Private keys, cloud keys and passwords are blocked, with a clear user message
  • Rules can be scoped to groups, people, models or tools
  • Every redaction and block is recorded in a searchable audit trail
  • Access to view original prompts is restricted and itself audited
  • Rules were tuned in alert-only mode before enforcement

Where Ayati AI Governance fits

Ayati AI Governance redacts Aadhaar, PAN, card numbers and secrets before a prompt leaves your network, using a built-in Indian PII pack. Rules can block, redact or alert by keyword, category, model or tool, and can be scoped to groups or people. Because it is a gateway for Claude Code, Codex, Cursor and chat apps alike, the same rules apply everywhere, and every request is searchable — with viewing of prompt content itself audited.

For the bigger picture, read what AI governance means for enterprises and how to bring shadow AI under control. To see redaction working on your own prompts, book a demo.

Frequently asked questions

What is PII redaction for LLM prompts?

It is the automatic detection and removal of personal and sensitive data — such as Aadhaar, PAN, card numbers and secrets — from a prompt before it is sent to an AI model, so the model provider never receives the original values.

Should I redact or block sensitive data in prompts?

Redact when the task still makes sense without the value, such as summarising a customer letter with the PAN replaced by a placeholder. Block when the content should never leave at all, such as private keys or passwords. Use alert-only while you tune rules.

How do you detect an Aadhaar number reliably?

Look for 12-digit numbers, with or without spaces, and validate the final digit, which is a Verhoeff check digit. Validation removes most false matches such as order numbers or phone numbers that happen to be 12 digits long.

Where should redaction happen?

At a gateway inside your network that every AI request passes through. Redaction in a single client or browser extension misses traffic from coding assistants, scripts and other applications.

See Ayati AI Governance on your own estate.

A 30-minute walkthrough on your own use case — endpoint, data, code, passwords, AI or network.