Skip to main content

Data Classification & Tag-Based Masking

Manually identifying sensitive data across hundreds of tables doesn't scale. Snowflake provides automatic classification to detect PII, an object tagging system to label it, and tag-based masking policies to protect it — all wired together.


Object Tagging Fundamentals​

Tags in Snowflake are key-value metadata attached to objects. They're schema-level objects with their own lifecycle.

CREATE TAG governance.tags.data_sensitivity
ALLOWED_VALUES 'PUBLIC', 'INTERNAL', 'CONFIDENTIAL', 'RESTRICTED';

CREATE TAG governance.tags.pii_type
ALLOWED_VALUES 'NAME', 'EMAIL', 'PHONE', 'SSN', 'DOB', 'ADDRESS', 'NONE';

Apply tags to tables and columns:

ALTER TABLE customers.profiles
SET TAG governance.tags.data_sensitivity = 'CONFIDENTIAL';

ALTER TABLE customers.profiles
MODIFY COLUMN email SET TAG governance.tags.pii_type = 'EMAIL';

ALTER TABLE customers.profiles
MODIFY COLUMN phone_number SET TAG governance.tags.pii_type = 'PHONE';

Tags can be applied to databases, schemas, tables, columns, and warehouses. They propagate through the object hierarchy — tag a schema, and the tag applies to every table and column within it.


Tag-Based Masking Policies​

You can link a masking policy directly to a tag. Any column carrying that tag value automatically gets the masking policy applied — no need to attach policies column by column.

CREATE OR REPLACE MASKING POLICY mask_email_tag
AS (val VARCHAR) RETURNS VARCHAR ->
CASE
WHEN IS_ROLE_IN_SESSION('PII_READER') THEN val
ELSE REGEXP_REPLACE(val, '.+@', '***@')
END
;

CREATE OR REPLACE MASKING POLICY mask_phone_tag
AS (val VARCHAR) RETURNS VARCHAR ->
CASE
WHEN IS_ROLE_IN_SESSION('PII_READER') THEN val
ELSE '***-***-' || RIGHT(val, 4)
END
;

Attach each policy to its corresponding tag value:

ALTER TAG governance.tags.pii_type SET MASKING POLICY mask_email_tag FOR 'EMAIL';
ALTER TAG governance.tags.pii_type SET MASKING POLICY mask_phone_tag FOR 'PHONE';

From this point on, any column tagged with pii_type = 'EMAIL' is automatically masked. Tag a new column, and it's protected instantly.


Automatic Data Classification​

Snowflake's classification engine analyzes column names and sample data to identify sensitive information automatically.

SELECT *
FROM TABLE(SNOWFLAKE.CORE.EXTRACT_SEMANTIC_CATEGORIES('customers.profiles'));

This returns suggested categories per column:

ColumnSemantic CategoryPrivacy CategoryProbability
full_nameNAMEIDENTIFIER0.95
emailEMAIL_ADDRESSIDENTIFIER0.98
phone_numberPHONE_NUMBERIDENTIFIER0.92
date_of_birthDATE_OF_BIRTHQUASI_IDENTIFIER0.88
account_balanceNULLNULLNULL

Apply classifications as system tags automatically:

CALL SYSTEM$CLASSIFY('customers.profiles', {'auto_tag': true});

Classification Categories​

Snowflake's classifier recognizes a wide range of sensitive data types:

CategoryExamplesPrivacy Category
NAMEFull name, first name, last nameIDENTIFIER
EMAIL_ADDRESSEmail addressesIDENTIFIER
PHONE_NUMBERPhone, fax, mobileIDENTIFIER
US_SSNSocial Security NumbersIDENTIFIER
DATE_OF_BIRTHBirth datesQUASI_IDENTIFIER

Identifiers can directly identify a person. Quasi-identifiers can identify someone when combined with other data.


Automating Classification Across Schemas​

For large environments, classify entire schemas programmatically and schedule it:

CREATE OR REPLACE TASK classify_new_tables
WAREHOUSE = governance_wh
SCHEDULE = 'USING CRON 0 2 * * 0 America/New_York'
AS
CALL governance.procedures.classify_schema('MY_DB', 'PUBLIC');

New tables get classified automatically on the weekly schedule.


Tag Lineage and Propagation​

Tags follow a propagation model:

  • A tag on a database propagates to all schemas, tables, and columns within it.
  • A tag on a schema propagates to all tables and columns within it.
  • A tag on a column takes precedence over inherited tags.
-- Mark entire schema as INTERNAL
ALTER SCHEMA analytics.reporting
SET TAG governance.tags.data_sensitivity = 'INTERNAL';

-- Override specific columns that contain PII
ALTER TABLE analytics.reporting.user_metrics
MODIFY COLUMN user_email
SET TAG governance.tags.data_sensitivity = 'CONFIDENTIAL';

When a table is cloned, tags on the source are copied to the clone.


Governance Dashboards: Querying Tag and Policy References​

Monitor your governance posture with ACCOUNT_USAGE views:

-- Find all objects with a specific tag
SELECT *
FROM SNOWFLAKE.ACCOUNT_USAGE.TAG_REFERENCES
WHERE tag_name = 'DATA_SENSITIVITY'
AND tag_value = 'CONFIDENTIAL'
ORDER BY object_name;

-- Find all columns protected by masking policies
SELECT
ref_entity_name AS table_name,
ref_column_name AS column_name,
policy_name
FROM SNOWFLAKE.ACCOUNT_USAGE.POLICY_REFERENCES
WHERE policy_kind = 'MASKING_POLICY'
ORDER BY ref_entity_name;


End-to-End Workflow: Classification to Protection​

Tying the whole process together for a new table:

-- Step 1: Classify the new table
CALL SYSTEM$CLASSIFY('sales.raw.customer_orders', {'auto_tag': true});

-- Step 2: Apply custom tags where classification missed
ALTER TABLE sales.raw.customer_orders
MODIFY COLUMN loyalty_id
SET TAG governance.tags.pii_type = 'IDENTIFIER';

-- Step 3: Verify masking is active
USE ROLE ANALYST;
SELECT customer_name, email, phone FROM sales.raw.customer_orders LIMIT 5;

Once your tag-based masking policies are set up, new tables only need to be classified and tagged. Protection follows automatically.


Key Takeaways​

  • Object tags are flexible metadata that propagate through the object hierarchy.
  • Tag-based masking links policies to tag values — protect columns by tagging them, not by attaching policies individually.
  • Automatic classification uses SYSTEM$CLASSIFY and EXTRACT_SEMANTIC_CATEGORIES to detect PII.
  • Schedule classification as a task to keep up with new data sources.
  • Query TAG_REFERENCES and POLICY_REFERENCES to build governance coverage dashboards.

Next, we'll cover network security and private connectivity.