What you will be able to do
- Choose between a row filter and a column mask for a given visibility requirement
- Decide when an ABAC policy beats a table-level mask, and what happens when both apply
- Design mask functions that keep query and retrieval latency low
Key concept
Query-time masking — Row filters and column masks are SQL functions that Unity Catalog runs every time a protected table is queried. They decide which rows a user sees and what each sensitive value looks like. Because they run inside every query, how expensive the function is decides how fast the query is.
1.Row filters hide rows, column masks rewrite values
A GenAI application that reads governed tables, such as a RAG retriever or an agent tool that runs SQL, inherits whatever Unity Catalog lets the querying identity see. That makes masking a guardrail in the data layer. The model can't leak a value that the query never returned. Unity Catalog gives you two controls for this, and each answers a different question.
A row filter answers "which records may this user see?" It is a SQL UDF that is evaluated against each row and returns a boolean. Rows where it returns FALSE are dropped from the result. Use it when access depends on a value in the row, such as a region, a department or an account.
A column mask answers "what should this user see in this field?" It is a SQL UDF that takes the column value and returns either the original or a masked version, and its return type must match or be castable to the column's type. Each column can have only one mask. A mask can also take other columns as inputs, so its behaviour can depend on several attributes. Use it when the user should still query the table but must not read SSNs, phone numbers or email addresses.
The mistake to avoid is reaching for a mask when the requirement is about rows. If amounts must stay readable while other regions' records disappear, the only control that meets it is a row filter that compares the row's region with the user's team. A mask on region leaves every row in the result. A mask on claim_amount hides the very value the requirement says to keep visible.
Checkpoint 1 of 4· Check yourself
An agent tool runs SQL against a customers table. Support agents must still be able to query every customer record, but they must not read SSNs. Which control meets this requirement?
The requirement is about what a field looks like, not which records are visible, so it needs a column mask. One mask function can return the original value or a masked version depending on the user. A row filter would drop the records the agents still need, a row filter only returns a boolean, and a column can have only one mask.
“You need to redact sensitive fields, such as SSNs, phone numbers, or email addresses, while still allowing the principal to query the table.”Source: docs.databricks.com
Checkpoint 2 of 4· Exam question
A RAG application's retrieval layer queries a claims table where analysts in the us-team group should see only rows for the US region, while the claim amount values themselves must remain fully visible to every analyst. Which governance control satisfies this requirement?
Correct answer: A — Set a row filter on the claims table that returns only rows where region is US to us-team members, leaving claim_amount values as stored.
- A. A row filter evaluates a condition per row and returns only the matching rows. Filtering on region =
USforus-teammembers limits which claims they can see, and the amount column is not altered in the rows that remain. - B. A column mask changes the value shown in one column and never removes rows. Masking
regionhides the region label, but the non-US claims, with their amounts, are still returned tous-teammembers, so the row restriction is not met. - C. Masking
claim_amountreturns NULL in place of real amounts, which breaks the requirement that amounts stay fully visible to analysts. A mask also leaves every row in the result, so non-US claims are still returned. - D. This row filter is keyed to claim size, not region. Non-US claims below the limit would still be returned, and US claims above it would be hidden, so it does not restrict
us-teammembers to US rows.
2.ABAC policies or table-level masks
Both controls can be attached in two ways. A table-level filter or mask is bound to one table with ALTER TABLE ... SET ROW FILTER or ALTER TABLE ... ALTER COLUMN ... SET MASK, and the table owner manages it. An ABAC policy attaches at the catalog or schema level (or the metastore, for org-wide rules) and applies automatically to every column that carries a matching governed tag. When masking has to be consistent across many tables, Databricks recommends ABAC over both table-level controls and dynamic views.
| Situation | Better fit |
|---|---|
| Same PII rule across many tables, schemas or catalogs | ABAC policy |
| New tables should be covered automatically once tagged | ABAC policy |
| Policy authors and data stewards (who tag) are separate roles | ABAC policy |
| One table with strict logic that doesn't generalize | Table-level filter or mask |
| Small, stable set of tables managed by their owners | Table-level filter or mask |
ABAC also has two guardrail advantages beyond scale. Higher-level admins can define the policies, so table owners can't override or remove them. And Databricks evaluates policy logic more efficiently than table-specific UDFs.
The two styles can coexist on the same table, with one firm rule: only one distinct row filter, and one distinct mask per column, can resolve for a given user. Databricks detects conflicts by comparing functions, not outputs. If an ABAC policy and a table-level mask apply two different functions, the query errors even when both would return identical data.
Inside an ABAC policy, decide who is masked with the TO and EXCEPT clauses rather than with identity checks inside the UDF. That keeps the function simple. Identity functions such as is_account_group_member() are still valid when the logic really is conditional. Keep the policy count low as well. ABAC is meant to reduce rules, and large numbers of policies with complex conditions slow down authorization checks.
Checkpoint 3 of 4· Check yourself
A governance admin attaches an ABAC column mask policy to a catalog. It masks every column tagged as an SSN with the function mask_ssn_std. One table owner had already run ALTER TABLE ... ALTER COLUMN ssn SET MASK with their own function, mask_ssn_owner. For an analyst, both functions return 'XXX-XX-XXXX'. What happens when that analyst queries the table?
Only one distinct mask can resolve per column for a given user. Databricks finds conflicts by comparing the functions, not their output, so two different functions block the query even when they return the same data.
“If multiple distinct row filters or column masks apply to the same user and table or column, Databricks blocks access and returns an error.”Source: docs.databricks.com
3.Keeping mask functions cheap enough to meet latency targets
A mask's cost is paid on every row. The UDF runs once per row for filters and once per matching value for masks, inside every query. A retriever that pulls thousands of rows through a slow mask misses its latency target no matter how fast the model is. The engine makes this worse on purpose: when it has to choose between an optimization and preventing leakage of masked values, it always makes the secure choice.
| Prefer | Avoid | Why |
|---|---|---|
| Simple CASE and boolean expressions | Multi-level nesting, mapping tables, expression subqueries | Fewer expressions perform better |
| SQL UDFs | Python UDFs | Python offers fewer optimization opportunities |
| Lookup tables small enough to broadcast, partitioned to the access pattern (for example by username) | Joins against large tables | Large joins prevent broadcast hash joins and force nested loop joins |
| Only target-table columns as inputs | External API calls, per-row information_schema lookups | Network calls add latency and timeouts |
| Deterministic, error-safe functions such as try_divide | Expressions that can throw, such as ANSI division | Possible errors block pushdown, because an error could reveal pre-mask values |
| Masks on large text skipped or kept simple | Heavy regex on serialized documents | Regex forces a scan and rewrite of the whole payload per row |
Two more costs come from how many masks you have and what you pass to them. Each distinct mask on a table is evaluated during queries, so mask only truly sensitive columns and reuse one function across columns. Every UDF argument costs something too. Databricks cannot optimize away a column passed as an argument even when the query never selects it. Row filters are the same kind of problem: piling AND conjuncts into the one filter that can resolve makes it more likely to include one of the slow patterns above.
Reusing one function gets easiest with a VARIANT mask. Databricks casts the column value to VARIANT before the function runs and casts the result back to the column's type, so a single ABAC policy can cover INT, DOUBLE and DECIMAL columns. Mark functions DETERMINISTIC where that applies. It also lets filters run before the mask.
CREATE FUNCTION mask_numeric(val VARIANT)
RETURNS VARIANT
DETERMINISTIC
RETURN 0::VARIANT;Checkpoint 4 of 4· Fill the gap
You want one SQL mask function that an ABAC policy can reuse on INT, DOUBLE and DECIMAL columns, and you want filters to be able to run before the mask. Which keyword completes the function?
CREATE FUNCTION mask_numeric(val VARIANT)
RETURNS VARIANT
?
RETURN 0::VARIANT;Marking the mask DETERMINISTIC gives the optimizer more room to work and lets filters run before the mask. The VARIANT input and return type let one function cover many numeric column types. READS SQL DATA describes a function that queries tables, which is the slow per-row lookup pattern this section warns against.
Source: docs.databricks.comSources
(7)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“Rows where the function returns FALSE are excluded from query results.”
↩︎ Row filters hide rows, column masks rewrite values“Each column can have one mask.”
↩︎ Row filters hide rows, column masks rewrite values“For consistent row filtering and column masking across many tables, ABAC policies are the recommended approach.”
↩︎ ABAC policies or table-level masks“For a more detailed comparison with dynamic views and ABAC policies, see When to use ABAC vs table-level row filters and column masks.”
↩︎ ABAC policies or table-level masks“Policy logic is also evaluated more efficiently than table-specific UDFs.”
↩︎ ABAC policies or table-level masks“it always makes the secure choice, which can affect query performance.”
↩︎ Keeping mask functions cheap enough to meet latency targets“Databricks cannot optimize away column references that come from UDF arguments, even if those columns are not used in the query.”
↩︎ Keeping mask functions cheap enough to meet latency targets“access controls that restrict the rows and column values a user can see at query time”
↩︎ Key concept“The mask is a SQL UDF that takes the column value as input and returns the original value or a masked version.”
↩︎ Exam trap 1“Prefer simple CASE expressions over mapping tables or expression subqueries.”
↩︎ Exam trap 2 - 2.
“You need to redact sensitive fields, such as SSNs, phone numbers, or email addresses, while still allowing the principal to query the table.”
↩︎ Row filters hide rows, column masks rewrite values“Access depends on the values in each row, such as filtering by the values in a column that contains geographic regions.”
↩︎ Row filters hide rows, column masks rewrite values - 3.
“Each table has strict, specific logic that doesn't generalize to other tables.”
↩︎ ABAC policies or table-level masks“If they apply different functions, Databricks blocks access and returns an error, even if those functions produce identical data output.”
↩︎ Exam trap 3 - 4.
“use the policy's TO and EXCEPT clauses to define which users and groups the policy applies to. This keeps UDF logic simple.”
↩︎ ABAC policies or table-level masks“Large numbers of policies and complex conditions can slow authorization checks.”
↩︎ ABAC policies or table-level masks - 5.
“The UDF in an ABAC policy executes for every row (row filters) or every matching column value (column masks) during query execution.”
↩︎ Keeping mask functions cheap enough to meet latency targets“Each distinct mask on a table adds overhead; reusing the same function across columns can reduce it.”
↩︎ Keeping mask functions cheap enough to meet latency targets“Network calls can introduce additional latency and timeouts.”
↩︎ Keeping mask functions cheap enough to meet latency targets - 6.
“can mask columns of many data types, which reduces the number of UDFs and policies you maintain.”
↩︎ Keeping mask functions cheap enough to meet latency targets
Also cited
“If multiple distinct row filters or column masks apply to the same user and table or column, Databricks blocks access and returns an error.”
↩︎ Checkpoint