Skip to content

Latest commit

 

History

History
93 lines (70 loc) · 2.78 KB

File metadata and controls

93 lines (70 loc) · 2.78 KB
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
sql-ai
f1_keywords
ai_extract_TSQL
ai_extract
helpviewer_keywords
ai_extract
dev_langs
TSQL
monikerRange =fabric

AI_EXTRACT (Transact-SQL)

[!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

Syntax

:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions

AI_EXTRACT ( text, class1, class2 [ , ...n ] )

Arguments

text

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

class1, class2, ...n

One or more property names to extract from the text.

Return types

Returns nvarchar(max) containing JSON text.

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. Extract properties from a sentence

SELECT ai_extract('Check-in was late and room dirty', 'sentiment', 'problem') AS extraction;

Expected result: {"sentiment":"Negative","problem":"Dirty room"}

B. Parse extracted JSON into columns

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)
);

Related content