PII Detector Reference
Use this reference when choosing a PII detector or predicting how AISIX will handle a match. It catalogs the built-in detector formats and checksums, masking limitations, match actions, and custom-pattern replacement behavior. For step-by-step configuration and verification, see Configure PII Guardrails.
Built-in Detectors
Use this table to choose the detector that matches the data format you need to protect. Configure its type in the PII guardrail's detector list.
type | Matches |
|---|---|
email | Email addresses |
china_mobile | Mainland China mobile numbers |
china_id_card | Mainland China resident ID numbers that pass the ISO 7064 checksum |
bank_card | Bank card numbers that pass the Luhn checksum |
us_ssn | US Social Security Numbers |
ip_address | IPv4 addresses |
api_key | API keys and tokens with OpenAI, AWS, GitHub, Slack, or Google signatures |
jwt | JSON Web Tokens |
private_key | PEM private key blocks |
Built-in detectors use ASCII word boundaries. A value next to Chinese text, such as 卡號4111111111111111, is therefore detected. The us_ssn and ip_address detectors do not match values written with full-width digits.
Bank Card Formats
The bank_card detector supports two forms. Every match must pass the Luhn check:
- Unbroken digits: 13 to 19 digits with any prefix.
- Grouped digits: groups of 4-4-4-4, 4-4-4-4-3, 4-6-5, or 4-6-4 digits separated by spaces or hyphens. The number must start with
22through27, or with3,4,5,6,8, or9. A 19-digit grouped number also matches when its first 16 digits pass the Luhn check.
The detector has these limitations:
- An unrelated digit run that passes the Luhn check, such as an order number, is still detected.
- A grouped card number is missed when a four-digit number with a card prefix comes directly before it, separated by one space or hyphen. For example, in
ref 4026 4111 1111 1111 1111, the match starts at the first number and consumes the card.
Match Actions
Each detector and custom pattern resolves to one action:
| Action | Behavior |
|---|---|
mask | Replace the matched span with a redaction token and continue. Input masking changes what the upstream receives; output masking changes what the caller receives. |
block | Reject the request or response with 422 Unprocessable Entity. |
default_action sets the action for the guardrail. Set action on an individual detector or custom pattern to override it.
Surfaces That Cannot Apply a Mask
Some surfaces relay content without a rewrite path. A mask match on a passthrough route, /a2a, Batch or Fine-tuning job, /v1/realtime, or /v1/videos prompt passes unchanged and is recorded as mask_unsupported. Monitor mode records would_mask_unsupported.
Inside structured tool arguments and results, a mask match on an object key or number blocks because AISIX cannot rewrite either value safely. See Surfaces That Cannot Apply a Mask and How Keyword and PII Guardrails Read Structured Content.
Custom Patterns
Custom patterns extend the built-in catalog with formats specific to your organization. Each pattern requires a name and Rust-compatible regular expression, and can override the guardrail's action or replacement.
AISIX uses the pattern name in the default redaction token and match counts. An invalid regular expression prevents the guardrail from entering the active chain.
Custom Pattern Replacements
replacement controls the text AISIX writes for a custom pattern whose effective action is mask. Do not configure it on a pattern whose effective action is block.
Replacement Value
| Configuration | Behavior |
|---|---|
replacement omitted | AISIX generates [<NAME>_REDACTED] from the pattern name. A pattern named employee_id uses [EMPLOYEE_ID_REDACTED]. |
replacement set to a nonempty string | AISIX inserts the configured string literally. It does not expand $1 or other group references. |
replacement: '' | AISIX removes the selected span. |
Replacement Span
The regular expression determines which part of a match AISIX replaces:
| Regular Expression | Selected Span |
|---|---|
| No capture group | The complete match. |
| One or more capture groups | Capture group 1 only. AISIX preserves the rest of the complete match, including text matched by later groups. |
For example, this configuration selects the version value while retaining its label:
custom_patterns:
- name: eda_version
regex: 'version: (\S+)'
replacement: '***'
| Input | Output |
|---|---|
version: 12.1 | version: *** |
Structured Content Boundaries
The regular expression must match within one content segment. In structured tool arguments, the key and value in {"version": "12.1"} are separate segments, so version: (\S+) does not match across them. Use a pattern that matches the value's format when the value is stored separately.
Literal Replacement Example
The following configurations demonstrate how literal replacement and capture-group selection interact for the input ACCT-1234-5678:
regex | replacement | Output | Explanation |
|---|---|---|---|
ACCT-([0-9]{4})-([0-9]{4}) | ACCT-$1-**** | ACCT-ACCT-$1-****-5678 | AISIX inserts $1 literally and preserves text outside group 1. Repeating ACCT- in the replacement duplicates the prefix. |
ACCT-([0-9]{4})-([0-9]{4}) | **** | ACCT-****-5678 | AISIX replaces group 1 and preserves the prefix, separator, and group 2. |