---
title: ai_parse_document task for jobs
description: Add an ai\_parse\_document task to a Lakeflow Job to run ai\_parse\_document on documents in a volume or table and write the results to a Unity Catalog table.
canonical_url: https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/document-parsing
---

# `ai_parse_document` task for jobs

> [!NOTE]
> **Beta**
>
> This feature is in [Beta](https://docs.databricks.com/gcp/en/release-notes/release-types.md). To use it, a workspace admin must turn on **Lakeflow AI Function Task** from the **Previews** page. See [Manage Databricks previews](https://docs.databricks.com/gcp/en/admin/workspace-settings/manage-previews.md).

To parse documents in a job, use an `ai_parse_document` task. The task runs [`ai_parse_document`](https://docs.databricks.com/gcp/en/sql/language-manual/functions/ai_parse_document.md) on each document in a Unity Catalog volume or table. The task parses text, tables, figure descriptions, and layout from documents such as PDFs and images, and writes the result for each document to a Unity Catalog table. For supported file formats and limits, see [`ai_parse_document`](https://docs.databricks.com/gcp/en/sql/language-manual/functions/ai_parse_document.md#formats).

Configure the task in the [Jobs UI](https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/document-parsing.md#ui), create it with the [Jobs API](https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/document-parsing.md#api), or define it in YAML with [Declarative Automation Bundles](https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/document-parsing.md#dabs). In the API and bundles, use `ai_function_task` with the `ai_parse_document` function set. For requirements and how AI Function tasks process data, see [AI Function tasks for jobs](https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/index.md).

## <a id="ui" />Add an `ai_parse_document` task in the Jobs UI

To add an `ai_parse_document` task:

1. Navigate to the **Tasks** tab in the Jobs UI.
2. Click ![Plus icon.](https://docs.databricks.com/gcp/en/images/product-icons/PlusIcon.svg) **Add task**. If the job has no tasks yet, click ![Plus icon.](https://docs.databricks.com/gcp/en/images/product-icons/PlusIcon.svg) **Add another task type**.
3. Under **Document intelligence**, select **Document Parsing**.
4. Enter a name into the **Task name** field. It defaults to `parsing`.
5. Under **Input**, select the documents to parse. See [Input](https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/index.md#input).
   * **Volume**: Select a volume or a folder in a volume.
   * **Table**: Select a table and a [`FILE`](https://docs.databricks.com/gcp/en/sql/language-manual/data-types/file-type.md) or `BINARY` **Column**.
6. Under **Output**, select the **Location**, and optionally enter a **Table name**. See [Output](https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/index.md#output).
7. (Optional) For a table input, add an **ID column**. See [ID column](https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/index.md#id-column).
8. In **Describe element types**, select which parsed elements get an AI-generated description: **All supported types**, **Figures only**, or **None**. **None** generates no descriptions, which reduces compute and cost for documents with many figures. See [Understanding elements](https://docs.databricks.com/gcp/en/sql/language-manual/functions/ai_parse_document.md#understanding-elements).
9. (Optional) To configure retries, run-duration or streaming-backlog thresholds, or notifications, see [ Advanced task settings](https://docs.databricks.com/gcp/en/jobs/configure-task.md#advanced).
10. Click **Save task**.

The task runs the next time the job runs. To run the job on a schedule, see [Run jobs on a schedule](https://docs.databricks.com/gcp/en/jobs/scheduled.md). To edit, clone, disable, or delete this task, see [Configure and edit tasks in Lakeflow Jobs](https://docs.databricks.com/gcp/en/jobs/configure-task.md).

## <a id="api" />Create the task with the Jobs API

Send a request to `POST /api/2.2/jobs/create` with the following JSON body. This example creates a job that parses documents in `/Volumes/main/finance/invoices` and writes the results to `main.finance.parsed_invoices`.

Replace the example locations with your own. The input volume and output schema must exist. The task creates and manages its output table. For the required privileges, see [Requirements](https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/index.md#requirements).

```json
{
  "name": "parse_invoices",
  "tasks": [
    {
      "task_key": "parsing",
      "ai_function_task": {
        "volume": {
          "volume_path": "/Volumes/main/finance/invoices"
        },
        "output": {
          "catalog": "main",
          "schema": "finance",
          "table": "parsed_invoices"
        },
        "ai_parse_document": {
          "version": "2.0"
        }
      }
    }
  ]
}
```

For authentication and request details, see [`jobs/create`](https://docs.databricks.com/api/workspace/jobs/create). For the task settings, see [`ai_function_task`](https://docs.databricks.com/api/workspace/jobs/create#tasks-ai_function_task).

## <a id="dabs" />Define the task in Declarative Automation Bundles

Declarative Automation Bundles let you define the job in source files, so you can version, review, and deploy changes to it like code.

Add the following job definition to the `databricks.yml` file of an existing bundle. It defines the same task as the API example. To create a bundle and validate, deploy, and run the job, see [Develop a job with Declarative Automation Bundles](https://docs.databricks.com/gcp/en/dev-tools/bundles/jobs-tutorial.md).

```yaml
resources:
  jobs:
    parse_invoices:
      name: parse_invoices
      tasks:
        - task_key: parsing
          ai_function_task:
            volume:
              volume_path: /Volumes/main/finance/invoices
            output:
              catalog: main
              schema: finance
              table: parsed_invoices
            ai_parse_document:
              version: '2.0'
```

Replace the example locations as described in the [API example](https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/document-parsing.md#api). For the complete configuration keys and more examples, including chained tasks, see [AI Function task](https://docs.databricks.com/gcp/en/dev-tools/bundles/job-task-types.md#ai-function-task).

## Output

The `response` column of the output table holds the full `ai_parse_document` result for each document as a `VARIANT`. The task doesn't add a column for each value. To get a value as a column, select it from `response` in a query. For the format, see [`ai_parse_document` returns](https://docs.databricks.com/gcp/en/sql/language-manual/functions/ai_parse_document.md#returns). For the other columns, see [Output table](https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/index.md#output-table).

## <a id="chaining" />Use with other AI functions

To extract fields from or classify the parsed documents, add an [`ai_extract`](https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/information-extraction.md) or [`ai_classify`](https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/classification.md) task that runs after the `ai_parse_document` task. In the Jobs UI, the new task's input defaults to the `ai_parse_document` task's output table and `response` column. See [Use the output in a later task](https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/index.md#chain).

To define an `ai_parse_document` task followed by an `ai_extract` task in Declarative Automation Bundles, see the examples in [AI Function task](https://docs.databricks.com/gcp/en/dev-tools/bundles/job-task-types.md#ai-function-task).

## Additional resources

* [AI Function tasks for jobs](https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/index.md): Learn about AI Function tasks.
