Breyta

AI_ANALYZE_SENTIMENT (Transact-SQL)

Applies to: SQL analytics endpoint in Microsoft Fabric and Warehouse in Microsoft Fabric

The AI_ANALYZE_SENTIMENT function analyzes input text and returns one of these sentiment labels: positive, negative, mixed, or neutral.

Note

  • AI_ANALYZE_SENTIMENT is in preview.
  • AI_ANALYZE_SENTIMENT is available only in SQL analytics endpoint and Warehouse in Microsoft Fabric.

Syntax

Transact-SQL syntax conventions

AI_ANALYZE_SENTIMENT ( text )

Arguments

text

An expression of a character type, for example nvarchar, varchar, nchar, or char.

Return types

Returns nvarchar with one of the following values:

  • positive
  • negative
  • mixed
  • neutral

Remarks

AI functions return NULL if the AI model can't process the text. Common reasons include:

  • Responsible AI rules block inappropriate content in the input text.
  • Input text exceeds token limits. The current model supports up to 15 KB of text.

Examples

A. Analyze sentiment in a string

SELECT ai_analyze_sentiment('This hotel was great!') AS sentiment;

Expected result: positive

B. Analyze sentiment from a table column

SELECT review_id,
       ai_analyze_sentiment(review_text) AS sentiment
FROM dbo.hotel_reviews;