> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# ai_extract

> 按给定字段名称从文本中提取信息。

按给定字段名称从文本中提取信息。

## 语法

```sql theme={null}
ai_extract(input, labels[, provider[, model]])
```

## 参数

* `input`：VARCHAR 表达式，要提取信息的文本。
* `labels`：非空常量 `ARRAY<VARCHAR>`，需要提取的字段名称。

`provider`、`model` 的类型及默认行为见 [公共调用规则](/documents/cn/4.2/sql-reference/sql-functions/ai-functions/ai_functions.md#公共调用规则)。

## 返回值

返回可空的 JSON 对象。数据库 要求模型把提取的字段和值放在 `response` 对象中，找不到值的字段填 JSON `null`。例如，提取姓名和城市时，模型可能返回 `{"response":{"name":"Alice","city":"Paris"}}`。

数据库 只检查返回值是否为 JSON 对象，不检查 `response` 的字段结构或提取结果是否准确。

## 示例

```sql theme={null}
SELECT ai_extract('Alice lives in Paris.', ['name', 'city']);

SELECT ai_extract(
    input => 'Alice lives in Paris.',
    labels => ['name', 'city'],
    provider => 'support_chat'
);
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.