FastPII Docs
Guides

Anonymization

Replace detected PII with a uniform placeholder using PrivacyGuard.anonymize.

PrivacyGuard.anonymize() replaces every detected PII span with a single placeholder string.

Default replacement

The default replacement is [REDACTED].

from fastpii import PrivacyGuard

guard = PrivacyGuard(regions=["cz"])
text = "Kontakt: jan.novak@email.cz, RČ 8001011238, IČO 25596641"

safe_text = guard.anonymize(text)
print(safe_text)

Output:

Kontakt: [REDACTED], RČ [REDACTED], IČO [REDACTED]

Custom replacement

Use the replacement parameter to choose your own placeholder.

from fastpii import PrivacyGuard

guard = PrivacyGuard(regions=["cz"])
text = "Email: jan.novak@email.cz"

safe_text = guard.anonymize(text, replacement="[PRIVATE]")
print(safe_text)

Output:

Email: [PRIVATE]

When to use anonymize

Use anonymize() when you want a single neutral marker and do not need to preserve the PII type.

from fastpii import PrivacyGuard

guard = PrivacyGuard(regions=["cz"])
prompt = "Customer Jan Novák can be reached at jan.novak@email.cz"

safe_prompt = guard.anonymize(prompt)

This is a good fit for sending cleaned text to LLMs, logs, or downstream services.

On this page