Describe how replacement values for a planned column are generated, for reports.
The description follows the routing in ReplacementExecutor, which allocates patterned and
integer identifiers itself, and in the Faker and Nemotron-Personas generators, so it must change with
them. It names the method a column is planned to use, not per-value fallbacks.
Example
An email column that depends on a full_name column and has no pattern is described as
"Built from full_name, keeping the original domain".
Source code in src/nemo_safe_synthesizer/pii_replacer/replacement/descriptions.py
| def describe_replacement(column: PiiColumnPlan, settings: ReplacePiiConfig) -> str:
"""Describe how replacement values for a planned column are generated, for reports.
The description follows the routing in ``ReplacementExecutor``, which allocates patterned and
integer identifiers itself, and in the Faker and Nemotron-Personas generators, so it must change with
them. It names the method a column is planned to use, not per-value fallbacks.
Example:
An ``email`` column that depends on a ``full_name`` column and has no pattern is described as
``"Built from full_name, keeping the original domain"``.
"""
entity_type = column.entity_type
pattern = column.pattern
uses_personas = settings.sampler.backend is PiiSamplerBackend.NEMOTRON_PERSONAS
if entity_type is EntityType.FREE_TEXT:
return "Each PII value found in the text is replaced with a generated value of its type"
if pattern is not None and entity_type in MASK_ALLOCATED_ENTITY_TYPES:
return "New values that fit the pattern"
if entity_type is EntityType.PHONE_NUMBER:
if pattern is None:
return "Random digits in the original's layout, keeping its country code and area code"
return "Random digits that fit the pattern, keeping the original's country code and area code"
if entity_type in NAME_ENTITY_TYPES:
source = "Sampled from Nemotron Personas" if uses_personas else "Generated by Faker"
return source if pattern is None else f"{source}, written in the pattern"
if entity_type is EntityType.STREET_ADDRESS:
personas = uses_personas and entity_type in PERSONA_ENTITY_TYPES and settings.locale == _PERSONA_STREET_LOCALE
source = "Nemotron Personas" if personas else "Faker"
return f"Street sampled from {source}; any city, state, or zip after the street is kept"
if entity_type is EntityType.EMAIL:
names = [d.column_name for d in column.depends_on if d.entity_type in NAME_ENTITY_TYPES]
if pattern is None and not names:
return "Generated by Faker"
built = f"Built from {', '.join(names)}" if names else "Built from generated names"
# Without a plan pattern, an email that depends on names uses ``{first}.{last}##@{domain}``.
if pattern is None or "{domain}" in pattern:
built += ", keeping the original domain"
return built if pattern is None else f"{built}, written in the pattern"
if entity_type is EntityType.DATE_OF_BIRTH:
return "The original date moved by a random number of days, at most 180"
if entity_type in NUMBER_ALLOCATED_ENTITY_TYPES:
return (
"Integer IDs get new integers, UUIDs get new UUIDs, and other IDs get random letters and digits "
"in the original's layout"
)
if entity_type is EntityType.NATIONAL_ID:
return (
"Values that are the locale's own national ID get new ones; others get random letters and digits "
"in the original's layout"
)
if entity_type is EntityType.CREDIT_DEBIT_CARD and pattern is not None:
return "Random digits that fit the pattern and pass the card checksum"
return "Generated by Faker"
|