FastPII Docs
Guides

Anonymization

Replace detected PII with uniform placeholders.

Anonymization

Use anonymize() to replace every detected PII value with a fixed placeholder string.

Basic anonymization

from fastpii import FastPII, DEFAULT_PRIORITY
from fastpii.countries.cz import CzechPack

engine = FastPII(priority=DEFAULT_PRIORITY)
engine.register(CzechPack())

text = "Email: jan.novak@example.cz, RČ: 8001011238"
result = engine.anonymize(text)
print(result)

Output:

Email: [REDACTED], RČ: [REDACTED]

Custom replacement

result = engine.anonymize(text, replacement="<PII>")
print(result)

Output:

Email: <PII>, RČ: <PII>

Using TransformationEngine directly

For more control, use the TransformationEngine with AnonymizeStrategy:

from fastpii.core.transform import TransformationEngine, AnonymizeStrategy

result = engine.detect(text)
anonymized = TransformationEngine.apply(result, AnonymizeStrategy(replacement="[PRIVATE]"))
print(anonymized)

Output:

Email: [PRIVATE], RČ: [PRIVATE]

When to use anonymization

Anonymization is best when:

  • You need a uniform placeholder regardless of PII type
  • Preparing text for LLM prompts where type labels are unnecessary
  • Writing logs where all PII should be treated equally

On this page