anonymizer_config
anonymizer_config
¶
Classes:
| Name | Description |
|---|---|
AnonymizerInput |
Input source definition for the anonymizer pipeline. |
TextRecord |
One in-memory text record to anonymize. |
TextRecordsInput |
Ordered in-memory text records and their dataset context. |
Detect |
Configuration for the entity detection stage. |
Rewrite |
Configuration for rewrite-mode execution. |
AnonymizerConfig |
Primary user-facing config for anonymization behavior. |
EvaluateConfig |
Optional knobs for :meth: |
Functions:
| Name | Description |
|---|---|
resolve_effective_detection_labels |
Resolve the labels used by detection after custom rules and exclusions. |
is_remote_input_source |
Return True when the input source is an HTTP(S) URL. |
has_unsupported_url_scheme |
Return True when the input looks like a URL but uses an unsupported scheme. |
infer_input_source_suffix |
Infer the lowercase file suffix from a local path or remote URL path. |
AnonymizerInput
pydantic-model
¶
Bases: BaseModel
Input source definition for the anonymizer pipeline.
Format is inferred from the file extension of a local path or HTTP(S) URL.
Fields:
-
source(str) -
text_column(str) -
id_column(str | None) -
data_summary(str | None)
Validators:
-
validate_source_path→source
source
pydantic-field
¶
Local path or HTTP(S) URL for a .csv or .parquet input file.
text_column = 'text'
pydantic-field
¶
Column containing the text to anonymize.
id_column = None
pydantic-field
¶
Optional column to use as record identifier.
data_summary = None
pydantic-field
¶
Short description of the data. Improves LLM detection accuracy.
TextRecord
pydantic-model
¶
TextRecordsInput
pydantic-model
¶
Bases: BaseModel
Ordered in-memory text records and their dataset context.
Fields:
-
records(list[TextRecord]) -
data_summary(str | None)
Validators:
-
validate_record_ids
Detect
pydantic-model
¶
Bases: BaseModel
Configuration for the entity detection stage.
Config:
hide_input_in_errors:True
Fields:
-
entity_labels(list[str] | None) -
entity_label_examples(dict[str, list[str]]) -
excluded_entity_labels(list[str] | None) -
gliner_threshold(float) -
validation_max_entities_per_call(int) -
validation_excerpt_window_chars(int) -
builtin_regexes(bool) -
regex_rules(list[BuiltinRegex | RegexRule]) -
regex_limits(RegexLimits)
Validators:
-
validate_entity_labels→entity_labels -
validate_excluded_entity_labels→excluded_entity_labels -
validate_entity_label_examples→entity_label_examples -
validate_entity_label_overlap -
validate_regex_rule_scope
entity_labels = None
pydantic-field
¶
Labels to detect. None uses the built-in default detection label set. To inspect the default set, use from anonymizer import DEFAULT_ENTITY_LABELS.
entity_label_examples
pydantic-field
¶
Configured positive detection examples organized by entity label. For default labels, these values are appended to the built-in examples. Non-default labels must also be declared in an explicit entity_labels set; examples never activate labels implicitly.
excluded_entity_labels = None
pydantic-field
¶
Entity labels to never detect, even if present in entity_labels or the default set. Excluded labels are removed before GLiNER and LLM prompts run, and are also filtered from the final entity output as a safety net. If this entirely overlaps the effective allowlist (entity_labels if set, otherwise the default label set plus labels from enabled custom regex rules), leaving an empty effective detection set, Detect raises a ValueError at config time.
gliner_threshold = 0.3
pydantic-field
¶
GLiNER detection confidence threshold (0.0-1.0).
validation_max_entities_per_call = 100
pydantic-field
¶
Target maximum number of candidate entities per validator LLM call. Overlapping alternatives stay in one chunk; a group larger than this target is sent alone with a warning. Chunks are dispatched round-robin across the validator pool.
validation_excerpt_window_chars = 500
pydantic-field
¶
Number of characters to include before and after a chunk's entity span when building the text excerpt sent to the validator. Bounds the prompt context the validator sees per chunk; it is NOT the LLM's context window limit.
builtin_regexes = True
pydantic-field
¶
Run built-in regex recognizers for labels in the effective detection scope.
regex_rules
pydantic-field
¶
Per-label built-in settings and user-defined regex candidate rules.
regex_limits
pydantic-field
¶
Per-record, per-rule validated-match cap and character-scaled timeout for all regex rules.
Rewrite
pydantic-model
¶
Bases: BaseModel
Configuration for rewrite-mode execution.
Fields:
-
privacy_goal(PrivacyGoal | None) -
instructions(str | None) -
risk_tolerance(RiskTolerance) -
max_repair_iterations(int) -
use_combined_graph(bool) -
strict_entity_protection(bool)
Validators:
-
populate_default_privacy_goal
privacy_goal = None
pydantic-field
¶
Structured privacy goal. Auto-populated with defaults if not provided.
instructions = None
pydantic-field
¶
Additional instructions for the rewrite LLM.
risk_tolerance = RiskTolerance.low
pydantic-field
¶
Preset controlling repair thresholds and review flagging.
max_repair_iterations = 3
pydantic-field
¶
Maximum repair rounds. Set to 0 to disable repair.
use_combined_graph = False
pydantic-field
¶
Run rewrite and conditional repair iterations in one Data Designer graph.
strict_entity_protection = False
pydantic-field
¶
If True, requires every entity to receive a protective disposition during sensitivity analysis.
evaluation
property
¶
Construct EvaluationCriteria from this Rewrite config for the engine.
Rewrite and EvaluationCriteria both carry max_repair_iterations.
This property keeps them in sync: it passes through self.risk_tolerance
and self.max_repair_iterations. Leakage thresholds and repair
parameters are derived from risk_tolerance via _RiskToleranceBundle
(see rewrite.py).
Production code that starts from a user-facing Rewrite should pass
rewrite.evaluation into the engine — never duplicate the mapping
manually. Tests and engine-internal callers may construct
EvaluationCriteria directly when they aren't routing through a
user-facing Rewrite.
AnonymizerConfig
pydantic-model
¶
Bases: BaseModel
Primary user-facing config for anonymization behavior.
Config:
hide_input_in_errors:True
Fields:
Validators:
-
validate_exactly_one_mode
detect
pydantic-field
¶
Entity detection configuration.
replace = None
pydantic-field
¶
Replacement method (Substitute(), Redact(), Annotate(), or Hash()).
rewrite = None
pydantic-field
¶
Optional rewrite-mode parameters.
emit_telemetry = True
pydantic-field
¶
Whether to emit anonymous Anonymizer telemetry events. See the Telemetry section in the README for what is collected and how to opt out at the environment or CLI level.
EvaluateConfig
pydantic-model
¶
Bases: BaseModel
Optional knobs for :meth:Anonymizer.evaluate.
Reserved for genuinely evaluation-specific configuration — metric selection,
per-judge model/prompt overrides, scoring thresholds, etc. The anonymization
mode is not here: it travels on the AnonymizerResult /
PreviewResult produced by run() / preview() and is read directly
by evaluate(), so users don't restate it and can't mis-state it.
Today this is an empty placeholder; fields will be added as evaluation knobs are introduced.
Fields:
-
compute_detection_validity(bool)
compute_detection_validity = False
pydantic-field
¶
Run the tag-precision judge (detection_valid / detection_invalid_entities).
Disabled by default — intended for internal use during model and threshold
experiments. When True, adds
detection_valid and detection_invalid_entities columns to the
evaluate() output alongside entity_coverage.
resolve_effective_detection_labels(entity_labels, *, regex_rules=None, excluded_entity_labels=None)
¶
Resolve the labels used by detection after custom rules and exclusions.
An explicit entity_labels list is authoritative. When it is None,
detection starts with DEFAULT_ENTITY_LABELS and appends labels from
enabled custom RegexRule entries. Only enabled custom rules extend the
effective label set: disabled custom rules are inert, and BuiltinRegex
settings configure existing built-ins without adding labels. Exclusions
are applied last using normalized label comparisons.
This helper intentionally returns only the resolved labels. Callers must
retain the original entity_labels is None state because it separately
controls permissive versus strict augmentation.
Source code in src/anonymizer/config/anonymizer_config.py
def resolve_effective_detection_labels(
entity_labels: list[str] | None,
*,
regex_rules: list[BuiltinRegex | RegexRule] | None = None,
excluded_entity_labels: list[str] | set[str] | None = None,
) -> list[str]:
"""Resolve the labels used by detection after custom rules and exclusions.
An explicit ``entity_labels`` list is authoritative. When it is ``None``,
detection starts with ``DEFAULT_ENTITY_LABELS`` and appends labels from
enabled custom ``RegexRule`` entries. Only enabled custom rules extend the
effective label set: disabled custom rules are inert, and ``BuiltinRegex``
settings configure existing built-ins without adding labels. Exclusions
are applied last using normalized label comparisons.
This helper intentionally returns only the resolved labels. Callers must
retain the original ``entity_labels is None`` state because it separately
controls permissive versus strict augmentation.
"""
labels = list(DEFAULT_ENTITY_LABELS) if entity_labels is None else list(entity_labels)
if entity_labels is None:
known = {normalize_entity_label(label) for label in labels}
for rule in regex_rules or []:
if not isinstance(rule, RegexRule) or not rule.enabled:
continue
normalized = normalize_entity_label(rule.label)
if normalized not in known:
labels.append(rule.label)
known.add(normalized)
excluded = {normalize_entity_label(label) for label in excluded_entity_labels or []}
return [label for label in labels if normalize_entity_label(label) not in excluded]
is_remote_input_source(value)
¶
Return True when the input source is an HTTP(S) URL.
Source code in src/anonymizer/config/anonymizer_config.py
def is_remote_input_source(value: str) -> bool:
"""Return True when the input source is an HTTP(S) URL."""
parsed = urlparse(value)
return parsed.scheme in {"http", "https"}
has_unsupported_url_scheme(value)
¶
Return True when the input looks like a URL but uses an unsupported scheme.
Source code in src/anonymizer/config/anonymizer_config.py
def has_unsupported_url_scheme(value: str) -> bool:
"""Return True when the input looks like a URL but uses an unsupported scheme."""
parsed = urlparse(value)
return "://" in value and bool(parsed.scheme) and parsed.scheme not in {"http", "https"}
infer_input_source_suffix(value)
¶
Infer the lowercase file suffix from a local path or remote URL path.
Source code in src/anonymizer/config/anonymizer_config.py
def infer_input_source_suffix(value: str) -> str:
"""Infer the lowercase file suffix from a local path or remote URL path."""
if is_remote_input_source(value):
return Path(urlparse(value).path).suffix.lower()
return Path(value).suffix.lower()