---
title: ai_extract function
description: Learn the syntax of the ai\_extract function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/ai_extract
---

# `ai_extract` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime

The `ai_extract()` function extracts structured data from text and documents according to a schema you provide. You can use simple field names for basic extraction, or define complex schemas with nested objects, arrays, type validation, and field descriptions for business documents like invoices, contracts, and financial filings.

The function accepts text or `VARIANT` output from other AI functions like `ai_parse_document`, enabling composable workflows for end-to-end document processing.

For a visual UI to validate and iterate on the results of `ai_extract`, see [Information Extraction](https://docs.databricks.com/aws/en/agents/agent-bricks/info-extraction.md).

## Requirements

**Apache 2.0 license**

The underlying models that might be used at this time are licensed under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0), Copyright © The Apache Software Foundation. Customers are responsible for ensuring compliance with applicable model licenses.

Databricks recommends reviewing these licenses to ensure compliance with any applicable terms. If models emerge in the future that perform better according to Databricks's internal benchmarks, Databricks might change the model (and the list of applicable licenses provided on this page).

The model powering this function is made available using Model Serving Foundation Model APIs. See [Applicable model terms](https://docs.databricks.com/aws/en/machine-learning/model-serving/acceptable-use-models.md) for information about which models are available on Databricks and the licenses and policies that govern the use of those models.

If models emerge in the future that perform better according to Databricks's internal benchmarks, Databricks may change the models and update the documentation.

* This function is only available in some regions, see [AI function availability](https://docs.databricks.com/aws/en/resources/feature-region-support.md#ai-functions-aws).
* For workspaces with the [Enhanced Security and Compliance add-on](https://docs.databricks.com/aws/en/security/privacy/enhanced-security-compliance.md),
  * See regional support for `ai_extract` for the appropriate [compliance standard](https://docs.databricks.com/aws/en/security/privacy/security-profile.md).
  * See [Manage Databricks previews](https://docs.databricks.com/aws/en/admin/workspace-settings/manage-previews.md) for how to enable it on your workspace.
* This function is not available on Databricks SQL Classic.
* Databricks Runtime 15.4 LTS or above is required. For an upcoming change to this requirement, see [AI Functions require Databricks Runtime 17.3 LTS or above](https://docs.databricks.com/aws/en/release-notes/whats-coming.md#ai-functions-runtime-support). Databricks Runtime 18.2 or above is recommended for the best performance and access to the latest features.
* Check the [Databricks SQL pricing page](https://www.databricks.com/product/pricing/databricks-sql).

> [!TIP]
>
> Databricks recommends using **version 2.0 or later** for `ai_extract`. Version 1.0 is a legacy interface that does not support these capabilities and is not recommended for new or production workloads.
>
> Version 2.0 and later supports,
>
> * Rich JSON schemas with nested objects, arrays, type validation, and field descriptions
> * Accepts both `STRING` and `VARIANT` input from upstream AI functions like `ai_parse_document`
>
> Version 2.1 also adds citations and confidence scores.
>
> To pin a version explicitly, pass `options => map('version', '2.1')`.

## Data security

Your document data is processed within the Databricks security perimeter. Databricks does not store the parameters that are passed into the AI function calls, but does retain metadata run details, such as the Databricks Runtime version used.

## Syntax

### Version 2.1 (recommended)

```
ai_extract(content, schema [, options])
```

### Version 2

```
ai_extract(content, schema [, options])
```

### Version 1 (Legacy)

```
ai_extract(content, labels [, options])
```

## <a id="arguments" />Arguments

### Version 2.1 (recommended)

* `content`: A `VARIANT` or `STRING` expression. Accepts either:
  * Raw text as a `STRING`
  * A `VARIANT` produced by another AI function (such as `ai_parse_document`)

* `schema`: A `STRING` literal defining the JSON schema for extraction. The schema can be:
  * Simple schema: A JSON array of field names (assumed to be strings)
    ```json
    "[\"vendor_name\", \"invoice_id\", \"total_amount\"]"
    ```
  * Advanced schema: A JSON object with type information, descriptions, and nested structures
    * Supports `string`, `integer`, `number`, `boolean`, and `enum` types. Performs type validation. Values that are not valid result in an error. Maximum of 500 enum values.
    * Enum fields list allowed values in `"labels"`, for example `{"currency": {"type": "enum", "labels": ["USD", "EUR", "GBP"]}}`. If no enum is found, the result is null.
    * Supports nested objects using `"type": "object"` with `"properties"`
    * Supports arrays of primitives or objects using `"type": "array"` with `"items"`
    * Optional `"description"` field for each property to guide extraction quality

* `options`: An optional `MAP<STRING, STRING>` containing configuration options:
  * `version`: Version switch to support migration (`"2.1"`, `"2.0"`, `"1.0"`). Default is based on input types.
  * `instructions`: Global description of the task and domain to improve extraction quality. Must be less than 20,000 characters.
  * `mode`: Set to `"precision"` for extraction optimized for long documents, high-volume outputs, and complex schemas that are large, deeply nested, or require reasoning. For example, use precision mode to extract hundreds of line items from invoices, pull contract terms specified across multi-page documents, and populate schemas that require reasoning, such as calculating metrics and ratings.
  * `enableCitations`: When `true`, the output for each field in the extraction schema includes a list of zero or more citations, which indicates in the document the output extracted.
  * `enableConfidenceScores`: When `true`, the output for each field in the extraction schema includes a confidence score between 0 and 1, indicating how certain the model is about that value. The appropriate confidence threshold depends on your specific use case, and you should choose a cutoff that aligns with your tolerance for risk and error.

### Version 2

* `content`: A `VARIANT` or `STRING` expression. Accepts either:
  * Raw text as a `STRING`
  * A `VARIANT` produced by another AI function (such as `ai_parse_document`)

* `schema`: A `STRING` literal defining the JSON schema for extraction. The schema can be:
  * Simple schema: A JSON array of field names (assumed to be strings)
    ```json
    "[\"vendor_name\", \"invoice_id\", \"total_amount\"]"
    ```
  * Advanced schema: A JSON object with type information, descriptions, and nested structures
    * Supports `string`, `integer`, `number`, `boolean`, and `enum` types. Performs type validation. Values that are not valid result in an error. Maximum of 500 enum values.
    * Enum fields list allowed values in `"labels"`, for example `{"currency": {"type": "enum", "labels": ["USD", "EUR", "GBP"]}}`. If no enum is found, the result is null.
    * Supports nested objects using `"type": "object"` with `"properties"`
    * Supports arrays of primitives or objects using `"type": "array"` with `"items"`
    * Optional `"description"` field for each property to guide extraction quality

* `options`: An optional `MAP<STRING, STRING>` containing configuration options:
  * `version`: Version switch to support migration (`"1.0"` for v1 behavior, `"2.0"` for v2 behavior). Default is based on input types, but falls back to `"1.0"`.
  * `instructions`: Global description of the task and domain to improve extraction quality. Must be less than 20,000 characters.
  * `mode`: Set to `"precision"` for more powerful extraction optimized for long documents, high-volume outputs, and complex schemas — large, deeply nested, or requiring reasoning. For example, use precision mode to extract hundreds of line items from invoices, pull contract terms specified across multi-page documents, and populate schemas that require reasoning, such as calculating metrics and ratings.

### Version 1 (Legacy)

* `content`: A `STRING` expression containing the raw text.

* `labels`: An `ARRAY<STRING>` literal. Each element is a type of entity to be extracted.

* `options`: An optional `MAP<STRING, STRING>` containing configuration options:
  * `version`: Version switch to support migration (`"1.0"` for v1 behavior, `"2.0"` for v2 behavior). Default is based on input types, but will fall back to `"1.0"`.

## <a id="returns" />Returns

### Version 2.1 (recommended)

Returns a `VARIANT` containing:

```json
{
  "response": {...},       // Extracted data matching the provided schema. Each leaf is returned as a Field object (see below).
  "error_message": null,   // null on success, or error message on failure
  "metadata": { ... }      // Metadata about the response, including version and citation details.
}

```

The `response` field contains the structured data extracted according to the schema:

* Field names and types match the schema definition
* The schema's structure is preserved in the response: nested objects and arrays keep their original shape. Each “scalar” field in the extraction schema has an output object with the following fields:
  * `value`: The extracted value, typed according to the schema. `Null` if the field can not be extracted.
  * `citation_ids`: Only present when `enableCitations` is `true`. An array of IDs indexed into `metadata.citations`.
  * `confidence_score`: Only present when `enableConfidenceScores` is `true`. A float between 0 and 1.
* Type validation is enforced for integer, number, boolean, and enum types
* If `content` is `NULL`, the result is `NULL`.

The `metadata` field contains the metadata about the response. When `mode` is set in the request, `metadata` includes the `mode` used. When `enableCitations` is `true`, it also contains details about each citation ID in the `response` field that trace the extracted value back to its location in the input.

Depending on the type of input, citations can be of one of two types:

* For raw text (STRING) inputs, a citation is a span of text in the original input. Each object in metadata.citations contains:
  * `id`: Integer matching a citation\_ids entry on a field.
  * `start`: Inclusive 0-based character offset into the input string.
  * `stop`: Exclusive 0-based character offset into the input string.
* For PDF documents and images (when using `ai_extract` downstream of `ai_parse_document`), a citation is a bounding box in the original input. Each object in `metadata.citations` contains:
  * `id`: Integer matching a `citation_ids` entry on a field.
  * `bbox`: Array of `{coord, page_id}` objects, identical in shape to element.bbox in `ai_parse_document` output. `coord `is pixel coordinates on the page image as `[x0, y0, x1, y1]; page_id` is a 0-based page index.

### Version 2

Returns a `VARIANT` containing:

```json
{
  "response": { ... },   // Extracted data matching the provided schema
  "metadata": {
    "version": "2.0"     // Function version used
  },
  "error_message": null  // null on success, or error message on failure
}
```

The `response` field contains the structured data extracted according to the schema:

* Field names and types match the schema definition
* Nested objects and arrays are preserved in the structure
* Fields may be `null` if not found
* Type validation is enforced for `integer`, `number`, `boolean`, and `enum` types

The `metadata` field contains metadata about the response.

If `content` is `NULL`, the result is `NULL`.

### Version 1 (Legacy)

Returns a `STRUCT` where each field corresponds to an entity type specified in `labels`. Each field contains a string representing the extracted entity. If the function finds more than one candidate for any entity type, it returns only one.

## Examples

### Version 2.1 (recommended)

### Simple schema - field names only

```sql
> SELECT ai_extract(
    'Invoice #12345 from Acme Corp for $1,250.00 dated 2024-01-15',
    '["invoice_id", "vendor_name", "total_amount", "invoice_date"]',
    options => map('version', '2.1')
  );
 {
   "response": {
     "invoice_id":   {"value": "12345"},
     "vendor_name":  {"value": "Acme Corp"},
     "total_amount": {"value": "1250.00"},
     "invoice_date": {"value": "2024-01-15"}
   },
   "error_message": null
 }

```

### Advanced schema - with types and descriptions

```sql
> SELECT ai_extract(
    'Invoice #12345 from Acme Corp for $1,250.00 dated 2024-01-15',
    '{
      "invoice_id": {"type": "string", "description": "Unique invoice identifier"},
      "vendor_name": {"type": "string", "description": "Legal business name"},
      "total_amount": {"type": "number", "description": "Total invoice amount"},
      "invoice_date": {"type": "string", "description": "Date in YYYY-MM-DD format"}
    }',
    options => map('version', '2.1')
  );
 {
   "response": {
     "invoice_id":   {"value": "12345"},
     "vendor_name":  {"value": "Acme Corp"},
     "total_amount": {"value": 1250.00},
     "invoice_date": {"value": "2024-01-15"}
   },
   "error_message": null
 }
```

### Nested objects and arrays

```sql
> SELECT ai_extract(
    'Invoice #12345 from Acme Corp
     Line 1: Widget A, qty 10, $50.00 each
     Line 2: Widget B, qty 5, $100.00 each
     Subtotal: $1,000.00, Tax: $80.00, Total: $1,080.00',
    '{
      "invoice_header": {
        "type": "object",
        "properties": {
          "invoice_id": {"type": "string"},
          "vendor_name": {"type": "string"}
        }
      },
      "line_items": {
        "type": "array",
        "description": "List of invoiced products",
        "items": {
          "type": "object",
          "properties": {
            "description": {"type": "string"},
            "quantity": {"type": "integer"},
            "unit_price": {"type": "number"}
          }
        }
      },
      "totals": {
        "type": "object",
        "properties": {
          "subtotal": {"type": "number"},
          "tax_amount": {"type": "number"},
          "total_amount": {"type": "number"}
        }
      }
    }',
    options => map('version', '2.1')
  );
 {
   "response": {
     "invoice_header": {
       "invoice_id":  {"value": "12345"},
       "vendor_name": {"value": "Acme Corp"}
     },
     "line_items": [
       {"description": {"value": "Widget A"}, "quantity": {"value": 10}, "unit_price": {"value": 50.00}},
       {"description": {"value": "Widget B"}, "quantity": {"value": 5},  "unit_price": {"value": 100.00}}
     ],
     "totals": {
       "subtotal":     {"value": 1000.00},
       "tax_amount":   {"value": 80.00},
       "total_amount": {"value": 1080.00}
     }
   },
   "error_message": null
 }

```

### Composability with `ai_parse_document`

```sql
> WITH parsed_docs AS (
    SELECT
      path,
      ai_parse_document(
        content,
        MAP('version', '2.0')
      ) AS parsed_content
    FROM READ_FILES('/Volumes/finance/invoices/', format => 'binaryFile')
  )
  SELECT
    path,
    ai_extract(
      parsed_content,
      '["invoice_id", "vendor_name", "total_amount"]',
      MAP('version', '2.1', 'instructions', 'These are vendor invoices.')
    ) AS invoice_data
  FROM parsed_docs;
```

### Using enums

```sql
> SELECT ai_extract(
    'Invoice #12345 from Acme Corp, amount: $1,250.00 USD',
    '{
      "invoice_id": {"type": "string"},
      "vendor_name": {"type": "string"},
      "total_amount": {"type": "number"},
      "currency": {
        "type": "enum",
        "labels": ["USD", "EUR", "GBP", "CAD", "AUD"],
        "description": "Currency code"
      },
      "payment_terms": {"type": "string"}
    }',
    options => map('version', '2.1')
  );
 {
   "response": {
     "invoice_id":     {"value": "12345"},
     "vendor_name":    {"value": "Acme Corp"},
     "total_amount":   {"value": 1250.00},
     "currency":       {"value": "USD"},
     "payment_terms":  {"value": null}
   },
   "error_message": null
 }

```

### Citations (STRING input, SPAN citations)

```sql
> SELECT ai_extract(
    'Invoice #12345 from Acme Corp for $1,250.00 dated 2024-01-15',
    '{
      "invoice_id": {"type": "string", "description": "Unique invoice identifier"},
      "vendor_name": {"type": "string", "description": "Legal business name"},
      "total_amount": {"type": "number", "description": "Total invoice amount"},
      "invoice_date": {"type": "string", "description": "Date in YYYY-MM-DD format"}
    }',
   options => map(
     'version', '2.1',
     'enableCitations', 'true'
   )
  );
 {
   "response": {
     "invoice_id": {"citation_ids": [0], "value": "12345"},
     "vendor_name": {"citation_ids": [0], "value": "Acme Corp"},
     "total_amount": {"citation_ids": [1], "value": 1250.00},
     "invoice_date": {"citation_ids": [1], "value": "2024-01-15"}
   },
   "metadata": {
     "version": "2.1",
     "chunk_type": "span",
     "citations": [
       {"id": 0, "start": 0, "stop": 29},
       {"id": 1, "start": 29, "stop": 60}
     ]
   },
   "error_message": null
 }

```

### Citations (VARIANT from ai\_parse\_document, BBOX citations)

```sql
> WITH parsed AS (
    SELECT ai_parse_document(
             content,
             map('imageOutputPath', '/Volumes/main/default/parsed_images/')  // necessary for rendering bboxes
           ) AS doc
    FROM READ_FILES('/Volumes/main/default/invoices/invoice.pdf', format => 'binaryFile')
  )
  SELECT ai_extract(
    doc,
    '{"invoice_id":{"type":"string"}, "total_amount":{"type":"number"}}',
    options => map('version','2.1','enableCitations','true')
  ) AS extracted
  FROM parsed;
{
  "response": {
    "invoice_id":   {"citation_ids": [0], "value": "12345"},
    "total_amount": {"citation_ids": [1], "value": 1250.00}
  },
  "metadata": {
    "version": "2.1",
    "chunk_type": "bbox",
    "citations": [
      {"id": 0, "bbox": [{"coord": [120, 80,  240, 110], "page_id": 0}]},
      {"id": 1, "bbox": [{"coord": [400, 500, 560, 530], "page_id": 0}]}
    ],
    "pages": [{"id": 0, "image_uri": "/Volumes/main/default/parsed_images/6077ca79...f8efdb2ed05.jpg"}]
  },
  "error_message": null
}

```

### Confidence scores

```sql

> SELECT ai_extract(
    'Invoice #12345 from Acme Corp for $1,250.00 dated 2024-01-15',
    '{
      "invoice_id": {"type": "string", "description": "Unique invoice identifier"},
      "vendor_name": {"type": "string", "description": "Legal business name"},
      "total_amount": {"type": "number", "description": "Total invoice amount"},
      "invoice_date": {"type": "string", "description": "Date in YYYY-MM-DD format"}
    }',
   options => map(
    'version', '2.1',
    'enableConfidenceScores', 'true'
   )
  );
{
  "response": {
    "invoice_id": {"confidence_score": 0.95, "value": "12345"},
    "vendor_name": {"confidence_score": 0.62, "value": "Acme Corp"},
    "total_amount": {"confidence_score": 1.0, "value": 1250.00},
    "invoice_date": {"confidence_score": 0.99, "value": "2024-01-15"}
  },
  "error_message": null
}
```

### Precision mode

```sql
> SELECT ai_extract(
    'Invoice #12345 from Acme Corp for $1,250.00 dated 2024-01-15',
    '["invoice_id", "vendor_name", "total_amount"]',
   options => map(
    'version', '2.1',
    'mode', 'precision'
   )
  );
{
  "response": {
    "invoice_id":   {"value": "12345"},
    "vendor_name":  {"value": "Acme Corp"},
    "total_amount": {"value": 1250.00}
  },
  "metadata": {
    "version": "2.1",
    "mode": "precision"
  },
  "error_message": null
}
```

## Notebook example

The following notebook provides a visual debugging interface for analyzing the citation outputs of the `ai_extract` function. It demonstrates how to render citation metadata as substring snippets (STRING input) or bounding-box overlays (VARIANT input), and join `ai_extract` citations back to `ai_parse_document` elements in SQL so you can flag low-confidence extractions for manual review.

#### Citation rendering notebook

[Get notebook](https://docs.databricks.com/notebooks/source/machine-learning/large-language-models/ai-extract-cite-confidence.html)

### Version 2

**Simple schema - field names only**

```sql
> SELECT ai_extract(
    'Invoice #12345 from Acme Corp for $1,250.00 dated 2024-01-15',
    '["invoice_id", "vendor_name", "total_amount", "invoice_date"]'
  );
 {
   "response": {
     "invoice_id": "12345",
     "vendor_name": "Acme Corp",
     "total_amount": "1250.00",
     "invoice_date": "2024-01-15"
   },
   "metadata": {
     "version": "2.0"
   },
   "error_message": null
 }
```

**Advanced schema - with types and descriptions**

```sql
> SELECT ai_extract(
    'Invoice #12345 from Acme Corp for $1,250.00 dated 2024-01-15',
    '{
      "invoice_id": {"type": "string", "description": "Unique invoice identifier"},
      "vendor_name": {"type": "string", "description": "Legal business name"},
      "total_amount": {"type": "number", "description": "Total invoice amount"},
      "invoice_date": {"type": "string", "description": "Date in YYYY-MM-DD format"}
    }'
  );
 {
   "response": {
     "invoice_id": "12345",
     "vendor_name": "Acme Corp",
     "total_amount": 1250.00,
     "invoice_date": "2024-01-15"
   },
   "metadata": {
     "version": "2.0"
   },
   "error_message": null
 }
```

**Nested objects and arrays**

```sql
> SELECT ai_extract(
    'Invoice #12345 from Acme Corp
     Line 1: Widget A, qty 10, $50.00 each
     Line 2: Widget B, qty 5, $100.00 each
     Subtotal: $1,000.00, Tax: $80.00, Total: $1,080.00',
    '{
      "invoice_header": {
        "type": "object",
        "properties": {
          "invoice_id": {"type": "string"},
          "vendor_name": {"type": "string"}
        }
      },
      "line_items": {
        "type": "array",
        "description": "List of invoiced products",
        "items": {
          "type": "object",
          "properties": {
            "description": {"type": "string"},
            "quantity": {"type": "integer"},
            "unit_price": {"type": "number"}
          }
        }
      },
      "totals": {
        "type": "object",
        "properties": {
          "subtotal": {"type": "number"},
          "tax_amount": {"type": "number"},
          "total_amount": {"type": "number"}
        }
      }
    }'
  );
 {
   "response": {
     "invoice_header": {
       "invoice_id": "12345",
       "vendor_name": "Acme Corp"
     },
     "line_items": [
       {"description": "Widget A", "quantity": 10, "unit_price": 50.00},
       {"description": "Widget B", "quantity": 5, "unit_price": 100.00}
     ],
     "totals": {
       "subtotal": 1000.00,
       "tax_amount": 80.00,
       "total_amount": 1080.00
     }
   },
   "metadata": {
     "version": "2.0"
   },
   "error": null
 }
```

**Composability with `ai_parse_document`**

```sql
> WITH parsed_docs AS (
    SELECT
      path,
      ai_parse_document(
        content,
        MAP('version', '2.0')
      ) AS parsed_content
    FROM READ_FILES('/Volumes/finance/invoices/', format => 'binaryFile')
  )
  SELECT
    path,
    ai_extract(
      parsed_content,
      '["invoice_id", "vendor_name", "total_amount"]',
      MAP('instructions', 'These are vendor invoices.')
    ) AS invoice_data
  FROM parsed_docs;
```

**Using enums**

```sql
> SELECT ai_extract(
    'Invoice #12345 from Acme Corp, amount: $1,250.00 USD',
    '{
      "invoice_id": {"type": "string"},
      "vendor_name": {"type": "string"},
      "total_amount": {"type": "number"},
      "currency": {
        "type": "enum",
        "labels": ["USD", "EUR", "GBP", "CAD", "AUD"],
        "description": "Currency code"
      },
      "payment_terms": {"type": "string"}
    }'
  );
 {
   "response": {
     "invoice_id": "12345",
     "vendor_name": "Acme Corp",
     "total_amount": 1250.00,
     "currency": "USD",
     "payment_terms": null
   },
   "metadata": {
     "version": "2.0"
   },
   "error": null
 }
```

**Precision mode**

```sql
> SELECT ai_extract(
    'Invoice #12345 from Acme Corp for $1,250.00 dated 2024-01-15',
    '["invoice_id", "vendor_name", "total_amount"]',
    options => map('version', '2.0', 'mode', 'precision')
  );
 {
   "response": {
     "invoice_id": "12345",
     "vendor_name": "Acme Corp",
     "total_amount": 1250.00
   },
   "metadata": {
     "version": "2.0",
     "mode": "precision"
   },
   "error_message": null
 }
```

### Version 1 (Legacy)

```sql
> SELECT ai_extract(
    'John Doe lives in New York and works for Acme Corp.',
    array('person', 'location', 'organization')
  );
 {"person": "John Doe", "location": "New York", "organization": "Acme Corp."}

> SELECT ai_extract(
    'Send an email to jane.doe@example.com about the meeting at 10am.',
    array('email', 'time')
  );
 {"email": "jane.doe@example.com", "time": "10am"}
```

## <a id="limitations" />Limitations

### Version 2.1 (recommended)

* This function is not available on Databricks SQL Classic.
* This function cannot be used with [views](https://docs.databricks.com/aws/en/views/index.md).
* The schema supports a maximum of 256 fields.
* Field names can contain up to 150 characters.
* Schemas support up to 12 levels of nesting for nested fields.
* Enum fields support a maximum of 500 values.
* Type validation is enforced for `integer`, `number`, `boolean`, and `enum` types. If a value does not match the specified type, the function returns an error.
* The maximum total context size is 1 million tokens.

### Version 2

* This function is not available on Databricks SQL Classic.
* This function cannot be used with [views](https://docs.databricks.com/aws/en/views/index.md).
* The schema supports a maximum of 256 fields.
* Field names can contain up to 150 characters.
* Schemas support up to 12 levels of nesting for nested fields.
* Enum fields support a maximum of 500 values.
* Type validation is enforced for `integer`, `number`, `boolean`, and `enum` types. If a value does not match the specified type, the function returns an error.
* The maximum total context size is 1 million tokens.

### Version 1 (Legacy)

* This function is not available on Databricks SQL Classic.
* This function cannot be used with [Views](https://docs.databricks.com/aws/en/views/index.md).
* If more than one candidate for an entity type is found in the content, only one value is returned.

## Related functions

* [`ai_parse_document` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/ai_parse_document.md)
* [`ai_classify` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/ai_classify.md)
* [`ai_prep_search` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/ai_prep_search.md)
* [`ai_search` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/ai_search.md)
* [`ai_enrich` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/ai_enrich.md)
