Skip to content

fix(masking): validate unmatched columns and support snake_case matching - #269

Open
Voyagerroc-Lab wants to merge 1 commit into
FreshCode-Org:mainfrom
Voyagerroc-Lab:fix/251-masking-unmatched-columns
Open

Voyagerroc-Lab wants to merge 1 commit into
FreshCode-Org:mainfrom
Voyagerroc-Lab:fix/251-masking-unmatched-columns

Conversation

@Voyagerroc-Lab

Copy link
Copy Markdown

Summary of Changes

This PR addresses #251 by handling unmatched and variant column names in masking rules:

  • Snake-case / Case-normalization Column Matching:
    • _resolve_columns now matches rule columns against DataFrame columns using both exact names and snake_case normalization (snake_case(col)), ensuring common casing variants (like --mask Email:hash for email, or First Name for first_name) resolve correctly.
  • Strict Validation for Missing Columns:
    • Added strict: bool = True field to MaskingRule and strict: bool | None = None parameter to mask_dataframe.
    • When explicit rule.columns are provided and any are missing from the DataFrame, ValueError is raised in strict mode (the default), causing the CLI to exit with code 1 and a descriptive error message instead of silently exiting 0 with unmasked data.
  • Audit Logging of Unmatched Columns:
    • Added unmatched_columns: list[str] to MaskReport and included it in MaskReport.to_dict(), capturing any unmatched columns for compliance and auditing when running in non-strict mode.
  • Testing:
    • Added unit tests in tests/test_enterprise_cleaner.py for snake_case column matching, strict ValueError raising on missing columns, and non-strict tracking in MaskReport.unmatched_columns.
    • Added CLI tests in tests/test_enterprise_cli.py verifying --mask Email:hash successfully masks email and --mask non_existent:hash exits with code 1 and an informative error message.

Closes #251

@coderabbitai

coderabbitai Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 9e826bfe-9ca4-4c47-bd2f-5c772c536003


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Masking rules naming a non-existent column mask nothing and exit 0, leaving raw PII

1 participant