CertSafari
    Databricks Certified Generative AI Engineer Associate· Lessons

    Domain 5 · Lesson 43/56

    Column masks and row filters as performance-aware guardrails

    Use masking techniques as guard rails to meet a performance objective

    9 min read
    2% of exam
    7 sources
    Published 22 Oct 2026
    Docs as of 17 Oct 2026

    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?

    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?

    Sources12

    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.

    Choosing the attachment style
    SituationBetter fit
    Same PII rule across many tables, schemas or catalogsABAC policy
    New tables should be covered automatically once taggedABAC policy
    Policy authors and data stewards (who tag) are separate rolesABAC policy
    One table with strict logic that doesn't generalizeTable-level filter or mask
    Small, stable set of tables managed by their ownersTable-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?

    Sources134

    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.

    Mask and filter UDF design for performance
    PreferAvoidWhy
    Simple CASE and boolean expressionsMulti-level nesting, mapping tables, expression subqueriesFewer expressions perform better
    SQL UDFsPython UDFsPython offers fewer optimization opportunities
    Lookup tables small enough to broadcast, partitioned to the access pattern (for example by username)Joins against large tablesLarge joins prevent broadcast hash joins and force nested loop joins
    Only target-table columns as inputsExternal API calls, per-row information_schema lookupsNetwork calls add latency and timeouts
    Deterministic, error-safe functions such as try_divideExpressions that can throw, such as ANSI divisionPossible errors block pushdown, because an error could reveal pre-mask values
    Masks on large text skipped or kept simpleHeavy regex on serialized documentsRegex 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.

    One deterministic VARIANT mask that covers many numeric column typessql
    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;

    Sources516

    Sources

    (7)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “Rows where the function returns FALSE are excluded from query results.”
      ↩︎ 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. 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. 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. 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. 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. 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

    Continue to part 2 of 2

    Where table masks stop: vector indexes, exempt pipelines and LLM requests

    Spotted a mistake, or was something unclear? Tell us.