← All posts
Data Engineering10 min read

Snowflake Columns With No Masking Policy: Find Them in SQL

Run three ACCOUNT_USAGE queries to find Snowflake columns without a masking policy, rank them by who actually reads them, and stop the gap coming back.

To find Snowflake columns without a masking policy, left-join SNOWFLAKE.ACCOUNT_USAGE.COLUMNS to SNOWFLAKE.ACCOUNT_USAGE.POLICY_REFERENCES, filtered to masking policies, and keep the rows with no match. Restrict the column side to sensitive-looking names or classification tags so you get a short list instead of every column in the account. The queries below do this in under five minutes. They also rank the gaps by who has actually read the data in the last 30 days.

Most teams assume masking is covered because someone wrote a masking policy once. That is usually true for the first table. It is rarely true for the forty tables and marts built since. A policy that protects a single raw customer table does nothing for the dbt mart that copies the email column, or the new ingestion table that landed last sprint.

This matters commercially as well as technically. IBM's 2025 Cost of a Data Breach Report put the global average breach cost at USD 4.44 million. For financial services the same report's average was USD 5.56 million. You do not need a breach to feel the cost of this gap. A due diligence questionnaire or a SOC 2 evidence request will ask you the same question, and you want to answer it from a query rather than from memory.

This post covers Snowflake only. If your warehouse is BigQuery, the access model and the metadata views are different.

Why Do Snowflake Columns End Up With No Masking Policy?

Because Snowflake masking is opt-in per column, and nothing in your pipeline forces the opt-in. In our work with growth-stage fintech and e-commerce teams, the gap almost always comes from one of four places:

  • New columns on existing tables. An upstream source adds a phone_number field and your ingestion picks it up automatically. Nobody touches the policy.
  • Derived marts. A dbt model selects email into a customer mart. Whether the new column is protected depends on how the model is built and what the base table carries.
  • Rebuilt tables. dbt table materialisations rebuild the object. Do not assume a policy attached directly to a column survives that. Verify it, as shown in the last section.
  • Classification that ran once. New tables get created, columns get added, and the auto-tag step does not retroactively cover them.

A pattern we see repeatedly is a team with a well-written masking policy, a tidy governance schema, and a first-run audit that finds sensitive columns sitting in analyst-readable marts. The policy was never wrong. It just was not attached to anything built after the first sprint.

Analytics engineer auditing Snowflake columns without masking policy in SQL results


📺 Watch: Snowflake Dynamic Data Masking | Protect Sensitive Data

Snowflake Dynamic Data Masking | Protect Sensitive Data


How Do You Find Snowflake Columns Without a Masking Policy?

Start with the name-based gap query. It is crude, but it runs on any Snowflake edition that exposes ACCOUNT_USAGE, and it finds the obvious problems fast. The POLICY_REFERENCES view returns one row per attachment, so you can join it to ACCOUNT_USAGE.COLUMNS to enumerate the columns not covered by any policy. Snowflake's own docs point to POLICY_REFERENCES as the account-level way to see every column that has a masking policy.

You need a role with access to the SNOWFLAKE database. Expect ACCOUNT_USAGE latency of up to a couple of hours, so a table created this morning may not show yet.

-- Query 1: sensitive-looking base-table columns with no masking policy
select
    c.table_catalog,
    c.table_schema,
    c.table_name,
    c.column_name,
    c.data_type
from snowflake.account_usage.columns c
join snowflake.account_usage.tables t
  on  t.table_catalog = c.table_catalog
  and t.table_schema  = c.table_schema
  and t.table_name    = c.table_name
  and t.table_type    = 'BASE TABLE'
  and t.deleted is null
left join snowflake.account_usage.policy_references p
  on  p.policy_kind      = 'MASKING_POLICY'
  and p.ref_database_name = c.table_catalog
  and p.ref_schema_name   = c.table_schema
  and p.ref_entity_name   = c.table_name
  and p.ref_column_name   = c.column_name
where c.deleted is null
  and c.table_schema <> 'INFORMATION_SCHEMA'
  and regexp_like(
        c.column_name,
        '.*(EMAIL|PHONE|MOBILE|SSN|NATIONAL_ID|DOB|BIRTH|IBAN|PASSPORT|FIRST_NAME|LAST_NAME|FULL_NAME|TAX_ID).*',
        'i')
  and p.ref_column_name is null
order by 1, 2, 3, 4;

Three notes on reading the output:

  1. I restrict to base tables on purpose. A view that selects a masked base column inherits the masking, so listing views mostly adds noise. Views that rebuild a column with a CASE expression are the exception, so review those by hand.
  2. Tune the regex to your own naming. In payments data, add things like card_number, account_number and sort_code. In e-commerce, add shipping_address and billing_address.
  3. The data_type column matters later. A masking policy signature must match the column type, and a mismatch is a common reason a policy will not attach.

How Do You Find Gaps That Name Matching Misses?

Name matching misses columns called val, notes or col_17 that hold exactly the data you worry about. For those, use Snowflake's sensitive data classification. Every column identified as sensitive is assigned a semantic category and a privacy category. The privacy category can be IDENTIFIER, QUASI_IDENTIFIER or SENSITIVE. Both are stored as system tags, SNOWFLAKE.CORE.SEMANTIC_CATEGORY and SNOWFLAKE.CORE.PRIVACY_CATEGORY.

Once a table has been classified with auto-tagging, Query 2 lists every classified column with no masking policy. Classification itself needs to have run first, via SYSTEM$CLASSIFY or a classification profile, so on a fresh account this returns nothing.

-- Query 2: columns classified as sensitive, with no masking policy
select
    t.object_database,
    t.object_schema,
    t.object_name,
    t.column_name,
    t.tag_value as privacy_category
from snowflake.account_usage.tag_references t
left join snowflake.account_usage.policy_references p
  on  p.policy_kind       = 'MASKING_POLICY'
  and p.ref_database_name = t.object_database
  and p.ref_schema_name   = t.object_schema
  and p.ref_entity_name   = t.object_name
  and p.ref_column_name   = t.column_name
where t.tag_name = 'PRIVACY_CATEGORY'
  and t.domain = 'COLUMN'
  and t.object_deleted is null
  and t.tag_value in ('IDENTIFIER', 'QUASI_IDENTIFIER', 'SENSITIVE')
  and p.ref_column_name is null
order by 1, 2, 3, 4;

Run both and compare. Columns that appear in Query 2 but not Query 1 are the interesting ones, because they are sensitive data with innocent names.

Running those queries for one account is fine. Checking every model in a dbt project for the code-level problems that let this happen, such as hardcoded table references and missing tests, is not something you want to do by hand. fintel-scan is a free, open-source (MIT) CLI that runs fifteen static checks across a dbt project locally, with no warehouse connection: uvx fintel-scan. It complements the warehouse queries here rather than replacing them.

Which Unmasked Columns Should You Fix First?

You will probably end up with a list that is too long to fix in a sprint. Do not fix it alphabetically. Rank it by exposure, using ACCESS_HISTORY (Enterprise Edition) to see who has actually read each column in the last 30 days.

-- Query 3: who read sensitive-looking columns in the last 30 days
select
    f.value:objectName::string      as table_name,
    col.value:columnName::string    as column_name,
    count(distinct ah.user_name)    as distinct_readers,
    count(distinct ah.query_id)     as queries
from snowflake.account_usage.access_history ah,
     lateral flatten(input => ah.direct_objects_accessed) f,
     lateral flatten(input => f.value:columns) col
where ah.query_start_time >= dateadd('day', -30, current_timestamp())
  and f.value:objectDomain::string in ('Table', 'View')
  and regexp_like(
        col.value:columnName::string,
        '.*(EMAIL|PHONE|IBAN|DOB|SSN|FULL_NAME).*',
        'i')
group by 1, 2
order by distinct_readers desc, queries desc;

Join that against Query 1 output and triage with a simple framework:

PriorityConditionAction
1Unmasked, privacy category IDENTIFIER, read by BI or service rolesMask this week
2Unmasked, read by many human usersMask this sprint
3Unmasked, no reads in 30 daysMask, or drop the column
4Unmasked, SENSITIVE but low volumeSchedule with the next mart refactor

Priority 3 is the underrated one. In our experience, a meaningful share of sensitive columns nobody reads should simply not exist in the analytical layer. Dropping them is cheaper than masking them forever.

Also look at who the readers are, not just how many. Service accounts and BI roles often hold broad SELECT grants nobody remembers granting. If you have not reviewed which users exist at all, start with finding dormant Snowflake users. If AI agents or automated tools read from the warehouse, the same logic applies to them. See least-privilege design for AI agent access.

Server cabinet with frosted panels representing Snowflake dynamic data masking of PII

How Do You Stop Snowflake Columns Without a Masking Policy Coming Back?

Fixing today's list is the easy half. The harder half is making sure next month's mart does not recreate it.

1. Prefer tag-based masking over per-column attachment. Attach the policy to a tag once, then tag columns. New columns that get the tag are protected automatically.

create masking policy governance.policies.mask_email as (val string)
  returns string ->
  case
    when is_role_in_session('PII_READER') then val
    else regexp_replace(val, '.+@', '*****@')
  end;

create tag governance.tags.pii_email;
alter tag governance.tags.pii_email
  set masking policy governance.policies.mask_email;

alter table analytics.marts.dim_customer
  modify column email
  set tag governance.tags.pii_email = 'email';

Two caveats. A given column can be protected by only one masking policy, so a tag-based policy will conflict with one you attached directly. And the policy data type must match the column type, so you need one policy per type.

2. Verify the policy survives your dbt run. This is the check most teams skip. Run a table-materialised model, then use the real-time INFORMATION_SCHEMA table function rather than the delayed ACCOUNT_USAGE view:

select *
from table(
  analytics.information_schema.policy_references(
    ref_entity_name   => 'analytics.marts.dim_customer',
    ref_entity_domain => 'table'
  )
);

If the row disappears after the run, re-apply the tag or policy in a post-hook, or move the protection to a mechanism that survives the rebuild. Do not guess. Test it on your own dbt and Snowflake setup.

3. Turn the audit into a failing test. A singular dbt test returns rows when something is wrong:

-- tests/assert_pii_columns_masked.sql
select c.table_schema, c.table_name, c.column_name
from snowflake.account_usage.columns c
left join snowflake.account_usage.policy_references p
  on  p.policy_kind       = 'MASKING_POLICY'
  and p.ref_database_name = c.table_catalog
  and p.ref_schema_name   = c.table_schema
  and p.ref_entity_name   = c.table_name
  and p.ref_column_name   = c.column_name
where c.deleted is null
  and c.table_catalog = '{{ target.database }}'
  and c.table_schema  = 'MARTS'
  and regexp_like(c.column_name, '.*(EMAIL|PHONE|IBAN|DOB).*', 'i')
  and p.ref_column_name is null

Because ACCOUNT_USAGE lags, run this on a schedule rather than immediately after a build, or you will get false failures on brand-new tables. Start at severity warn, clear the backlog, then switch it to error. Also check how much it costs to run in CI. See our notes on dbt Slim CI for BigQuery for the same principle: do not run governance checks on every pull request if a nightly run does the job.

4. Re-run classification on a schedule. Because auto-tagging is not retroactive, schedule it weekly across the schemas your dbt project writes to.

Frequently Asked Questions

Q: How do I find columns without a masking policy in Snowflake?

A: Left-join SNOWFLAKE.ACCOUNT_USAGE.COLUMNS to SNOWFLAKE.ACCOUNT_USAGE.POLICY_REFERENCES where policy_kind is MASKING_POLICY, and keep rows with no match. Filter the column side to sensitive names or PRIVACY_CATEGORY tags to keep the list useful.

Q: Does Snowflake mask PII automatically?

A: No. Classification can detect and tag likely sensitive columns, but a masking policy only applies when you attach it to a column or to a tag on that column. Without that step the data is returned in plain text to any role with SELECT.

Q: Do masking policies survive a dbt table rebuild?

A: Do not assume so. Table materialisations rebuild the object, so confirm after a run that the policy is still listed in the INFORMATION_SCHEMA POLICY_REFERENCES function. If it is gone, re-apply it in a post-hook or use a tag-based approach that you have verified against your own setup.

Q: What Snowflake edition do I need for masking and access history?

A: Dynamic data masking and ACCESS_HISTORY are Enterprise Edition features or higher. On lower editions you can still run the name-based COLUMNS query to size the problem, but you cannot enforce masking natively.

Q: How often should I audit Snowflake columns without a masking policy?

A: Weekly is a sensible default for a team shipping dbt models regularly, and daily if you ingest new sources often. Automate it as a scheduled test so the audit never depends on someone remembering.

Closing

The challenge is rarely writing a masking policy. It is knowing, on any given Tuesday, which Snowflake columns without a masking policy are being read by people and tools that should not see them. At Fintel Analytics, we have helped fintech, payments and e-commerce teams run exactly this audit, then build the tag-based masking, dbt tests and access reviews that keep it clean as the project grows. If your next investor or enterprise customer asks where your PII sits, you want a query as the answer, and that is a fixable problem.

← Back to all posts