# `AI_SENTIMENT`

**Applies to:** ✅ Data 360 SQL ❌ Tableau Hyper API

Performs sentiment analysis on text input and returns a sentiment label. This function uses a multilingual sentiment model to analyze customer feedback, support tickets, survey responses, and other unstructured text.

## Syntax

```sql
ai_sentiment(<input_text>)
```

## Arguments

### Required

- `input_text`: The [text](/docs/data/data-cloud-query-guide/references/dc-sql-reference/string.md) to analyze for sentiment. The function processes empty input values normally. The text must be a non-NULL value.

## Returns

Returns a [text](/docs/data/data-cloud-query-guide/references/dc-sql-reference/string.md) sentiment label. Sentiment labels are:

- `Positive`: Text expressing positive sentiment
- `Negative`: Text expressing negative sentiment
- `Neutral`: Text expressing neutral sentiment
- `Mixed`: Text containing conflicting positive and negative signals
- `Unknown`: Text with unclear or indeterminate sentiment

## Considerations

- **Input text length**: The function supports input text up to 512 tokens (approximately 400-500 words). For longer text such as full call transcripts or lengthy emails, split the content into shorter passages before analyzing.
- **Best for short text**: This function works best on short, intent-rich text such as support tickets, CRM notes, social media posts, and chat messages.
- **Performance**: Requests to the function time out after 30 seconds.
- **First execution**: When executing this function on a large number of rows for the first time, you can encounter timeout or capacity errors. Start with smaller row counts and gradually increase volume to avoid these issues.
- **Non-NULL values**: `input_text` must be a non-NULL value. Add `IS NOT NULL` to the `WHERE` clause in your SQL statement to avoid `NULL` value errors.
- **Multilingual support**: The underlying model supports multiple languages.

## Examples

### Using Table Data

Analyzes sentiment for multiple rows from a table.

```sql
SELECT
  "customerServiceFeedback__c",
  ai_sentiment("customerServiceFeedback__c") AS sentiment
FROM "AutomobileServiceFeedback__dll"
```

Returns the sentiment of the feedback for each row in the `AutomobileServiceFeedback__dll`.

### Filtering Results

Show only positive feedback in a table.

```sql
WITH AnalyzedFeedback AS (
  SELECT
    "customerServiceFeedback__c",
    ai_sentiment("customerServiceFeedback__c") AS sentiment
  FROM "AutomobileServiceFeedback__dll"
)
SELECT * FROM AnalyzedFeedback
WHERE sentiment = 'positive';
```

Returns all positive feedback.

## Related Documentation

- [Sentiment Analysis](https://help.salesforce.com/s/articleView?id=data.c360\_a_ai_predictive_model_sentiment.htm\&type=5): Learn about sentiment analysis models, use cases, and integration options.
- [AI Models in Data Cloud](https://help.salesforce.com/s/articleView?id=data.c360\_a_ai_create_connect_activate_models.htm\&type=5): Read an overview of AI model capabilities.
