---
title: ai_classify task for jobs
description: Add an ai\_classify task to a Lakeflow Job to run ai\_classify on every row of a table and write the assigned labels to a Unity Catalog table.
canonical_url: https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/classification
---

# `ai_classify` 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 classify text in a job, use an `ai_classify` task. The task runs [`ai_classify`](https://docs.databricks.com/gcp/en/sql/language-manual/functions/ai_classify.md) on each row of a Unity Catalog table. The task classifies text or parsed documents into labels that you define and writes the result for each row to a Unity Catalog table.

Configure the task in the [Jobs UI](https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/classification.md#ui), create it with the [Jobs API](https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/classification.md#api), or define it in YAML with [Declarative Automation Bundles](https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/classification.md#dabs). In the API and bundles, use `ai_function_task` with the `ai_classify` 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_classify` task in the Jobs UI

To add an `ai_classify` 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 **Classification**.
4. Enter a name into the **Task name** field. It defaults to `classification`.
5. Under **Input**, select a table and the **Column** to classify. To classify documents, parse them first. See [Use with other AI functions](https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/document-parsing.md#chaining).
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) Add an **ID column**. See [ID column](https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/index.md#id-column).
8. Define the labels to classify into. See [Define the labels](https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/classification.md#labels).
9. (Optional) Configure the settings under **Optional settings**. See [Optional settings](https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/classification.md#optional-settings).
10. (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).
11. Click **Save task**.

The task runs the next time the job runs. The first run classifies every row in the table. Later runs classify only the rows added or changed since the previous run, and remove the results of deleted rows. 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="labels" />Define the labels

Under **Labels**, add each label that an input can be classified as, with a name and an optional description. Label names must be unique. A description helps the function tell similar labels apart.

The function assigns each input the best-matching label, even when no label fits well. To catch inputs that don't fit, add a catch-all label, such as `other`, and describe what belongs in it. To review uncertain results, turn on **Confidence scores**.

An `ai_classify` task takes 2 to 10 labels. The `ai_classify` function itself takes up to 500 labels, so to use more than 10, call [`ai_classify`](https://docs.databricks.com/gcp/en/sql/language-manual/functions/ai_classify.md) in a [SQL](https://docs.databricks.com/gcp/en/jobs/tasks/sql.md), [notebook](https://docs.databricks.com/gcp/en/jobs/tasks/notebook.md), or [pipeline](https://docs.databricks.com/gcp/en/jobs/tasks/pipeline.md) task.

### <a id="optional-settings" />Optional settings

Under **Optional settings**, you can configure the following:

* **Confidence scores**: Include a confidence score for each label in the response.
* **Rationales**: Include a rationale that explains each classification in the response.
* **Multiple labels**: Assign more than one label to each input.
* **Instructions**: Guidance applied to every row, such as which label to choose when two labels fit.
* **Version**: The `ai_classify` version that the task runs, shown for reference. The version is pinned, so scheduled runs don't change when the function is updated.

## <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 classifies the `body` column of `main.support.tickets` as `urgent` or `normal` and writes the results to `main.support.ticket_labels`. The `ticket_id` column identifies each input row across runs.

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

```json
{
  "name": "classify_support_tickets",
  "tasks": [
    {
      "task_key": "classification",
      "ai_function_task": {
        "delta_table": {
          "table_name": "main.support.tickets",
          "input_column": "body",
          "merge_key_columns": ["ticket_id"]
        },
        "output": {
          "catalog": "main",
          "schema": "support",
          "table": "ticket_labels"
        },
        "ai_classify": {
          "version": "2.1",
          "inline_labels": {
            "labels": [
              {
                "name": "urgent",
                "description": "The customer is blocked or reports an outage."
              },
              {
                "name": "normal",
                "description": "A question or a non-blocking issue."
              }
            ]
          }
        }
      }
    }
  ]
}
```

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). To classify documents in a volume, [parse them first](https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/document-parsing.md#chaining).

## <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:
    classify_support_tickets:
      name: classify_support_tickets
      tasks:
        - task_key: classification
          ai_function_task:
            delta_table:
              table_name: main.support.tickets
              input_column: body
              merge_key_columns: [ticket_id]
            output:
              catalog: main
              schema: support
              table: ticket_labels
            ai_classify:
              version: '2.1'
              inline_labels:
                labels:
                  - name: urgent
                    description: The customer is blocked or reports an outage.
                  - name: normal
                    description: A question or a non-blocking issue.
```

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

To classify documents in a volume, parse them first. See [Use with other AI functions](https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/document-parsing.md#chaining).

## Output

The `response` column of the output table holds the full `ai_classify` result for each row as a `VARIANT`, including confidence scores and rationales when you turn them on. 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_classify` returns](https://docs.databricks.com/gcp/en/sql/language-manual/functions/ai_classify.md#returns). For the other columns, see [Output table](https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/index.md#output-table).

## Additional resources

* [AI Function tasks for jobs](https://docs.databricks.com/gcp/en/jobs/tasks/ai-functions/index.md): Learn about AI Function tasks.
* [Classification](https://docs.databricks.com/gcp/en/agents/agent-bricks/classification.md): Build and test labels in the Agent Bricks UI.
