[Multi-Agent Privacy] Add privacy agents: Analyzer, Detector, Sanitizer#337
Closed
JCHAVEROT wants to merge 0 commit into
Closed
[Multi-Agent Privacy] Add privacy agents: Analyzer, Detector, Sanitizer#337JCHAVEROT wants to merge 0 commit into
JCHAVEROT wants to merge 0 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces the first end-to-end stage of the privacy “sanitized context” pipeline in mmore.privacy, adding domain-aware policy construction, per-chunk PII detection with risk scoring, and multiple sanitization strategies wired as LangGraph agent nodes/tools.
Changes:
- Added domain profiles and a request-scoped
PrivacyPolicy/RiskAssessmentmodel to drive privacy decisions per request. - Implemented analyzer → detector → sanitizer agent nodes over a shared
PrivacyState, with detector tool-dispatch and sanitizer strategy-dispatch. - Added sanitization strategy toolkit (token masking, entity replacement via Faker, Presidio anonymizer, synthetic rewrite) and updated detection config/constants + tests.
Reviewed changes
Copilot reviewed 33 out of 34 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_privacy.py | Updates BaseAgent LLM patching and adds tests for LLM-less subclasses / node naming behavior. |
| tests/test_detection.py | Updates imports/config expectations and adapts tests to renamed params and constants. |
| tests/conftest.py | Switches test sample metadata to plain dicts (leveraging MultimodalSample.__post_init__). |
| src/mmore/privacy/sanitization/base.py | Defines sanitization strategy interface and shared replacement helpers. |
| src/mmore/privacy/sanitization/constants.py | Defines YAML strategy names → tool name mapping for sanitizer dispatch. |
| src/mmore/privacy/sanitization/token_masking_strategy.py | Adds [LABEL_N] token masking strategy and tool registration. |
| src/mmore/privacy/sanitization/entity_replacement_strategy.py | Adds Faker-based realistic replacement strategy and tool registration. |
| src/mmore/privacy/sanitization/presidio_strategy.py | Adds Presidio anonymizer strategy with operator normalization and caching. |
| src/mmore/privacy/sanitization/synthetic_rewrite_strategy.py | Adds DSPy-based synthetic rewrite sanitization strategy. |
| src/mmore/privacy/sanitization/init.py | Exposes sanitization strategies and tool names as package API. |
| src/mmore/privacy/risk.py | Introduces RiskAssessment produced by the detector. |
| src/mmore/privacy/policy.py | Introduces request-scoped PrivacyPolicy shared across agents. |
| src/mmore/privacy/dspy_llm.py | Adds shared cached HF pipeline getter for reuse across agents/engines. |
| src/mmore/privacy/domains/profile.py | Adds DomainProfile presets and clinical Presidio patterns + resolver. |
| src/mmore/privacy/domains/init.py | Exposes domain profile API. |
| src/mmore/privacy/detection/presidio_engine.py | Updates detection tool signature to accept PrivacyPolicy and forwards policy params. |
| src/mmore/privacy/detection/openai_filter_engine.py | Updates tool signature to accept PrivacyPolicy and forwards policy params. |
| src/mmore/privacy/detection/llm_engine.py | Updates constants usage and tool signature to accept PrivacyPolicy. |
| src/mmore/privacy/detection/gliner_engine.py | Renames entity_types → sensitive_entities and forwards policy params. |
| src/mmore/privacy/detection/defaults.py | Removes old detection defaults module (superseded by constants.py). |
| src/mmore/privacy/detection/constants.py | Adds centralized detection constants, guidance, default params, and tool-name mapping. |
| src/mmore/privacy/detection/config.py | Removes old detection config dataclass (superseded by privacy/config.py). |
| src/mmore/privacy/detection/base.py | Simplifies base types and removes embedded engine enum. |
| src/mmore/privacy/detection/init.py | Updates exports/imports to new config/enum location. |
| src/mmore/privacy/config.py | Adds top-level privacy config dataclasses + enums (detection/sanitization). |
| src/mmore/privacy/agents/state.py | Adds shared PrivacyState for analyzer/detector/sanitizer graph. |
| src/mmore/privacy/agents/analyzer.py | Adds analyzer node that infers domain and emits per-request PrivacyPolicy. |
| src/mmore/privacy/agents/detector.py | Adds detector node that runs configured engine tools, dedupes spans, and computes risk. |
| src/mmore/privacy/agents/sanitizer.py | Adds sanitizer node that dispatches to strategy tools and optionally manages DSPy LM context. |
| src/mmore/privacy/agents/config.py | Clarifies AgentConfig role as a template vs the new PrivacyConfig. |
| src/mmore/privacy/agents/base.py | Generalizes BaseAgent to support LLM-less nodes, shared model caching, and node composition. |
| src/mmore/privacy/_cache.py | Switches to RLock for cache registry locking. |
| pyproject.toml | Adds faker>=30 to the privacy extra for entity replacement strategy. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
JCHAVEROT
force-pushed
the
feat/privacy-agents-clean
branch
from
June 30, 2026 17:03
939127a to
72e379f
Compare
JCHAVEROT
force-pushed
the
feat/detection-toolkit-clean
branch
from
July 11, 2026 18:27
251c48f to
627cf02
Compare
JCHAVEROT
force-pushed
the
feat/privacy-agents-clean
branch
from
July 11, 2026 18:54
1b801cf to
627cf02
Compare
This was referenced Jul 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please refer to the new PR in #344
Summary
Related issue: #293
Depending on: #335
Important rebases were needed to solve conflicts, that's why this PR squashed the commits from its original PR in a fork (link)
This PR adds the first stage for the sanitized context production: pick the domain, build a per-request privacy policy, detect what is sensitive, and transform it
What this adds
DomainProfile: a dataclass with three presets that set the pipeline defaults per domain (sensitive entities, agent prompts, detection and sanitization settings):Sanitization toolkit (
mmore.privacy.sanitization) with four strategies, each a registered agent tool:John Doeto[PERSON_1]presidio_anonymizer.AnonymizerEngine(replace, redact, mask, hash, encrypt, keep, custom)DomainProfileThree agent nodes over a shared
PrivacyStateLangGraph state (analyzer>detector>sanitizer):PrivacyPolicy(entities, detection engine and thresholds, sanitization strategy)RiskAssessment(counts, density, level). Fails clearly on an unknown engineShared
PrivacyPolicy: the Analyzer emits it and the Detector and Sanitizer read itConfig
Dependencies / CI
privacynow has thefakerdependency (for the entity-replacement strategy)Demo
Each strategy runs on the same chunks and hand-annotated spans, so the output isolates strategy behavior from detector noise.
Input chunks
John Doejohn.doe@example.com2024-03-15Alice SmithJohn Doe555-123-4567AB12345678token_masking
entity_replacement (Faker,
consistency=true,John Doemaps to the same fake in both chunks)presidio (
AnonymizerEngine, per operator)synthetic_rewrite (
Qwen/Qwen2.5-3B-Instruct)