| title | AI_EXTRACT (Transact-SQL) | ||
|---|---|---|---|
| description | The AI_EXTRACT function extracts named values from text as JSON. | ||
| author | WilliamDAssafMSFT | ||
| ms.author | wiassaf | ||
| ms.reviewer | jovanpop | ||
| ms.date | 06/10/2026 | ||
| ms.service | sql | ||
| ms.subservice | t-sql | ||
| ms.topic | reference | ||
| ms.custom |
|
||
| f1_keywords |
|
||
| helpviewer_keywords |
|
||
| dev_langs |
|
||
| monikerRange | =fabric |
[!INCLUDE fabricsedw]
The AI_EXTRACT function extracts values from input text using the classes you provide, and returns the result as a JSON object.
Note
AI_EXTRACTis in preview.AI_EXTRACTis available only in [!INCLUDE fabric-se-short] and [!INCLUDE fabric-dw].
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions
AI_EXTRACT ( text, class1, class2 [ , ...n ] )
An expression of a character type, for example nvarchar, varchar, nchar, or char.
One or more property names to extract from the text.
Returns nvarchar(max) containing JSON text.
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.
SELECT ai_extract('Check-in was late and room dirty', 'sentiment', 'problem') AS extraction;Expected result: {"sentiment":"Negative","problem":"Dirty room"}
SELECT sentiment, time_reported, problem
FROM dbo.hotel_reviews
CROSS APPLY OPENJSON(
ai_extract(review_text, 'sentiment', 'time_reported', 'problem')
) WITH (
sentiment VARCHAR(1000),
time_reported VARCHAR(100),
problem VARCHAR(1000)
);