Skip to content

fix(anonymizer): include confidence score in OperatorResult#2179

Closed
kalra-mohit wants to merge 1 commit into
data-privacy-stack:mainfrom
kalra-mohit:feature/anonymizer-operator-result-score
Closed

fix(anonymizer): include confidence score in OperatorResult#2179
kalra-mohit wants to merge 1 commit into
data-privacy-stack:mainfrom
kalra-mohit:feature/anonymizer-operator-result-score

Conversation

@kalra-mohit

Copy link
Copy Markdown

Summary

Adds an optional score field to OperatorResult, threaded through from the originating RecognizerResult during AnonymizerEngine.anonymize() and preserved through DeanonymizeEngine.deanonymize().

  • score defaults to None so existing callers are unaffected
  • The surviving entity after conflict resolution keeps its own (max) score, not a dropped entity's — this relies on existing conflict-resolution behavior in anonymizer_engine.py, unmodified here
  • Included in to_dict()/to_json() output and round-trips via from_json()

Enables audit/traceability use cases where the confidence of an anonymized entity needs to be recoverable after anonymization.

Closes #2057

Test plan

  • Unit tests for OperatorResult score default, equality, to_dict/from_json
  • Unit tests for score propagation through AnonymizerEngine (single, multiple, conflicting entities)
  • Integration tests updated for new score field in output
  • Round-trip test: encrypt → decrypt preserves score

…vacy-stack#2057)

AnonymizerEngine currently drops the RecognizerResult.score during
anonymization, making it impossible to recover per-entity confidence
for audit/traceability without re-running the analyzer.

Add an optional `score` field to OperatorResult, threaded through
EngineBase._operate() from the originating entity (RecognizerResult
during anonymize, or an already-scored OperatorResult during
deanonymize). Defaults to None so existing callers, JSON shape
consumers, and the deanonymize path are unaffected unless they opt in.

- score is preserved through conflict resolution: the surviving
  entity keeps its own score, not a dropped entity's
- score is included in to_dict()/to_json() and round-trips via
  OperatorResult.from_json()
- unit + integration tests cover construction, equality, JSON
  (de)serialization, score propagation through anonymize, conflict
  resolution, and the anonymize -> deanonymize round trip

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@kalra-mohit

Copy link
Copy Markdown
Author

Closing — I found that #2059 already implements this same change (optional `score` field threaded through `OperatorResult`) and was already approved on 2026-07-13, pending test fixes. Didn't want to duplicate review effort. Thanks @kshvg for getting there first — nice implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Include confidence score in AnonymizerEngine output (OperatorResult) for audit/traceability

2 participants