AI_SENTIMENT

functiondeferredAI & ML

docs.snowflake.com ↗

String & binary functions

AI_SENTIMENT provides sentiment classification across diverse markets and languages. It uses a custom Snowflake large language model to return overall sentiment for a piece of text and, optionally, aspect-based (also called category-based or entity-based) sentiment for specific topics that you specify. Common use cases include: - Social media monitoring - Detailed product analysis - Comprehensive brand perception studies - Advanced market intelligence - Employee engagement analysis - Customer experience journey mapping - Content performance analysis - Customer support optimization

Syntax

supportedpartialnot supportednot scored

AI_SENTIMENT( <text> [ , <categories> ] [, <return_error_details> ] )

Parameters

NameRequiredDescription
textrequiredA string containing the text in which sentiment is detected.
categoriesoptionalAn array containing up to ten categories (also called entities or aspects) for which sentiment should be extracted. Each category is a string. For example, if extracting sentiment from a restaurant review, you might specify ['cost', 'quality', 'service', 'wait time'] as the categories. Each category may be a maximum of 30 characters long. If you do not provide this argument, AI_SENTIMENT returns only the overall sentiment.
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

An OBJECT value containing a categories field. categories is an array of category records. Each category includes these fields: - name: The name of the category. The category names match the categories specified in the categories argument. - sentiment: The sentiment of the category. Each sentiment result is one of the following strings. unknown: The category was not mentioned in the text. - positive: The category was mentioned positively in the text. - negative: The category was mentioned negatively in the text. - neutral: The category was mentioned in the text, but neither positively nor negatively. - mixed: The category was mentioned both positively and negatively in the text. The overall category record is always included and contains the overall sentiment of the text. Example:

Usage notes

Error behavior

By default, if AI_SENTIMENT 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 sentiment analysis 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 role.

Regional availability

AI_SENTIMENT is available in the following regions: Function (Model) | 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) AI_SENTIMENT | ✔ | ✔ | ✔ | | | ✔ | ✔ | ✔ | ✔ Note AI_SENTIMENT is the updated version of ENTITY_SENTIMENT. For the latest functionality, use AI_SENTIMENT.

Legal notices

Refer to Snowflake AI and ML.

Known gaps

Parts not fully supported, and recorded divergences from Snowflake.