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

# Classify

> Label one file against classes you define

Classify reads the original file. It rejects a `parse_result` source.

```python theme={"dark"}
from ndi_sdk import NdiClient
from ndi_sdk.models.document_ops import ClassifyClass

with NdiClient() as client:
    document = client.documents.create_upload("invoice.pdf")
    job = client.jobs.wait(
        client.documents.classify(
            document,
            classes=[
                ClassifyClass(id="invoice", label="Invoice", description="A supplier invoice"),
            ],
            wait_seconds=30,
        ).job_id
    )
    for unit in job.result.units:
        print(unit.unknown, unit.labels)
```

## Method signature

```text theme={"dark"}
def classify(
    source: UploadSource | UrlSource | WorkspaceFileSource | UploadResponse,
    *,
    classes: list[ClassifyClass],
    granularity: Literal["document", "page"] = "document",
    page_ranges: list[PageRange] | None = None,
    unknown_policy: Literal["allow", "force_best"] = "allow",
    output: ClassifyOutputOptions | None = None,
    wait_seconds: int = 0,
    idempotency_key: str | None = None,
) -> Job
```

### Parameters

| Parameter        | Type                        | Required | Description                           |
| ---------------- | --------------------------- | -------- | ------------------------------------- |
| `source`         | upload, URL, workspace file | Yes      | Original file — not a `parse_result`  |
| `classes`        | `list[ClassifyClass]`       | Yes      | Labels to choose from                 |
| `granularity`    | `"document"` / `"page"`     | No       | Default `document`                    |
| `page_ranges`    | `list[PageRange]`           | No       | Inclusive 1-indexed ranges            |
| `unknown_policy` | `"allow"` / `"force_best"`  | No       | Default `allow`                       |
| `output`         | `ClassifyOutputOptions`     | No       | Alternatives and reasons              |
| `wait_seconds`   | `int`                       | No       | Hold the HTTP response open (max 300) |

### Returns

A `Job`. On success, `result.units` is one row per document or page range.
Confidence is the fraction of the unit assigned that label, not a calibrated
probability.

See [Classify guide](/guides/classify).
