fix: harden rewrite replacement and leak metrics - #246
Conversation
Signed-off-by: Aaron Gonzales <aagonzales@nvidia.com>
Signed-off-by: Aaron Gonzales <aagonzales@nvidia.com>
Signed-off-by: Aaron Gonzales <aagonzales@nvidia.com>
Greptile SummaryThe PR hardens rewrite processing by applying deterministic replacements to validated spans before generation and retaining that sanitized baseline through repair. It also introduces schema-v2 replacement and leak metrics and updates benchmark and W&B tooling to keep schema versions isolated.
Confidence Score: 5/5The PR appears safe to merge because no blocking failure remains. No blocking failure remains. Important Files Changed
|
|
General note: this PR correctly supersedes #208 by using validated entity spans instead of global regex replacement, preventing embedded-substring corruption such as Ann inside Anna. It verifies that every required span was replaced and fails closed when a map is absent, partial, ambiguous, or cannot be applied. It also preserves the sanitized baseline through repair and reports only safe labels and counts in diagnostics. cc @asteier2026 |
Signed-off-by: Aaron Gonzales <aagonzales@nvidia.com>
Summary
iterrows()or per-row Series constructionWhy
The schema-v1 leak metric used raw substring matching for longer values and counted every same-valued source entity when one match appeared in output. This produced false positives such as
lawyerinlawyers. Adjacent replacement metrics also described map membership rather than actual span execution, and detection sidecars exported post-validation detections underfinal_*names.The rewrite path additionally relied on the model to apply deterministic replacement-map entries. This change uses the existing offset-based replacement boundary, fails closed when required mappings cannot be applied, and prevents the repair loop from returning to the original sensitive baseline. It supersedes the global-regex runtime approach proposed in #208.
Both local replacement and LLM-generated replacement maps now use the same DataFrame orchestration helper. The helper iterates aligned columns directly, preserves row order and custom column names, and records replacement text and application telemetry together.
Compatibility
Validation
make checkmake test(1,219 passed, one existing W&B deprecation warning)uv run pytest tests/engine/test_replace_strategies.py tests/engine/test_replace_runner.py -q(21 passed)git diff --checkiterrows()calls instrategies.py