AI_CLASSIFY

functiondeferredAI & ML

docs.snowflake.com ↗

String & binary functions

Classifies text, images, or documents into categories that you specify.

Syntax

supportedpartialnot supportednot scored

AI_CLASSIFY( <input> , <list_of_categories> [, <config_object> ] [, <return_error_details> ] )

Parameters

NameRequiredDescription
inputrequiredThe string, image, document, or prompt object that you’re classifying. For text classification, the input string is case sensitive. Results may vary based on capitalization.
list_of_categoriesrequiredAn array of categories with at least two unique values. The number of categories is restricted only by the token window, but in practice, exceeding twenty categories might reduce classification accuracy. Categories are case sensitive. Categories can be simple strings or SQL objects of the same type. If you’re using objects, you can provide a description for one or more categories to improve classification accuracy. For each category, specify the following: label (Required): The name of the category. description (Optional): Describes the category in no more than 25 words. Note Descriptions count as input tokens, which affects the cost of the classification operation. For more information, see Snowflake Cortex AI functions incur compute cost based on the number of tokens….
config_objectoptionalConfiguration settings specified as key/value pairs. Supported keys: task_description: An explanation of the classification task that is 50 words or fewer. This can help the model understand the context of the classification task and improve accuracy. output_mode: Set to 'multi' for multi-label classification. Defaults to 'single' for single-label classification. examples: A list of example objects for few-shot learning. Each example must include: input: Example text to classify. labels: List of correct categories for the input. explanation: Explanation of why the input maps to those categories. When the input is a document, output_mode must be 'single' and examples is not supported.
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

A serialized object. The object’s labels field is an array that specifies the list of categories to which the input belongs. For single label classification, the labels array has exactly one element. For multi-label classification, the labels field can have multiple elements.

Usage notes

Region availability

The following table shows the regions where you can use the AI_CLASSIFY function for each input type: 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 | ✔ | ✔ | ✔ | | | | | | ✔ DOCUMENT (Preview) | | | | | | | | | ✔

Error behavior

By default, if AI_CLASSIFY 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: An OBJECT containing the classification 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 the SNOWFLAKE.CORTEX_USER database role. For more information about this privilege, see Cortex LLM privileges.

Limitations

- Snowflake AI functions don’t work on FILE objects created from files in the following kinds of stages: 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 Note AI_CLASSIFY is the updated version of CLASSIFY_TEXT. For the latest functionality, use AI_CLASSIFY.

Legal notices

Refer to Snowflake AI and ML for legal notices.

Known gaps

Parts not fully supported, and recorded divergences from Snowflake.