Feature policy rules

A feature policy can carry a YAML body with rules that block a statement only when a condition you define is true. These rules let you allow users to create or change objects of a type in general but block specific uses, such as a particular creation option or a property value you don’t permit.

For example, a feature policy can:

  • Block temporary or transient tables.
  • Restrict object creation to a specific schema.
  • Require request logging on Cortex Search Services, both when a service is created and whenever it’s altered.
  • Block an ALTER that changes a task’s warehouse.

To block every creation of an object type, regardless of the statement, list the type in BLOCKED_OBJECT_TYPES_FOR_CREATION instead. See Blockable object types.

Creation rules and creation and alteration rules

A policy body can contain two lists of rules. Both use the same rule properties, conditions, and blocking expressions:

  • blocked_creation_rules: Creation rules. They apply only to statements that create an object: CREATE and CREATE OR ALTER.
  • blocked_creation_alteration_rules: Creation and alteration rules. They apply to CREATE, CREATE OR ALTER, and standalone ALTER statements.

Creation rules are the simpler choice for properties that can’t change after an object is created, such as whether a table is temporary or transient. An ALTER can’t change these properties, so checking them when the object is created is enough. On CREATE, every property has a value, including the default for a property that the statement omits, so an expression such as $IS_TEMPORARY always evaluates to TRUE or FALSE and needs no extra handling.

A creation rule can test any supported property, including one that an ALTER can change later. In that case, the rule doesn’t prevent a later standalone ALTER from changing the property, even to a value that the rule blocks at creation. For example, a creation rule that requires REQUEST_LOGGING = TRUE on a Cortex Search Service doesn’t stop a user from later running ALTER CORTEX SEARCH SERVICE ... SET REQUEST_LOGGING = FALSE.

Use creation and alteration rules when a requirement on a property that an ALTER can change must hold for the life of the object, not only when it’s created. A creation and alteration rule for REQUEST_LOGGING blocks both of the statements in the previous example. Because an ALTER reports only the properties that it sets, expressions in these rules must handle properties that are missing. See Properties on ALTER and Safely handling missing properties.

Policy body syntax

The body is a YAML document attached to the policy with an AS clause:

CREATE FEATURE POLICY <name>
  [ BLOCKED_OBJECT_TYPES_FOR_CREATION = ( <type> [ , ... ] ) ]
  [ COMMENT = '<string-literal>' ]
  [ AS $$
      <yaml-body>
    $$ ]

The YAML body has the following structure:

conditions:
  - name: <condition-name>
    expression: "<sql-expression>"

blocked_creation_rules:
  - object_type: <OBJECT_TYPE>
    block_when: "<sql-expression>"
    # or, referencing one or more named conditions:
    block_when_any:
      - <condition-name>
    error_message: "<text>"   # optional

blocked_creation_alteration_rules:
  - object_type: <OBJECT_TYPE>
    block_when: "<sql-expression>"
    # or block_when_any, as above
    error_message: "<text>"   # optional

The policy body supports the following top-level keys:

  • conditions: Optional. A list of named, reusable expressions that rules reference through block_when_any. See Condition properties.
  • blocked_creation_rules: Optional. A list of rules that block matching CREATE and CREATE OR ALTER statements. See Rule properties.
  • blocked_creation_alteration_rules: Optional. A list of rules that block matching CREATE, CREATE OR ALTER, and standalone ALTER statements. See Rule properties.

Condition properties

The conditions list is optional. Each condition gives a name to a SQL Boolean expression, so you can define the expression once and reuse it across multiple rules instead of repeating it in each rule’s block_when. A rule references conditions by name in its block_when_any list. Rules in both blocked_creation_rules and blocked_creation_alteration_rules can reference the same conditions.

Each entry in conditions supports these properties:

  • name: Required. The name that rules use to reference the condition in block_when_any. Must be unique within conditions.
  • expression: Required. A SQL Boolean expression. See Blocking expressions. If a rule in blocked_creation_alteration_rules references the condition, the expression must evaluate to TRUE or FALSE on both CREATE and ALTER. See Validation rules.

Rule properties

Each entry in blocked_creation_rules and blocked_creation_alteration_rules supports these properties:

  • object_type: Required. The object type that the rule applies to, such as TABLE, TASK, or CORTEX_SEARCH_SERVICE, or the ALL wildcard. Snowflake rejects an unsupported type when the policy is created or altered. See Supported object types.
  • block_when: Optional. A SQL Boolean expression. The rule blocks the statement when the expression evaluates to TRUE. Can’t be an empty string.
  • block_when_any: Optional. A list of condition names. The rule blocks the statement when any of the named conditions evaluates to TRUE. Must contain at least one name, and each name must match an entry in conditions.
  • error_message: Optional. Text that Snowflake appends to the error for a blocked statement. See Custom error messages.

A rule can specify block_when or block_when_any, but not both. If a rule specifies neither, it blocks every statement of its object_type that the list applies to: every CREATE for blocked_creation_rules, and every CREATE and ALTER for blocked_creation_alteration_rules. An ALL rule must specify one of them.

An ALL rule applies to every supported object type, not to every object type in Snowflake. For the list of supported types, see Supported object types. The expression in an ALL rule can use only the following properties:

  • TYPE
  • REQUEST_OPERATION
  • IS_TEMPORARY
  • IS_TRANSIENT
  • DATABASE
  • SCHEMA

To use a property that applies only to specific object types, such as WAREHOUSE on TASK, write a rule for that object type instead.

Attention

A property used in an ALL rule can be NULL for some of the object types that the rule applies to. A comparison against NULL evaluates to NULL, and a rule whose expression evaluates to NULL blocks the statement. To avoid blocking statements unintentionally, check for NULL before comparing a property’s value. See Using NULL checks.

Supported object types

A rule’s object_type can name any of the following types, in either singular or plural form (for example, both TABLE and TABLES are accepted):

CategoryObject types
Account-levelCOMPUTE_POOL, DATABASE, WAREHOUSE
Database-levelSCHEMA
Schema-levelAPPLICATION_SERVICE, ARTIFACT_REPOSITORY, AGENT, CORTEX_SEARCH_SERVICE, DYNAMIC_TABLE, FILE_FORMAT, FUNCTION, GIT_REPOSITORY, ICEBERG_TABLE, MATERIALIZED_VIEW, MCP_SERVER, PROCEDURE, RESTRICTED_SESSION_SCOPE, SECRET, STAGE, TABLE, TASK, VIEW, WORKSPACE

Attention

Account-level types are evaluated only when a native app creates the object and the policy applies to the application’s database. They have no effect for objects that users create directly.

Each of these types has at least one object property that a blocking expression can test. For the properties that apply to each type, see Object properties. The ALL wildcard covers every supported type.

To block every creation of other object types, list them in BLOCKED_OBJECT_TYPES_FOR_CREATION. See Blockable object types.

Blocking expressions

This section applies to both a rule’s block_when expression and a condition’s expression. Each is a SQL Boolean expression written as a quoted string. Snowflake validates the expression when the policy is created or altered. An expression in blocked_creation_alteration_rules is validated once for a CREATE and once for an ALTER.

Object properties

A blocking expression can refer to properties of the object that the statement creates or changes, such as the values that the statement sets. It can also refer to properties of the operation’s context, such as the type of statement. Refer to a property in either of the following ways:

  • $<PROPERTY>: Resolves the property directly. The variable has the same type as the property. For example, $IS_TRANSIENT is a Boolean, so use it directly or compare it with an unquoted TRUE or FALSE (for example, $IS_TRANSIENT or NOT $IS_TRANSIENT). $SCHEMA is a string, so compare it with a string literal (for example, $SCHEMA = 'STAGING'). Using an unrecognized name, or a property that doesn’t apply to the rule’s object_type, is a compilation error when the policy is created or altered.
  • SYS_CONTEXT('SNOWFLAKE$REQUEST', 'GET_OBJECT_PROPERTY', '<property>'): The full form. Always returns a string, so Boolean comparisons require = 'TRUE'. A property that doesn’t apply to the rule’s object_type returns NULL at runtime instead of causing an error when the policy is created.

For example, the following two rules are equivalent:

blocked_creation_rules:
  - object_type: TABLE
    block_when: "$IS_TEMPORARY"
    error_message: "Temporary tables aren't allowed. Create a permanent table."
  - object_type: TABLE
    block_when: "SYS_CONTEXT('SNOWFLAKE$REQUEST', 'GET_OBJECT_PROPERTY', 'IS_TEMPORARY') = 'TRUE'"
    error_message: "Temporary tables aren't allowed. Create a permanent table."

The following properties describe the context of the operation: what kind of statement it is and what type of object it acts on. They apply to every object type, and are populated on both CREATE and ALTER:

PropertyTypeReturns
REQUEST_OPERATIONStringThe kind of statement being evaluated: CREATE for CREATE and CREATE OR ALTER, and ALTER for a standalone ALTER. Always CREATE in blocked_creation_rules.
TYPEStringThe type of the object being created or altered, using the same name as a rule’s object_type, for example TABLE, AGENT, or TASK. Useful in ALL rules and in shared conditions.

The following properties describe attributes of the object itself. Each one is available only for the listed object types. The notes describe the values on CREATE. For values on ALTER, see Properties on ALTER.

PropertyTypeObject typesNotes
IS_TEMPORARYBooleanEvery supported typeTRUE for CREATE TEMPORARY ... of TABLE, VIEW, STAGE, FILE_FORMAT, FUNCTION, PROCEDURE, SECRET, or AGENT. FALSE otherwise.
IS_TRANSIENTBooleanEvery supported typeTRUE for CREATE TRANSIENT ... of TABLE, ICEBERG_TABLE, DYNAMIC_TABLE, SCHEMA, or DATABASE. FALSE otherwise.
REQUEST_LOGGINGBooleanCORTEX_SEARCH_SERVICEFALSE when the statement omits the property.
WAREHOUSEStringTASKNULL for a serverless task.
EXTERNAL_VOLUMEStringICEBERG_TABLEThe external volume resolved for the request, which can come from the table, schema, database, or account level. NULL if none.
DATABASEStringEvery supported type except DATABASEThe name of the database that contains the object.
SCHEMAStringEvery supported schema-level typeThe name of the schema that contains the object.

IS_TEMPORARY and IS_TRANSIENT are FALSE for object types that don’t support that creation option, so a single rule applied across mixed object types behaves predictably. For example, $IS_TRANSIENT is FALSE for STAGE. For the other properties, using the $<PROPERTY> form in a rule for an object type that isn’t listed causes an error when the policy is created or altered. For example, $WAREHOUSE in a TABLE rule and $SCHEMA in a DATABASE or SCHEMA rule are both rejected. The SYS_CONTEXT('SNOWFLAKE$REQUEST', 'GET_OBJECT_PROPERTY', '<property>') form returns NULL for those object types instead.

Properties on CREATE and CREATE OR ALTER

A blocking expression can read the properties that the statement explicitly sets. It can also read properties that the statement doesn’t set but that have a default or a resolved value for the object type. Those properties report that value.

  • Boolean properties are always present. If the statement omits one, the value is that property’s default. IS_OBJECT_PROPERTY_PRESENT returns TRUE.
  • Other properties that have a default or a resolved value for the object type, such as EXTERNAL_VOLUME on ICEBERG_TABLE, are present at that value when the statement omits them. IS_OBJECT_PROPERTY_PRESENT returns TRUE.
  • Properties without a default are NULL when the statement omits them or sets them to NULL. IS_OBJECT_PROPERTY_PRESENT returns TRUE only when the statement supplies a value.
  • The context properties (REQUEST_OPERATION and TYPE) are always present, and DATABASE and SCHEMA are always present when they apply to the object type.

Properties on ALTER

Rules in blocked_creation_alteration_rules are also evaluated for a standalone ALTER. On an ALTER, a blocking expression can read only the object properties that the statement sets or unsets, plus the context properties, DATABASE, and SCHEMA. Object properties that the statement doesn’t mention don’t report a default or a resolved value.

  • Object properties such as IS_TEMPORARY, REQUEST_LOGGING, and WAREHOUSE are present only when the statement sets or unsets them. That includes Boolean properties. An omitted Boolean is absent: reading it returns NULL, and IS_OBJECT_PROPERTY_PRESENT returns FALSE.
  • TYPE and REQUEST_OPERATION are populated on every ALTER. DATABASE and SCHEMA are populated when the object type has that container, and are NULL otherwise, the same as on CREATE.

Safely handling missing properties

A string property can be NULL, for example WAREHOUSE on a serverless task. A comparison against NULL is itself NULL, and a rule whose expression evaluates to NULL blocks the statement. For example, $WAREHOUSE NOT IN ('CORP_M', 'CORP_XL') is NULL for a serverless task, so the rule blocks every serverless task, even if you intended to allow them.

Missing properties are more common in blocked_creation_alteration_rules, because an ALTER reports only the properties it mentions. For example, NOT $REQUEST_LOGGING is NULL for an ALTER CORTEX SEARCH SERVICE that doesn’t set REQUEST_LOGGING. Snowflake rejects an alteration rule like this when you create or alter the policy. See Validation rules.

To write a rule that behaves predictably for every statement, use one of the following approaches instead of comparing the property directly.

Using NULL checks

Test whether a property is NULL before comparing its value. A property is NULL when it has no value, when a statement explicitly sets or unsets it to NULL, and when an ALTER doesn’t mention it. An IS NOT NULL check makes the expression FALSE instead of NULL in those cases.

The following rule requires that a task’s warehouse, when set, is CORP_M or CORP_XL. A task without a warehouse is allowed:

blocked_creation_rules:
  - object_type: TASK
    block_when: "$WAREHOUSE IS NOT NULL AND $WAREHOUSE NOT IN ('CORP_M', 'CORP_XL')"
    error_message: "Tasks must use the CORP_M or CORP_XL warehouse, or run as serverless tasks."

The rule handles each statement as follows:

  • CREATE TASK with WAREHOUSE = CORP_M or WAREHOUSE = CORP_XL: allowed.
  • CREATE TASK with a different warehouse: blocked.
  • CREATE TASK with no warehouse (a serverless task): allowed.

The same expression works in blocked_creation_alteration_rules, where it also covers changes to existing tasks:

blocked_creation_alteration_rules:
  - object_type: TASK
    block_when: "$WAREHOUSE IS NOT NULL AND $WAREHOUSE NOT IN ('CORP_M', 'CORP_XL')"
    error_message: "Tasks must use the CORP_M or CORP_XL warehouse, or run as serverless tasks."

In addition to the CREATE TASK cases in the previous example, the rule handles ALTER as follows:

  • ALTER TASK ... SET WAREHOUSE = CORP_M or CORP_XL: allowed.
  • ALTER TASK ... SET WAREHOUSE to a different warehouse: blocked.
  • ALTER TASK ... UNSET WAREHOUSE: allowed.
  • ALTER TASK that doesn’t mention WAREHOUSE: allowed.

Without the IS NOT NULL check, the NOT IN comparison would be NULL for an ALTER that doesn’t mention WAREHOUSE, and Snowflake would reject the alteration rule when you create the policy.

Using IS_OBJECT_PROPERTY_SET_TO

Use IS_OBJECT_PROPERTY_SET_TO to require that a property has a specific value whenever a statement supplies it. The function returns TRUE when the statement sets the property to the value, or when the statement doesn’t supply the property at all. The value is compared case-insensitively, and an explicit NULL doesn’t match any value. An omitted Boolean is present at its default, so the function compares that default. The function returns NULL for an unrecognized property name.

The following rule requires that a task that names a warehouse uses CORP_M:

blocked_creation_rules:
  - object_type: TASK
    block_when: "NOT SYS_CONTEXT('SNOWFLAKE$REQUEST', 'IS_OBJECT_PROPERTY_SET_TO', 'WAREHOUSE', 'CORP_M')"
    error_message: "Tasks must use the CORP_M warehouse, or run as serverless tasks."

The rule handles each statement as follows:

  • CREATE TASK with WAREHOUSE = CORP_M: allowed.
  • CREATE TASK with a different warehouse: blocked.
  • CREATE TASK with no warehouse (a serverless task): allowed.

Because the function returns TRUE when the statement doesn’t mention the property, it’s well suited to blocked_creation_alteration_rules: it allows an ALTER that leaves the property alone. The following rule requires request logging on Cortex Search Services, both at creation and on every later change:

blocked_creation_alteration_rules:
  - object_type: CORTEX_SEARCH_SERVICE
    block_when: "NOT SYS_CONTEXT('SNOWFLAKE$REQUEST', 'IS_OBJECT_PROPERTY_SET_TO', 'REQUEST_LOGGING', 'TRUE')"
    error_message: "Cortex Search Services must have request logging enabled. Set REQUEST_LOGGING = TRUE."

The rule handles each statement as follows:

  • CREATE or CREATE OR ALTER with REQUEST_LOGGING = TRUE: allowed.
  • CREATE or CREATE OR ALTER that omits REQUEST_LOGGING: blocked. The omitted Boolean is present at its default, FALSE.
  • ALTER ... SET REQUEST_LOGGING = TRUE: allowed.
  • ALTER ... SET REQUEST_LOGGING = FALSE: blocked.
  • ALTER that doesn’t mention REQUEST_LOGGING: allowed.

Using IS_OBJECT_PROPERTY_PRESENT

Use IS_OBJECT_PROPERTY_PRESENT to block a statement based on whether a property is present, regardless of its value. The function returns TRUE when the property is present and FALSE when it isn’t. For the properties that count as present, see Properties on CREATE and CREATE OR ALTER and Properties on ALTER. The function returns NULL for an unrecognized property name.

The following rule allows only serverless tasks:

blocked_creation_rules:
  - object_type: TASK
    block_when: "SYS_CONTEXT('SNOWFLAKE$REQUEST', 'IS_OBJECT_PROPERTY_PRESENT', 'WAREHOUSE')"
    error_message: "Only serverless tasks are allowed. Create the task without a WAREHOUSE."

The rule handles each statement as follows:

  • CREATE TASK with any WAREHOUSE: blocked.
  • CREATE TASK with no warehouse (a serverless task): allowed.

On an ALTER, a property is present when the statement sets or unsets it. The following rule blocks any ALTER that changes a task’s warehouse:

blocked_creation_alteration_rules:
  - object_type: TASK
    block_when: >
      $REQUEST_OPERATION = 'ALTER'
      AND SYS_CONTEXT('SNOWFLAKE$REQUEST', 'IS_OBJECT_PROPERTY_PRESENT', 'WAREHOUSE')
    error_message: "A task's warehouse can't be changed after the task is created."

The rule handles each statement as follows:

  • CREATE TASK or CREATE OR ALTER TASK, with or without WAREHOUSE: allowed, because REQUEST_OPERATION is CREATE.
  • ALTER TASK ... SET WAREHOUSE = <name>: blocked.
  • ALTER TASK ... UNSET WAREHOUSE: blocked.
  • ALTER TASK that doesn’t mention WAREHOUSE: allowed.

The REQUEST_OPERATION check limits the rule to ALTER. Without it, a CREATE TASK that sets WAREHOUSE would also be blocked, because the property is present on that statement.

Each of these expressions evaluates to TRUE or FALSE for every statement, so a missing property never causes the rule to block the statement.

Validation rules

Snowflake rejects the following expressions when the policy is created or altered:

  • Expressions that don’t evaluate to TRUE or FALSE, such as a numeric or string literal. In blocked_creation_alteration_rules, this includes an expression that’s NULL on an ALTER because the statement doesn’t mention a property that the expression uses.
  • Expressions that reference tables or other database objects (for example, (SELECT COUNT(*) FROM t) > 0).
  • Expressions that call a user-defined function (UDF) or user-defined table function (UDTF). Only built-in functions are allowed.
  • Expressions that call functions with side effects (for example, SYSTEM$RUN_QUERY_SYNC).
  • Expressions that call functions that must run in a warehouse.
  • Expressions that call a function that doesn’t exist.
  • Expressions that use $<NAME> where <NAME> isn’t a recognized object property, or where the property doesn’t apply to the rule’s object_type (for example, $WAREHOUSE in a TABLE rule).

Attention

An expression that compares a property can evaluate to NULL at runtime, and a rule whose expression evaluates to NULL blocks the statement. Validation doesn’t catch the following cases:

  • The property has no value for the statement, for example WAREHOUSE on a serverless task.
  • The expression uses SYS_CONTEXT to read a property that doesn’t apply to the rule’s object_type, or a misspelled property name.
  • The statement explicitly sets the property to NULL. This applies to both rule lists.

To avoid these failures, check for NULL before comparing a property’s value. See Using NULL checks.

How statements are evaluated

Snowflake evaluates the rules that apply to the statement:

  • A CREATE or CREATE OR ALTER is checked against blocked_creation_rules and blocked_creation_alteration_rules. Property values follow Properties on CREATE and CREATE OR ALTER, including defaults.
  • A standalone ALTER is checked against blocked_creation_alteration_rules only. Property values follow Properties on ALTER. A blocked_creation_rules entry never blocks an ALTER.

Snowflake evaluates CREATE OR ALTER as a creation, even when the object already exists. The statement uses creation property values, and REQUEST_OPERATION is CREATE.

Custom error messages

When a rule blocks the statement, the statement is denied. By default, the error names the object type and points to the effective feature policy, for example:

Create TABLE denied due to feature policy restriction for the account. Consult your internal policy administrator to review the effective feature policy by running 'SHOW FEATURE POLICIES ON ACCOUNT'.

Add an error_message to a rule to tell the user why the statement was blocked and what to do instead:

CREATE FEATURE POLICY require_permanent_tables
  AS $$
    blocked_creation_rules:
      - object_type: TABLE
        block_when: "$IS_TEMPORARY OR $IS_TRANSIENT"
        error_message: "Temporary and transient tables aren't allowed. Create a permanent table."
  $$;

When this policy is applied to all databases, a CREATE TRANSIENT TABLE statement fails with an error that includes the rule’s text after Your policy::

Create TABLE denied due to feature policy restriction for the account. Your policy: Temporary and transient tables aren't allowed. Create a permanent table. Consult your internal policy administrator to review the effective feature policy by running 'SHOW FEATURE POLICIES ON ACCOUNT'.

The following rules apply to error_message:

  • The value is trimmed of leading and trailing whitespace. The trimmed text must be 1 to 512 characters long.
  • The value must be a single line. Newlines, tabs, and other control characters aren’t allowed.
  • The sequence ${, followed later by }, is reserved and isn’t allowed.
  • Snowflake validates the value when the policy is created or altered. An invalid value causes the statement to fail.

Snowflake shows the message from the first rule in the list that blocks the statement. If a statement is blocked because its object type is listed in BLOCKED_OBJECT_TYPES_FOR_CREATION, Snowflake shows the generic error without any rule’s error_message, even if a rule for the same object type also matches. If both blocked_creation_rules and blocked_creation_alteration_rules block a CREATE, Snowflake shows the message from the matching blocked_creation_rules entry.

When an alteration rule blocks a standalone ALTER, the error starts with Alter instead of Create. For example, the rule in Using IS_OBJECT_PROPERTY_PRESENT produces the following error for ALTER TASK ... SET WAREHOUSE:

Alter TASK denied due to feature policy restriction for the account. Your policy: A task's warehouse can't be changed after the task is created. Consult your internal policy administrator to review the effective feature policy by running 'SHOW FEATURE POLICIES ON ACCOUNT'.

Examples

The following examples assume the feature policy is attached to all databases, an application, or a specific database after creation. For attachment syntax, see Apply a feature policy.

Each example includes an error_message. Snowflake recommends adding one to every rule so that users who are blocked understand why and know what to do instead. For more information, see Custom error messages.

Block all temporary tables

CREATE FEATURE POLICY block_temp_tables
  AS $$
    blocked_creation_rules:
      - object_type: TABLE
        block_when: "$IS_TEMPORARY"
        error_message: "Temporary tables aren't allowed. Create a permanent or transient table."
  $$;

Block all transient tables

Transient tables don’t carry the same Time Travel and Fail-safe protections as permanent tables. A policy that requires only permanent tables can block CREATE TRANSIENT TABLE statements:

CREATE FEATURE POLICY block_transient_tables
  AS $$
    blocked_creation_rules:
      - object_type: TABLE
        block_when: "$IS_TRANSIENT"
        error_message: "Transient tables aren't allowed. Create a permanent table."
  $$;

To block both temporary and transient tables in one rule, see the example in Custom error messages.

Block transient and temporary objects across multiple object types

A single named condition can be reused across object types, including object types that don’t support TRANSIENT (such as STAGE, VIEW, FUNCTION, PROCEDURE). For those types, $IS_TRANSIENT is FALSE, so the rule fires only on temporary creations:

CREATE FEATURE POLICY block_transient_and_temp_objects
  AS $$
    conditions:
      - name: is_transient
        expression: "$IS_TRANSIENT"
      - name: is_temporary
        expression: "$IS_TEMPORARY"
    blocked_creation_rules:
      - object_type: TABLE
        block_when_any: [is_transient, is_temporary]
        error_message: "Temporary and transient tables aren't allowed. Create a permanent table."
      - object_type: DYNAMIC_TABLE
        block_when_any: [is_transient, is_temporary]
        error_message: "Transient dynamic tables aren't allowed. Create a permanent dynamic table."
      - object_type: ICEBERG_TABLE
        block_when_any: [is_transient, is_temporary]
        error_message: "Transient Iceberg tables aren't allowed. Create a permanent Iceberg table."
      - object_type: STAGE
        block_when_any: [is_transient, is_temporary]
        error_message: "Temporary stages aren't allowed. Create a permanent stage."
      - object_type: VIEW
        block_when_any: [is_transient, is_temporary]
        error_message: "Temporary views aren't allowed. Create a permanent view."
      - object_type: FUNCTION
        block_when_any: [is_transient, is_temporary]
        error_message: "Temporary functions aren't allowed. Create a permanent function."
      - object_type: PROCEDURE
        block_when_any: [is_transient, is_temporary]
        error_message: "Temporary procedures aren't allowed. Create a permanent procedure."
  $$;

Block serverless tasks

Serverless tasks are tasks created without a WAREHOUSE. The following policy permits warehouse-attached tasks but blocks serverless ones:

CREATE FEATURE POLICY block_serverless_tasks
  AS $$
    blocked_creation_rules:
      - object_type: TASK
        block_when: "$WAREHOUSE IS NULL"
        error_message: "Serverless tasks aren't allowed. Specify a WAREHOUSE when you create the task."
  $$;

Require request logging for Cortex Search Services

The following policy blocks creating a Cortex Search Service unless the statement sets REQUEST_LOGGING = TRUE. Because REQUEST_LOGGING defaults to FALSE, a statement that omits the property is also blocked. For more information about request logging, see Enable request logging.

CREATE FEATURE POLICY require_search_request_logging
  AS $$
    blocked_creation_rules:
      - object_type: CORTEX_SEARCH_SERVICE
        block_when: "NOT $REQUEST_LOGGING"
        error_message: "Create Cortex Search Services with REQUEST_LOGGING = TRUE."
  $$;

This rule applies only when a service is created. It doesn’t block an ALTER CORTEX SEARCH SERVICE statement that later disables request logging. To also block that change, use blocked_creation_alteration_rules. See Using IS_OBJECT_PROPERTY_SET_TO.

Block a property across every object type with ALL

Use the ALL wildcard to apply one rule to every supported object type without listing each one. Because Boolean properties such as $IS_TEMPORARY are FALSE for object types that can’t be temporary, the following policy blocks every temporary creation across all types and permits everything else:

CREATE FEATURE POLICY block_temp_everywhere
  AS $$
    blocked_creation_rules:
      - object_type: ALL
        block_when: "$IS_TEMPORARY"
        error_message: "Temporary objects aren't allowed. Create a permanent object."
  $$;

To exempt specific types from an ALL rule, test $TYPE. The following policy blocks every temporary creation except temporary tables:

CREATE FEATURE POLICY block_temp_except_tables
  AS $$
    blocked_creation_rules:
      - object_type: ALL
        block_when: "$IS_TEMPORARY AND $TYPE <> 'TABLE'"
        error_message: "Only temporary tables are allowed. Create other objects as permanent objects."
  $$;

Restrict object creation to a specific schema

Use the $SCHEMA variable to block creations outside an approved schema. A schema-level object such as a table always carries a SCHEMA value, so the comparison never evaluates to NULL:

CREATE FEATURE POLICY tables_only_in_staging
  AS $$
    blocked_creation_rules:
      - object_type: TABLE
        block_when: "$SCHEMA <> 'STAGING'"
        error_message: "Tables can be created only in the STAGING schema."
  $$;

The $SCHEMA variable returns the schema name as stored in the catalog (uppercase unless the schema was created with a quoted, case-sensitive identifier). The companion $DATABASE variable restricts by containing database in the same way.

Block creation based on user or session properties

A block_when expression can use session context functions such as CURRENT_USER and IS_ROLE_IN_SESSION. The following policy lets only specific users or roles create application services:

CREATE FEATURE POLICY restrict_app_service_creators
  AS $$
    blocked_creation_rules:
      - object_type: APPLICATION_SERVICE
        block_when: "NOT (CURRENT_USER() = 'APPMGR' OR IS_ROLE_IN_SESSION('APP_CREATOR'))"
        error_message: "Only APPMGR or users with the APP_CREATOR role can create application services."
  $$;

With this policy in place:

  • The user APPMGR can create application services.
  • Any user with the APP_CREATOR role active in the session, as a primary or secondary role, can create application services.
  • Any other user is blocked.

A creation rule is enough here because an ALTER statement doesn’t change who created the service.

Block every table

Omit block_when to block every creation of an object type, regardless of request attributes:

CREATE FEATURE POLICY block_all_tables
  AS $$
    blocked_creation_rules:
      - object_type: TABLE
        error_message: "Creating tables isn't allowed here. Contact your administrator to request a table."
  $$;

Unlike listing TABLE in BLOCKED_OBJECT_TYPES_FOR_CREATION, this rule shows its error_message when it blocks a statement.

Reuse a condition across rules

CREATE FEATURE POLICY block_temp_objects
  AS $$
    conditions:
      - name: is_temp
        expression: "$IS_TEMPORARY"
    blocked_creation_rules:
      - object_type: TABLE
        block_when_any:
          - is_temp
        error_message: "Temporary tables aren't allowed. Create a permanent table."
      - object_type: VIEW
        block_when_any:
          - is_temp
        error_message: "Temporary views aren't allowed. Create a permanent view."
  $$;

Combine type-level blocks and rules

BLOCKED_OBJECT_TYPES_FOR_CREATION and blocked_creation_rules can be used together in a single policy. Listing an object type in BLOCKED_OBJECT_TYPES_FOR_CREATION blocks every creation of that type regardless of any rule. Rules covering different object types are evaluated independently. The following policy blocks every warehouse creation and also blocks temporary tables:

CREATE FEATURE POLICY combined_policy
  BLOCKED_OBJECT_TYPES_FOR_CREATION = (WAREHOUSES)
  AS $$
    blocked_creation_rules:
      - object_type: TABLE
        block_when: "$IS_TEMPORARY"
        error_message: "Temporary tables aren't allowed. Create a permanent table."
  $$;

Block every ALTER of a task

REQUEST_OPERATION is ALTER only for a standalone ALTER. The following policy blocks ALTER TASK and still allows CREATE TASK and CREATE OR ALTER TASK:

CREATE FEATURE POLICY block_task_alters
  AS $$
    blocked_creation_alteration_rules:
      - object_type: TASK
        block_when: "$REQUEST_OPERATION = 'ALTER'"
        error_message: "Tasks can't be altered. Contact your administrator to change a task."
  $$;

Block every CREATE and ALTER of one type

Omit block_when from an alteration rule to block every CREATE and every ALTER of that type:

CREATE FEATURE POLICY block_all_table_ddl
  AS $$
    blocked_creation_alteration_rules:
      - object_type: TABLE
        error_message: "Creating and altering tables isn't allowed here. Contact your administrator to request a table."
  $$;

Block ALTER statements across every object type with ALL

REQUEST_OPERATION applies to every object type, so an ALL rule can use it. The following policy blocks standalone ALTER statements for every supported type and still allows CREATE:

CREATE FEATURE POLICY block_all_alters
  AS $$
    blocked_creation_alteration_rules:
      - object_type: ALL
        block_when: "$REQUEST_OPERATION = 'ALTER'"
        error_message: "Objects can't be altered in this account. Contact your administrator to request a change."
  $$;

Combine creation rules and alteration rules

blocked_creation_rules and blocked_creation_alteration_rules can appear in the same body, and their rules can share conditions. The following policy blocks temporary tables at creation time and blocks every alter of a task:

CREATE FEATURE POLICY create_and_alter_policy
  AS $$
    conditions:
      - name: is_alter
        expression: "$REQUEST_OPERATION = 'ALTER'"
    blocked_creation_rules:
      - object_type: TABLE
        block_when: "$IS_TEMPORARY"
        error_message: "Temporary tables aren't allowed. Create a permanent table."
    blocked_creation_alteration_rules:
      - object_type: TASK
        block_when_any:
          - is_alter
        error_message: "Tasks can't be altered. Contact your administrator to change a task."
  $$;

A condition written for creation defaults can’t be referenced from an alteration rule. For example, a condition with the expression $IS_TEMPORARY = FALSE is NULL on an ALTER that doesn’t set the property, so Snowflake rejects a policy that names it in blocked_creation_alteration_rules.

Modify or remove a policy body

Use ALTER FEATURE POLICY to set, replace, or clear the body of an existing policy.

To replace the body, use the AS clause, with or without other SET clauses:

ALTER FEATURE POLICY my_policy AS $$
  blocked_creation_rules:
    - object_type: TABLE
      block_when: "true"
$$;

ALTER FEATURE POLICY my_policy SET COMMENT = 'updated' AS $$
  blocked_creation_rules:
    - object_type: TABLE
      block_when: "true"
$$;

To remove the body but keep any BLOCKED_OBJECT_TYPES_FOR_CREATION clause:

ALTER FEATURE POLICY my_policy UNSET POLICY_DEFINITION;

To inspect the current body, use DESCRIBE FEATURE POLICY. The body appears as the policy_definition property in the result.

Apply a policy with rules

Rules are enforced through the same attachments as the rest of the feature policy: all native apps, a specific application, all databases, a specific database, or all personal databases. The effective policy for a statement is resolved from the object’s containing database, falling back to the policy attached to all databases. For attachment syntax and precedence, see Apply a feature policy and Feature policy precedence.