fix(ai-service): enforce PII scrubbing on the humanitarian verification path - #452
Open
Degentle12 wants to merge 1 commit into
Open
Conversation
…on path The PII scrubber was only reachable as an opt-in /anonymize endpoint, so /v1/ai/humanitarian/verify transmitted raw recipient evidence (names, locations, phones, emails, IDs) to OpenAI/Groq unredacted. Wire the scrubber in as a mandatory preprocessing stage before prompt construction: - Scrub aid_claim, supporting_evidence, and string-valued context_factors before any provider call; only masked tokens reach the provider. - Fail closed: when PII_SCRUBBING_ENABLED=false or scrubbing itself fails, the request is rejected and no provider call is made. - Expose a pii_scrubbing block (applied/anonymized/pii_summary) in the verification response so callers can tell scrubbed input from raw; raw text stays on the backend side only. - Persist aggregate-only scrub metadata (counts + SHA-256 fingerprint, never text) to the pii_decisions store when enabled. - Document the scrubbing posture and residual risk in the AI service README. Closes ChainForgee#430
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.
Closes #430
Problem
/v1/ai/humanitarian/verifytransmitted raw recipient evidence (names, locations, phones, emails, IDs) straight to OpenAI/Groq. The PII scrubber was only reachable as an opt-in/anonymizeendpoint, so nothing enforced anonymization before the provider call.Changes
HumanitarianVerificationService:aid_claim, everysupporting_evidenceentry, and string-valuedcontext_factorsare scrubbed before any prompt is constructed, so only masked tokens ever reach a provider.PII_SCRUBBING_ENABLEDsetting (defaulttrue). When scrubbing is disabled or raises, the request is rejected withsuccess=falseand no provider call is made — raw text is never sent unredacted.pii_scrubbingblock (applied,anonymized,pii_summary) so callers can distinguish scrubbed input from raw; raw text remains on the backend (human-review) side only.PII_DECISIONS_ENABLED=true, each verification persists an aggregate-only record (entity/token counts + non-reversible SHA-256 fingerprint, never text) to thepii_decisionsstore, mirroring the/v1/ai/anonymizeaudit path.Verification
New tests in
tests/test_humanitarian_pii_scrubbing.py:Full suite:
256 passed.flake8 --select=E9,F63,F7,F82clean;test_setup.pypasses.Out of scope
Improving scrubber detection precision and backend-side metadata scrubbing (#213) remain separate concerns as scoped in the issue.