BXUP Track progress & test yourself — free
QA & Testing · Playbook · Core · ~6 min read
QA & TESTING · PLAYBOOK · CORE

Mask PII Before Any Prompt — the Privacy-Safe Test Data Workflow

The fastest way to turn an AI-assisted QA practice into a data-protection incident is pasting a production extract into a chat window. This workflow puts detection and masking in front of every prompt: Presidio finds the PII, a local model handles the sensitive step, and a per-tool decision tree says what may enter which assistant — DPDP Rules and GDPR compliant by construction.

Tier: Core · Workflow area: Test data & environments

This playbook builds the pipeline — discover, mask, verify, then prompt — plus the one-page decision tree that makes the policy usable by the whole team rather than known by one careful engineer.

USE IT WHEN

Real data wants to meet an AI tool

  • Any workflow in this track touches production-derived artifacts: extracts for test data, logs for flake triage, HARs for defect reports, traces for root-cause bundles.
  • DPDP Rules 2025, GDPR, or a services client's contract governs the data you test with.
  • The team's current "policy" is individual judgment about what is safe to paste.
SKIP IT WHEN

There is nothing to protect — provably

  • The data is fully synthetic from a factory with reserved identifier ranges (previous playbook) — masking synthetic data is theater.
  • The tool never leaves your boundary (local Ollama, client-hosted endpoint) and policy only restricts egress — though masking may still be right, since test artifacts spread further than tools.
  • You need irreversible anonymization for data publication — that is a stricter discipline (k-anonymity, DP) than test-data masking; consult the privacy team.

Prerequisites

  • Python environment with Microsoft Presidio (presidio-analyzer, presidio-anonymizer) and its NLP model.
  • Ollama with a capable local model for the sensitive-context steps.
  • A catalog of the AI tools your team actually uses, each with its data-processing terms (retention, training use, region).
  • Sign-off channel: whoever owns privacy/DPO duties reviews the decision tree once.

The workflow

  1. Discover before you believe. Run Presidio's analyzer over a representative extract and measure what lives in it — schemas lie about where PII hides (free-text notes fields are the classic offender):

    from presidio_analyzer import AnalyzerEngine
    analyzer = AnalyzerEngine()
    results = analyzer.analyze(text=row_text, language="en",
        entities=["PERSON","EMAIL_ADDRESS","PHONE_NUMBER","CREDIT_CARD",
                  "IN_AADHAAR","IN_PAN","LOCATION","DATE_TIME","IP_ADDRESS"])
    
    discovery report — orders_extract.csv (10k rows)
    EMAIL_ADDRESS 10,012 · PERSON 11,394 · PHONE 9,876 · IN_PAN 214 (!)
    IN_AADHAAR 3 (!!) · notes column: 1,102 PERSON hits nobody expected
    

    PAN and Aadhaar in an orders table is a finding to report upstream, not just to mask.

  2. Extend recognizers for your domain identifiers. Out-of-the-box entities miss customer IDs, order references, internal employee codes — anything that re-identifies when joined. Add pattern recognizers (PatternRecognizer with regex + context words) for each, and re-run discovery until the report matches your data-owner's expectations.

  3. Mask with consistency, not just redaction. Test data must stay useful: referential joins and realistic shapes survive when masking is deterministic per value:

    from presidio_anonymizer import AnonymizerEngine
    # strategy per entity:
    #   EMAIL -> hash-keyed fake:  u_a41f2@masked.example
    #   PERSON -> Faker name seeded by hash(original)   (same person -> same alias)
    #   PHONE/PAN/AADHAAR -> synthetic valid-format from reserved ranges
    #   free text -> replace spans, keep surrounding prose
    

    Same input always maps to the same alias, so anita@… appearing in users, orders, and a log line becomes the same masked identity everywhere — joins, dedupe tests, and log-correlation workflows keep working.

  4. Verify the mask with a second, independent pass. Re-run the analyzer over the masked output; the pass condition is numeric:

    verification — orders_masked.csv: 0 findings above 0.4 confidence
    canary check: 25/25 planted identifiers caught and masked in pipeline test
    

    The canary set — identifiers you deliberately plant in a pipeline test — is your ongoing regression suite for the masker itself. A masking pipeline without its own tests is a policy written in hope.

  5. Route the residual risk through a local model. Some steps need semantic judgment on unmasked data — "which of these free-text notes mention health conditions?" — precisely the data that must not leave. Run those steps on Ollama:

    ollama run llama3.1:8b "Classify each note: contains-sensitive-category or clean.
    Notes follow..." < notes_batch.txt
    

    Local models are good enough for classification and pre-screening; the powerful external model gets the masked output afterward. This split — local for sensitive, external for masked — is the workflow's load-bearing wall.

  6. Publish the decision tree and make it the default path. One page, three questions, on the wall:

    Q1 Is the artifact fully synthetic (factory-generated)?     -> any approved tool
    Q2 Has it passed the masking pipeline with 0 findings?      -> approved external
       tools (list: ...), with client tools first on client work
    Q3 Neither?                                                 -> local Ollama only,
       or don't use AI for this step. NO EXCEPTIONS FOR DEADLINES.
    

    Wire convenience toward compliance: a make mask FILE=... target, masked-extract storage the team pulls from by default, and the pipeline running in CI on every new extract. The policy people follow is the one that is easier than the violation.

Warning

Masking is for names, numbers, and identifiers — not for guilt. If discovery finds regulated identifiers (Aadhaar, PAN, card numbers) somewhere they should never be stored, masking the extract does not fix the system that leaked them into an orders table. File that as a finding to the data owner; the pipeline just handed you the evidence.

Variations

  • Log and HAR scrubbing: the same analyzer + anonymizer over CI logs, HAR files, and trace exports feeds the flake-triage, defect-report, and root-cause playbooks — one pipeline, many consumers. Add recognizers for bearer tokens and session cookies.
  • Database-native masking: for full-environment refreshes, push deterministic masking into the ETL (SQL + hash functions) and reserve Presidio for free-text columns — throughput without losing the verification pass.
  • DPDP/GDPR posture: masked-for-testing data generally remains personal data under strict readings if re-identifiable; deterministic-alias tables must themselves be access-controlled. Keep the alias key in a secrets store, not the repo.
  • No-Presidio environments: regex + Faker gets you surprisingly far for structured columns; you lose NER on free text — compensate by routing all free-text columns to the local-model path.

Quality check

  • Discovery before masking, every extract: reports archived; surprises (new PII columns) escalated, not silently masked.
  • Zero-findings verification: independent re-analysis of masked output clean; canary regression green in CI.
  • Consistency proven: join a masked parent/child pair and confirm referential behavior survives.
  • Tree adoption: spot-check real team artifacts (prompt histories, tickets) for the masked-extract path being used — the audit is of behavior, not the document.
  • Alias-key custody: re-identification material stored and access-logged separately from the masked data.

Pitfalls

  • Schema-based confidence. "That table has no PII columns" — until discovery finds names in notes, emails in metadata_json, and an Aadhaar number in description. Always run discovery on actual data.
  • Random (non-deterministic) masking. Breaks joins and dedupe tests, and teams quietly revert to raw extracts "just for this test". Deterministic aliasing is what makes the safe path usable.
  • Masking the batch, leaking the sample. The three rows someone pastes into a ticket to discuss the masking pipeline are raw. The pipeline's boundary is every artifact, including screenshots and Slack messages.
  • Trusting one pass. The analyzer that masked is the analyzer that missed; verification must be a separate run with the canary set, ideally stricter thresholds.
  • Local-model complacency. Local means no egress — it does not mean no access control. The unmasked batch on a laptop is still an incident waiting for a lost laptop.

Restricted-environment variant

This playbook is the restricted-environment playbook — but services-company delivery adds one layer: the client's rules override yours. Confirm which masking standard the client requires (some mandate their own tooling or on-premises processing), run the pipeline inside their environment where required, and put the decision tree into the engagement's runbook with the client's approved-tool list substituted. Disclose the pipeline in the engagement's data-processing documentation — a working masker with canary tests is an asset in the client's audit, and it is much better introduced before their DPO asks.

Success criteria

  • Every production-derived artifact that meets an AI tool has a masking record; prompt-history audits find zero raw-data violations.
  • Verification passes and canary regressions run automatically; the masker has its own green CI badge.
  • The decision tree is signed off by the privacy owner and demonstrably followed by the team under deadline pressure.
  • At least one upstream finding (PII where it should not live) reported from discovery — the pipeline improving the system, not just laundering its output.
Key Takeaway:

Privacy-safe AI-assisted QA is an architecture, not a resolution. Detection you can test, masking that preserves utility, a local path for what must not leave, and a three-question tree anyone can follow — build it once, and "can I paste this?" stops being a judgment call forever.

This is the free reading view. Open BXUP to track your progress, run the hands-on labs, and prove it with original, exam-pattern assessments.
© Anvi Innovate · BXUP — Be Exponentially Upskilled · BXUP is an independent learning platform, not affiliated with or endorsed by AWS, Microsoft, Google, NVIDIA, IBM, Salesforce, Databricks, Oracle or Anthropic. All trademarks belong to their respective owners. · bxup.in