RedaktAIDocs

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>.

OriginalAnonymized
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.

OriginalAnonymized
John SmithRobert Johnson
Acme CorpHenderson LLC
San FranciscoPortland

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 TypeStrategy Used
PERSONSynthetic
ORGANIZATIONSynthetic
LOCATIONSynthetic
ADDRESSSynthetic
Everything elseToken

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: token

Global 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

ScenarioRecommended
General-purposeHybrid (default)
Maximum privacy, minimal LLM coherence neededToken for all
Narrative text generationSynthetic for all
Compliance auditUse audit mode instead (no anonymization)

On this page