Anonymizer icon indicating copy to clipboard operation
Anonymizer copied to clipboard

Rewrite: a confirmed medium leak of a protected value is never repaired or flagged under any preset

Open binaryaaron opened this issue 1 month ago • 3 comments

Summary

In Rewrite mode, a protected entity's value can survive verbatim in the rewritten text, the privacy QA can confirm it ("yes"), and the record is still neither repaired nor flagged for review under any RiskTolerance preset, because one medium-severity leak scores below every threshold.

Evidence

From ten recorded rewrite runs at the default low preset:

  • 5 rows kept a value the sensitivity disposition had marked for protection (generalize or remove) verbatim in the rewritten text.
  • The privacy QA asked about each one and answered "yes" in 5 of 5.
  • 4 of the 5 were medium. Each scored leakage_mass 0.60. None was repaired or flagged.
  • The fifth was high, scored 1.0, and was repaired and flagged through any_high_leaked.

Why

  • One medium "yes" contributes at most 0.6 to leakage_mass (src/anonymizer/config/rewrite.py:30-34, SENSITIVITY_WEIGHTS).
  • Repair requires leakage_mass strictly greater than the preset's threshold: 0.6 / 1.0 / 1.5 / 2.0 for minimal / low / moderate / high.
  • The review flag requires more than 1.0 / 2.0 / 2.5 / 3.0.
  • A single confirmed medium leak therefore never crosses either bar on any preset. Only high items have a severity-based trigger (repair_any_high_leak).

Question

Should a "yes" from the privacy QA on an item the disposition marked for protection trigger repair (and, if it survives repair, the review flag) regardless of leakage_mass?

If yes, the natural place is the privacy QA answer itself rather than a separate text match against the rewrite, so the signal and the repair prompt stay aligned. It can be implemented on top of #333, which owns the disposition policy.

Context

  • #353 proposed a separate verbatim-retention check for this; it was closed in favour of #333, and this issue carries the remaining policy question.
  • Docs describe the review flag as threshold-based (docs/concepts/rewrite.md, "Working with flagged records").

binaryaaron avatar Nov 03 '26 00:11 binaryaaron

Proposal: move Rewrite's repair and review rules into a small findings module, so this issue and #333 add named findings instead of new boolean clauses. Policy decisions stay with @asteier2026 and become preset settings.

Today the rules are hard-coded in three places on main:

  • engine/rewrite/evaluate.py:424-435, determine_repair_needs: repair if any high-sensitivity item leaked, or if the leakage mass is above the preset threshold. The disposition's protection method is not an input, so a confirmed leak of an item marked generalize or remove counts the same as any other medium answer.
  • engine/rewrite/evaluate.py:401-410 and the weighted sum in config/rewrite.py:30-34: after summing, the leaked item cannot be recovered.
  • engine/rewrite/rewrite_workflow.py:459-464 and combined_rewrite_workflow.py:370-378: the needs_human_review formula, duplicated across the two paths. #328 added a term and #356 adds another.

Nothing lists these rules, and nothing fails when a new one lacks a test or a preset entry.

The module: an enum of named findings (high_leak, protected_leak, leakage_above_threshold, utility_below_flag, replacement_unavailable, missed_entities), each a pure function of the privacy answers, the disposition and the metrics. Repair and review read which findings are present, and each RiskTolerance preset lists which findings repair and which flag. Weights and thresholds do not move. The first PR reproduces current behaviour exactly, checked against the recorded runs, in about 60-100 lines. Tests: one table per finding with NaN and missing-evidence rows, and one test that every preset names only known findings.

For this issue, protected_leak is the first new finding. It reads the protection method that #333 is reshaping, so the two changes should share one type. Whether a confirmed medium leak of a protected item should trigger repair, and whether the QA confirmation is reliable enough to act on, are decisions for @asteier2026; with this shape they are preset edits.

Plan: the module goes up as its own PR to main, independent of #333. The only shared code is the needs_human_review formula in rewrite_workflow.py, which #333 already touches via #328, so whichever lands second rebases one hunk. If the findings PR lands first, the offer stands to adapt #333's branch to the shared type.

binaryaaron avatar Nov 03 '26 07:11 binaryaaron

@asteier2026, a question for you now that #368 is open. It changes the shape of this issue a little.

#368 names the conditions Rewrite acts on as findings and lets each RiskTolerance preset list, as data, which findings send a row to repair and which flag it for review. Behaviour is unchanged. One thing came out of the review: privacy questions are generated only for entities the disposition marks for protection (qa_generation.py, one question per protected_entities member), so "a QA yes on a protected item" is the same as "any privacy question answered yes". The finding this issue needs is therefore one boolean computed beside any_high_leaked, plus preset entries.

The question is whether presets should act on it, and how. The proposal, written the way it would appear in the preset table:

preset repair on flag on
minimal high_leak, leakage_above_repair, confirmed_leak all findings, incl. confirmed_leak
low high_leak, leakage_above_repair, confirmed_leak same
moderate high_leak, leakage_above_repair, confirmed_leak same
high leakage_above_repair same

high keeps its current exemption from severity-based repair and only flags, so a human decides. Thresholds and weights do not move.

Two things to settle:

  1. Is a privacy-QA "yes" reliable enough to act on by itself? In the recorded runs behind this issue, all five "yes" answers were real verbatim retentions. The cost of a false "yes" is one extra repair pass on a clean row, bounded by max_repair_iterations; repair rewrites, it does not delete.
  2. Does the table above match the policy you want, or should high repair on it too, or should some preset only flag?

If this reads right to you, the change is a short PR on top of #368 that adds the finding and these preset rows, and this issue closes with it. If you'd rather define the condition differently (for example only when the disposition method is remove), say so and the finding takes that definition instead; the preset table does not change shape.

binaryaaron avatar Nov 03 '26 18:11 binaryaaron

Status, now that #368 has merged:

  • The rules this issue touches are data now: each preset lists which findings repair and which flag (config/rewrite.py), and the findings themselves are computed in one place (engine/rewrite/findings.py). The line numbers in the description above refer to the pre-#368 layout.
  • The finding is built and tested as confirmed_leak (the same thing my first comment called protected_leak): present when any privacy question is answered "yes". Missing or unparseable answers give no finding and do not raise. Preset rows are exactly the table above: every preset flags on it; minimal, low and moderate also repair on it; high flags only. The change is small (under 30 source lines plus tests) and every behaviour difference against today is a row that was not acted on and now is.
  • The two questions above still decide the preset rows, and each is a one-line edit.

@asteier2026 if you'd rather define the condition differently or change which presets repair, say so here or on the PR. If I don't hear back, I'll open the PR with the table as proposed and we can adjust the rows in review.

binaryaaron avatar Nov 05 '26 19:11 binaryaaron