altimate-code icon indicating copy to clipboard operation
altimate-code copied to clipboard

[Feature] Improve PII detection with column-name heuristics

Open anandgupta42 opened this issue 9 months ago • 1 comments

Problem

The altimate_core_query_pii tool returns "CLEAN" for queries that clearly select PII columns (SSN, credit_card_number, email, phone, date_of_birth). This happens because the tool needs schema context that isn't provided, leading to false negatives.

For a security-critical feature, false assurance is worse than no detection.

Desired Behavior

PII detection should work even without full schema context by using column-name heuristics as a first-pass analysis.

Implementation Notes

Approach

Phase 1: Column-name regex matching (quick win)

Add a fast first-pass detector that flags columns based on name patterns, inspired by piicatcher's ColumnNameRegexDetector:

Personal:   first_name, last_name, full_name, ssn, social_security, passport, date_of_birth, dob
Contact:    email, phone, phone_number, mobile, address, street, city, zip, postal
Financial:  credit_card, card_number, cvv, bank_account, iban, salary, income
Auth:       password, passwd, secret, token, api_key
Health:     diagnosis, medical, patient, prescription

This doesn't need warehouse access or API credentials — just parse the SQL to extract column names/aliases.

Phase 2: Schema-enhanced detection

When schema cache is populated:

  • Use column types + names for better classification (e.g., VARCHAR(9) named ssn → high confidence SSN)
  • Cross-reference with table context (columns in a users table are more likely PII than in metrics)

Phase 3: Belt-and-suspenders

Always run column-name heuristics even when altimate_core_query_pii reports CLEAN:

  • If heuristics find potential PII but the API says clean → flag with lower confidence: "Potential PII detected based on column names (ssn, email). Verify with schema context."
  • If both agree → high confidence result

Key Files

  • PII detection tool implementation
  • Python engine methods for PII analysis
  • Schema cache for column metadata

Industry Patterns

  • Microsoft Presidio: 3-layer approach — regex → NLP NER → context-aware enhancer, 50+ recognizers
  • piicatcher: Column-name regex (fast) + data sampling (accurate), extensible detector classes
  • Snowflake: EXTRACT_SEMANTIC_CATEGORIES assigns semantic + privacy category tags
  • BigQuery: DLP API integration with auto-tagging

Acceptance Criteria

  • [ ] Column-name heuristics detect obvious PII patterns (ssn, email, credit_card, etc.)
  • [ ] Works without warehouse access or API credentials
  • [ ] Results clearly indicate confidence level and detection method
  • [ ] False negatives reduced for queries with obviously-named PII columns
  • [ ] Heuristics run as complement to (not replacement for) existing PII detection

anandgupta42 avatar Mar 05 '26 23:03 anandgupta42

I'd like to contribute Phase 1 with column-name and output-alias heuristics alongside the native PII analysis, including with a partial schema. Results would preserve engine findings and label heuristic hits with their detection method and low confidence. No warehouse connection or API credentials would be needed.

The local prototype has 27 passing tests covering obvious names, near misses, aliases and classification failures. Schema enrichment and data sampling would remain separate. Is this scope acceptable, and may I open a PR?

Drafted-by: Codex (GPT-6); reviewed by @Vamsi-klu before posting

Vamsi-klu avatar Oct 25 '26 02:10 Vamsi-klu