> For the complete documentation index, see [llms.txt](https://docs.tagshelf.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tagshelf.dev/document-processing.md). Agents can also search and read this documentation through its [MCP server](https://docs.tagshelf.dev/~gitbook/mcp).

# Document processing

How a document moves through Alfred, from the moment you send it to the data you read back.

<figure><img src="https://2255375864-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mae8GCwLSd9I2djPI-M%2Fuploads%2FTI9crcxXU0ALCK4jmqW3%2Fdocument-processing-sorter.png?alt=media&amp;token=d17083f0-ddb0-4506-997d-78bc75e6fa28" alt="A sorting machine turning an incoming document into structured cards" width="420"><figcaption></figcaption></figure>

This page explains how a document moves through Alfred, so the reference pages make sense when you read them. You send files, Alfred groups them into a job, classifies each file into a tag (a document type), extracts the data points that tag defines, and optionally sends the result to a person for review. You then read the results through the API, or Alfred delivers them to you as events.

If you want to run code first, start with the [Quick start](https://docs.tagshelf.dev/quick-start.md).

### Ways to send documents

Every way of sending documents ends the same way: Alfred creates a job. The job's `channel` field tells you how it reached Alfred.

| You have                                                                               | Use                                                                                                                                                                                                                                                                | `channel`                    |
| -------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------- |
| Files at URLs Alfred can download                                                      | [`POST /api/file/upload`](https://docs.tagshelf.dev/endpoints/file.md) with `url` or `urls` (up to 100 URLs in one request)                                                                                                                                        | `api`, or the label you send |
| Files in your own cloud storage (Amazon S3, DigitalOcean Spaces or Azure Blob Storage) | [Remote sources](https://docs.tagshelf.dev/endpoints/file/source.md), then `POST /api/file/upload` with the source's name                                                                                                                                          | `api`, or the label you send |
| Files on your computer or server                                                       | A [deferred session](https://docs.tagshelf.dev/endpoints/deferred-session.md): open a session, upload each file with [`POST /api/file/uploadfile`](https://docs.tagshelf.dev/endpoints/file.md), then [create the job](https://docs.tagshelf.dev/endpoints/job.md) | `api`, or the label you send |
| Documents someone uploads in the Alfred app                                            | The Alfred app                                                                                                                                                                                                                                                     | `web`                        |
| Documents your company receives by email, when email intake is set up for it           | Email                                                                                                                                                                                                                                                              | `email`                      |

When you create a job through the API, you can set `channel` to your own label, such as `erp`. If you don't, it is `api`. You can filter [List jobs](https://docs.tagshelf.dev/endpoints/job.md) by `channel`, together with your own `correlation_id`.

Your company decides which file types Alfred accepts, and it has a largest-file setting that defaults to 1 GB. A file that breaks either rule is refused or fails on its job, with a message that names the reason.

### The job lifecycle

A job is one submission: the files you sent together. Its `stage` shows where the job as a whole is. Most jobs follow this path:

```mermaid
flowchart LR
    draft(["draft"]) --> queued["queued"]
    queued --> started["started"]
    started --> prep["downloading, downloaded,<br/>syncing, synced"]
    prep --> in_progress["in_progress"]
    in_progress --> pre_completion["pre_completion"]
    pre_completion --> completed(["completed"])
    in_progress --> completed
    queued -.-> ended(["failed, invalid,<br/>canceled or expired"])
    in_progress -.-> ended
```

* `draft` applies only to a deferred session. The job waits there until you create it from the session.
* `pre_completion` appears only if your company has final checks that run before a job completes. Other jobs go straight to `completed`.
* Between `started` and `in_progress`, Alfred fetches and stores your files. Which of the intermediate stages you see depends on how the files arrived, and a job can skip some of them.
* While a file waits for a person to review it, the job stays in `in_progress`. The job summary shows it: `has_confirmation_required_files` is `true` and `confirmation_required_files_count` says how many files are waiting. The job completes after the review.
* Sending results to a connected system is tracked per file, in the file's status, not as a job stage.

A job is done when it reaches `completed`. The stages `failed`, `invalid`, `canceled` and `expired` mean the job ended without results. You can restart a job that ended this way. Every stage is described in [Job Stages](https://docs.tagshelf.dev/endpoints/job/job-stages.md).

### What happens to each file

A job holds one or more files, and each file has its own `status`. The statuses move in this order:

1. **Receive and prepare.** The file is `uploaded`, then prepared for reading. Alfred can split a file into separate documents (`decomposing`, `decomposed`) or convert it to a readable format (`transforming`, `transformed`).
2. **Classify.** Alfred works out the file's tag (`classifying`, `classified`). It uses the tag's description and gives the file a confidence score. A higher score means Alfred is more confident. It doesn't tell you whether the result is correct. If the score is below the tag's confidence threshold, Alfred doesn't assign the tag, and nothing is extracted.
3. **Extract.** Alfred reads the data points the tag defines (`extracting`, `extracted`). Each value has its own `classification_score`, and a tag with no data points skips this step.
4. **Review.** A tag can ask for human review, and a low score can trigger it. The file then waits in `confirmation_required`, and the job stays in `in_progress` until the review is done. After a person confirms the results, the file goes through `confirmation_submitted` and `confirmed`.
5. **Finish.** The file is `finished`, and its results are ready. When your company sends results to a connected system, that delivery shows in the file's status (`waiting_to_be_sent_to_third_party`, `sent_to_third_party`), not in the job's stage.

If a step fails, the file gets a status that starts with `failed_`, such as `failed_classification` or `failed_extraction`. Every status is listed in [File Status](https://docs.tagshelf.dev/endpoints/file/file-status.md).

You can change what happens to files:

* **Merge.** `merge` on [`POST /api/job/create`](https://docs.tagshelf.dev/endpoints/job.md) combines all the files of a session into one PDF. It needs at least two files.
* **Decompose.** `decompose` splits each file into separate documents, and each one continues on its own. You can't use it together with `merge`.
* **Re-extract.** [`POST /api/file/reextract/{id}`](https://docs.tagshelf.dev/endpoints/file.md) reads a file's data points again, for example after you change the tag's data points. It can ask for a review. An API key can re-extract if your company's role policy allows it, but it can't reprocess.

### Getting results

You have three ways to read results:

* **Poll the job.** Call `GET /api/job/detail/{id}` and watch `stage`. The default response is a summary with the stage and file counts. Ask for `view=full` to also get the list of files. See [Get a job](https://docs.tagshelf.dev/endpoints/job.md).
* **Read the values.** Call `GET /api/values/file/{id}` for each file to get its data points. See [Values](https://docs.tagshelf.dev/endpoints/values.md).
* **Subscribe to events.** Register a webhook and Alfred sends you an event when a job or file changes, so you don't have to poll. See the [Event API](https://docs.tagshelf.dev/event-api.md).

To find a job again later, send your own `correlation_id` when you create it, then call `GET /api/job/all?correlation_id=...`.

### Next steps

| If you want to…                                                    | Read                                                                                                                           |
| ------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ |
| Send your first document and read its data                         | [Quick start](https://docs.tagshelf.dev/quick-start.md)                                                                        |
| Choose between API keys, OAuth and HMAC                            | [Authentication](https://docs.tagshelf.dev/authentication.md)                                                                  |
| Learn the headers, errors and rate limits that apply to every call | [API conventions](https://docs.tagshelf.dev/endpoints/api-conventions.md)                                                      |
| Create jobs, check them and restart them                           | [Job](https://docs.tagshelf.dev/endpoints/job.md) and [Job Stages](https://docs.tagshelf.dev/endpoints/job/job-stages.md)      |
| Upload, read and re-extract files                                  | [File](https://docs.tagshelf.dev/endpoints/file.md) and [File Status](https://docs.tagshelf.dev/endpoints/file/file-status.md) |
| Read extracted data                                                | [Values](https://docs.tagshelf.dev/endpoints/values.md)                                                                        |
| Get notified when something changes                                | [Event API](https://docs.tagshelf.dev/event-api.md)                                                                            |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.tagshelf.dev/document-processing.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
