Anonymization Strategies
Token, synthetic, and hybrid strategies for replacing PII
When Rdakt AI detects an entity, it replaces the original value with an anonymized substitute. The replacement strategy determines what the LLM sees instead of the real data.
Token Strategy
Replaces values with structured tokens like <TYPE_N>.
| Original | Anonymized |
|---|---|
john@example.com | <EMAIL_1> |
123-45-6789 | <SSN_1> |
4111 1111 1111 1111 | <CREDIT_CARD_1> |
Best for: Structured data (SSNs, credit cards, emails) where the LLM doesn't need realistic values to produce useful output.
Trade-off: The LLM sees that the data exists and knows its type, but the output may reference <EMAIL_1> literally if the prompt asks the model to use the value.
Synthetic Strategy
Replaces values with realistic fake data generated by Faker.
| Original | Anonymized |
|---|---|
John Smith | Robert Johnson |
Acme Corp | Henderson LLC |
San Francisco | Portland |
Best for: Names, organizations, and locations where the LLM needs realistic-sounding values to produce coherent text.
Trade-off: The LLM's output will contain the fake values, which are deanonymized back to the originals in the response. Slight risk of the LLM generating new fake names that aren't in the session map (these pass through un-deanonymized).
Hybrid Strategy (Default)
Combines both: synthetic for names and organizations, tokens for structured data.
| Entity Type | Strategy Used |
|---|---|
PERSON | Synthetic |
ORGANIZATION | Synthetic |
LOCATION | Synthetic |
ADDRESS | Synthetic |
| Everything else | Token |
This is the default and recommended strategy for most use cases.
Configuring Strategies
Per-entity in YAML
entities:
EMAIL:
strategy: token
PERSON:
strategy: synthetic
SSN:
strategy: tokenGlobal default in code
from rdakt_ai import Anonymizer, AnonymizationStrategy
anonymizer = Anonymizer(
default_strategy=AnonymizationStrategy.TOKEN,
type_strategies={
"PERSON": AnonymizationStrategy.SYNTHETIC,
"ORGANIZATION": AnonymizationStrategy.SYNTHETIC,
},
)Via middleware config
from rdakt_ai import RdaktMiddleware, RdaktConfig, EntityConfig
config = RdaktConfig(
entities={
"PERSON": EntityConfig(strategy="synthetic"),
"EMAIL": EntityConfig(strategy="token"),
},
)
middleware = RdaktMiddleware(config=config)Choosing a Strategy
| Scenario | Recommended |
|---|---|
| General-purpose | Hybrid (default) |
| Maximum privacy, minimal LLM coherence needed | Token for all |
| Narrative text generation | Synthetic for all |
| Compliance audit | Use audit mode instead (no anonymization) |