AI_FILTER

functiondeferredAI & ML

docs.snowflake.com ↗

String & binary functions

Classifies free-form prompt inputs into a boolean. Currently supports both text and image filtering.

Syntax

supportedpartialnot supportednot scored

Applying AI_FILTER to an input string

AI_FILTER( <input> [, <return_error_details> ] )

Applying AI_FILTER to single image

AI_FILTER( <predicate> , <input> [, <return_error_details> ] )

Applying AI_FILTER to multiple columns with both text and images, leveraging the PROMPT

AI_FILTER( PROMPT('<template_string>',  <col_1>, … ) [, <return_error_details> ] )

Parameters

NameRequiredDescription
inputrequiredA string containing the text to be classified.
predicaterequiredA string containing the instructions to classify the file input as either TRUE or FALSE.
filerequiredThe column that the file is classified by based on the instructions specified in predicate. You can use IMAGE FILE as an input to the AI_FILTER function.
return_error_detailsoptionalA BOOLEAN flag that indicates whether to return error details in case of error. When set to TRUE, the function returns an OBJECT that contains the value and the error message, one of which is NULL depending on whether the function succeeded or failed. See Error behavior for details.

Returns

Returns a Boolean value that indicates whether the statement evaluates to TRUE or FALSE for the specified text.

Usage notes

Region availability

The following table shows the regions where you can use the AI_FILTER function for both text and images: Data type | AWS US West 2 (Oregon) | AWS US East 1 (N. Virginia) | AWS Europe Central 1 (Frankfurt) | AWS Europe West 1 (Ireland) | AWS AP Southeast 2 (Sydney) | AWS AP Northeast 1 (Tokyo) | Azure East US 2 (Virginia) | Azure West Europe (Netherlands) | AWS (Cross-Region) TEXT | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ IMAGE | ✔ | ✔ | ✔ | | | | | | ✔

Error behavior

By default, if AI_FILTER can’t process the input, the function returns NULL. If the query processes multiple rows, rows with errors return NULL and don’t prevent the query from completing. The return value on error depends on the return_error_details argument. The following table shows the return value based on the return_error_details argument: return_error_details | Return value | Description FALSE Not passed | NULL | TRUE | OBJECT with value and error fields | value: A BOOLEAN value indicating the filter result, or NULL if an error occurred. error: A VARCHAR value that contains the error message if an error occurred, or NULL if the function succeeded. For more information about error handling for AI functions, see Snowflake Cortex AI Function: Multirow error handling improvements.

Access control requirements

Users must use a role that has been granted the SNOWFLAKE.CORTEX_USER database role. See Cortex LLM privileges for more information on this privilege.

Performance and cost optimization

By default, AI_FILTER includes a built-in performance optimization on qualifying queries. This optimization can provide 2 to 10 times faster performance and up to 60% lower token usage with a minimal impact on quality. This optimization is triggered automatically when the query engine detects a suitable pattern. Similar to other query optimizations, Snowflake doesn’t guarantee that this optimization will be applied for every query. The engine leverages adaptive routing and context-aware rewriting to execute more efficient AI operations where possible. To disable this optimization for your account, contact your account manager.

Limitations

- Snowflake AI functions don’t work on FILEs created from stage files from the following stage types: Internal stages with encryption mode TYPE = 'SNOWFLAKE_FULL' - External stages with any customer-side encrypted mode: TYPE = 'AWS_CSE' - TYPE = 'AZURE_CSE' - User stage, table stage - Stage with double-quoted names

Legal notices

Refer to Snowflake AI and ML for legal notices.

Known gaps

Parts not fully supported, and recorded divergences from Snowflake.