Skip to main content
Version: Dev

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.

typeMatches
emailEmail addresses
china_mobileMainland China mobile numbers
china_id_cardMainland China resident ID numbers that pass the ISO 7064 checksum
bank_cardBank card numbers that pass the Luhn checksum
us_ssnUS Social Security Numbers
ip_addressIPv4 addresses
api_keyAPI keys and tokens with OpenAI, AWS, GitHub, Slack, or Google signatures
jwtJSON Web Tokens
private_keyPEM 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 22 through 27, or with 3, 4, 5, 6, 8, or 9. 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:

ActionBehavior
maskReplace the matched span with a redaction token and continue. Input masking changes what the upstream receives; output masking changes what the caller receives.
blockReject 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​

ConfigurationBehavior
replacement omittedAISIX generates [<NAME>_REDACTED] from the pattern name. A pattern named employee_id uses [EMPLOYEE_ID_REDACTED].
replacement set to a nonempty stringAISIX 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 ExpressionSelected Span
No capture groupThe complete match.
One or more capture groupsCapture 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: '***'
InputOutput
version: 12.1version: ***

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:

regexreplacementOutputExplanation
ACCT-([0-9]{4})-([0-9]{4})ACCT-$1-****ACCT-ACCT-$1-****-5678AISIX 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-****-5678AISIX replaces group 1 and preserves the prefix, separator, and group 2.