Talk to the Team

Tell us about your stack and the privacy problems you're trying to solve. We typically respond within one business day.

Prefer email? support@philterd.ai

Prefer to skip the form? Pick a time on our calendar →
or send a message

Please do not enter PII or PHI in this form. If you need to share an example, use a sanitized one.

← All policies

General · Philterd

Spanish Identifiers (DNI, NIE, CIF)

Redact Spanish personal and organization identifiers (DNI, NIE, CIF), validated by their control letter or character.

v1.0.0 Updated 2026-06-15 Philter Requires Phileas 4.1.0+ (redaction policy schema 1.1.0 with the mod23-letter and es-cif validators) By Philterd
SpainDNINIECIFnational IDtax ID

The policy

The full spanish-identifiers.json file. The same content you’d get by downloading. Copy any part of it, or use the buttons in the hero to grab the whole file.

{
  "config": {
    "splitting": {
      "enabled": false,
      "threshold": 4000
    }
  },
  "ignored": [],
  "identifiers": {
    "identifiers": [
      {
        "classification": "spanish-dni",
        "pattern": "\\b\\d{8}[A-Za-z]\\b",
        "caseSensitive": false,
        "validator": "mod23-letter",
        "identifierFilterStrategies": [
          {
            "strategy": "REDACT",
            "redactionFormat": "[REDACTED-SPANISH-DNI]"
          }
        ]
      },
      {
        "classification": "spanish-nie",
        "pattern": "\\b[XYZxyz]\\d{7}[A-Za-z]\\b",
        "caseSensitive": false,
        "validator": "mod23-letter",
        "identifierFilterStrategies": [
          {
            "strategy": "REDACT",
            "redactionFormat": "[REDACTED-SPANISH-NIE]"
          }
        ]
      },
      {
        "classification": "spanish-cif",
        "pattern": "\\b[A-HJ-NP-SUVWa-hj-np-suvw]\\d{7}[0-9A-Ja-j]\\b",
        "caseSensitive": false,
        "validator": "es-cif",
        "identifierFilterStrategies": [
          {
            "strategy": "REDACT",
            "redactionFormat": "[REDACTED-SPANISH-CIF]"
          }
        ]
      }
    ]
  }
}

Example

Input

DNI 12345678Z, NIE X1234567L, CIF A58818501.

Output

DNI [REDACTED-SPANISH-DNI], NIE [REDACTED-SPANISH-NIE], CIF [REDACTED-SPANISH-CIF].

Entities this policy acts on

SPANISH_DNISPANISH_NIESPANISH_CIF

What this policy does

Detects and redacts three Spanish identifiers using Phileas’s generic identifier filter with a control-character validator, so each match is kept only if its control is correct:

  • DNI (Documento Nacional de Identidad): 8 digits and a control letter, validated by the mod23-letter validator.
  • NIE (Numero de Identidad de Extranjero): a leading X, Y, or Z (mapped to 0, 1, 2), 7 digits, and a control letter, validated by the mod23-letter validator.
  • CIF (the organization tax identifier): a leading organization-type letter, 7 digits, and a control digit or letter, validated by the es-cif validator.

Each is replaced with a distinct token.

Why the validators matter

The shapes alone (eight digits plus a letter, and so on) would over-match. The validator keeps a match only if the control character is correct, so 12345678A (a DNI shape with the wrong control letter) is left in place while 12345678Z is redacted. Detection remains probabilistic; validate against your own documents.

Test vectors

  • DNI, valid: 12345678Z. Invalid (wrong control letter): 12345678A.
  • NIE, valid: X1234567L. Invalid (wrong control letter): X1234567A.
  • CIF, valid: A58818501. Invalid (wrong control character): A58818502.

Contextual cues

In free text, anchor on a nearby cue (“DNI”, “NIE”, “CIF”) and capture only the identifier with groupNumber:

{
  "classification": "spanish-dni",
  "pattern": "DNI[\\s:#-]*(\\d{8}[A-Za-z])",
  "caseSensitive": false,
  "groupNumber": 1,
  "validator": "mod23-letter",
  "identifierFilterStrategies": [
    { "strategy": "REDACT", "redactionFormat": "[REDACTED-SPANISH-DNI]" }
  ]
}

This trades recall for precision.

Prerequisites

Use Phileas 4.1.0 or later, which provides redaction policy schema 1.1.0 and the mod23-letter and es-cif validators. The example input and output were verified against Phileas 4.1.0.

References

Use this policy

Download and load into your running Philter instance:

# Download the policy
curl -O https://raw.githubusercontent.com/philterd/pii-redaction-policies/main/policies/philterd/general/spanish-identifiers.json

# Upload to your Philter instance
curl -X POST http://localhost:8080/api/policies \
     -H "Content-Type: application/json" \
     --data @spanish-identifiers.json

# Redact text using the policy
curl http://localhost:8080/api/filter?p=spanish-identifiers \
     --data "your text here" \
     -H "Content-Type: text/plain"

No Philter instance yet? Deploy one in 5 minutes → · Want to tune this policy against your data? Talk to the team.