Guide
Document Classification: How to Build It Into a Document AI Pipeline
Before a pipeline can extract anything, it has to know what each document is. How to design the labels, choose an approach, split mixed files and measure whether the classifier is right.
What document classification is
Document classification assigns each incoming document, or each page of it, a type from a fixed list: invoice, purchase order, bank statement, pay stub, W-2, lease, explanation of benefits, bill of lading. The label decides everything that happens next: which extraction schema runs, which validation rules apply, which queue or agent receives the result, and who is allowed to see it.
In a document AI pipeline it is the first decision made about content, and the cheapest one to get wrong in the moment and the most expensive to get wrong later. A pay stub labelled as a bank statement is extracted against the wrong schema, so every downstream field is either empty or invented, and nothing in the extraction step itself signals that the problem started earlier.
The phrase is also used in two other senses. In records management it means filing documents under a retention schedule, and in government and security work it means marking documents by sensitivity level (confidential, secret). Both overlap with what follows, since a classifier's label can drive retention and access rules, but this guide is about automated classification by document type as the front end of an extraction pipeline.
Where classification sits in the pipeline
Classification runs after files are ingested and normalised and before layout parsing and extraction. It is usually three related jobs, and it helps to name them separately because each fails differently:
| Classification | Splitting | Routing | |
|---|---|---|---|
| Question it answers | What type is this document or page? | Where does one document end and the next begin in this file? | Which schema, model, agent or person handles it? |
| Unit it works on | A document, or a single page | A sequence of pages | A labelled document plus its confidence |
| Typical failure | Two similar types confused (invoice vs credit note) | Two documents merged, or one document cut in half | A low-confidence label sent straight through with no fallback |
| How you notice | Extraction against the wrong schema, many empty fields | Fields from one document attached to another | Errors that only show up downstream, in the target system |
When documents arrive one per file and of a single known type (a supplier portal that only accepts invoices), classification can be skipped. As soon as files arrive by email, scanner or bulk upload, or a single PDF can hold several documents, it becomes a required stage.
Go deeper: Intelligent Document Processing (IDP): A Guide for Engineering Teams · Document Routing Logic in Multi-Agent AI Pipelines · Orchestration Patterns for Document Ingestion Pipelines
Designing the label set
Most classification problems in production are taxonomy problems. A model cannot reliably separate two labels that the business itself has not defined clearly. Before choosing an approach, write the label set down and test it on real documents:
- Define labels by what happens next, not by what a document looks like. If an invoice and a credit note are extracted with the same schema and go to the same queue, they may not need separate labels; if they post to the ledger with opposite signs, they do.
- Write a one-paragraph description and a few real examples for every label. The same descriptions serve as annotation guidelines for people and as label definitions for an LLM-based classifier.
- Always include an 'other' or 'unknown' label. Real inboxes contain cover letters, blank pages, marketing inserts and document types nobody planned for. A classifier with no place to put them will force each one into the closest real label.
- Decide how fine-grained to go. One 'tax form' label with sub-types (W-2, 1099, 1040) is often easier to maintain than a flat list of dozens of near-identical labels.
- Decide whether a document can carry more than one label. A single page that is both a signed contract and an amendment is a multi-label case; most pipelines avoid it by choosing a primary label and capturing the rest as fields.
- Version the taxonomy. Adding or splitting a label changes what past evaluation numbers mean, so record which version each result was measured against.
Go deeper: Structured Output Schema Design for Document Extraction APIs
Rules, trained models and LLMs compared
There are four broad ways to classify documents. Most production systems combine at least two: a cheap, deterministic layer for the cases that are certain, and a model for everything else.
| Approach | How it works | Good fit | Watch out for |
|---|---|---|---|
| Rules and keywords | Match titles, form numbers, sender addresses, file names or regular expressions | A few stable document types with unmistakable markers (a form number printed on every page) | Silent misses when wording or layout changes; rule sets that grow until nobody can maintain them |
| Text classifiers | A model trained on extracted text, from classic bag-of-words methods to fine-tuned transformer encoders | High volume, a stable label set, and labelled examples you can collect | Needs OCR first; ignores layout, so visually distinct types with similar wording get confused |
| Layout-aware and visual models | Models that read page images, or text together with its position on the page | Forms and statements where layout identifies the type better than wording does | Need labelled training data and retraining when new types appear |
| LLMs and vision-language models | Prompt a general model with the label set and descriptions; zero-shot or with a few examples | Many document types, few labelled examples, a label set that changes often | Cost and latency per page, output that needs constraining to valid labels, and confidence that is not calibrated by default |
A practical starting point: classify with an LLM or vision-language model constrained to your label set (structured output with an enum of labels plus 'unknown'), collect the human-reviewed results as training data, and move high-volume types to a cheaper trained classifier once you have enough examples to measure it against. Keep simple rules for the cases where a document announces its own type.
Many document AI platforms offer classification as a built-in step, either with prebuilt labels for common types or with custom labels you define. Check each vendor's documentation for whether it classifies whole files or individual pages, whether it can split files, whether it returns a confidence per label, and how custom labels are trained or described.
Go deeper: Vision-Language Models vs Traditional OCR Engines · Hybrid Computer Vision Pipelines for Document Parsing · Agentic Document Workflows With Tool-Calling LLMs
Splitting multi-document files
A loan application packet, a medical records release or a scanned batch from a mailroom arrives as one PDF holding many documents. Classifying the whole file gives one label for something that has several. The usual approach is to classify page by page and then find the boundaries:
- Classify each page. Give every page a type label and a confidence. Include labels for pages that belong to no document, such as separator sheets and blanks, so they can be dropped rather than merged into a neighbour.
- Detect first pages. Decide for each page whether it starts a new document. Strong signals include a title or letterhead at the top, a 'page 1 of n' marker, a change in issuer or account number, and a change in page size or orientation.
- Group and check. Group consecutive pages into documents and check each group against what you expect: page counts that match their own 'page x of n' markers, a statement with a single date range, one pay period per pay stub.
- Keep the page map. Record which source pages each document came from, so a reviewer can see the original pages and an extracted value can always be traced back to the page it was read from.
Two consecutive documents of the same type (three months of bank statements back to back) are the hardest case, because the page label never changes. Boundary signals such as page numbering, statement periods and account numbers matter more than the type label there.
Go deeper: Stateful Document Processing for Multi-Page Reasoning Tasks · Explanation of Benefits Document Parsing for Healthcare Revenue Cycle
Confidence, thresholds and the unknown pile
A classifier's output should always be a label plus a confidence, and the pipeline needs a rule for what happens below a threshold. Typical options are sending the document to a person to label, running a slower and more capable model as a second opinion, or extracting against a generic schema and flagging the result.
- Check calibration on your own documents. If documents labelled with 90% confidence are right far less often than that, the threshold you set will not mean what you think it means. LLM-reported confidence in particular should be measured before it is trusted.
- Set thresholds per label, not one for the whole system. Confusing two low-risk types costs little; misfiling a medical record or a legal notice can cost a great deal.
- Treat 'unknown' as a signal, not a failure. A rising share of unknown documents usually means a new document type, a new sender or a broken scanner, and it is worth an alert.
- Use agreement between independent signals. When a rule and a model agree, the document can pass straight through; when they disagree, it is a good candidate for review.
Go deeper: Confidence Scoring Architecture for Document Extraction Models · Human-in-the-Loop Review Workflows for Low-Confidence Extractions
How to evaluate a document classifier
A single accuracy figure hides most of what matters. Build a labelled test set from documents as they actually arrive, then look at the errors in detail:
- Sample the test set from real traffic, including the mix of types in their real proportions, plus a separate set weighted towards rare and difficult types so they are measured at all.
- Report precision and recall per label, and read the confusion matrix. It shows which pairs of types are confused, which usually points to a taxonomy fix rather than a model fix.
- Include documents that belong to none of your labels, and measure how often they are correctly sent to 'unknown' instead of forced into a real label.
- Score splitting separately from labelling: how many document boundaries were found exactly, how many documents were merged, and how many were cut in two.
- Weight errors by cost. Agree with the business which confusions are expensive, and make sure the evaluation reports those specifically.
- Measure latency and cost per page at your expected volume, since classification runs on every page that enters the pipeline.
Go deeper: Ground Truth Dataset Construction for Document Extraction Tasks · Evaluating Document AI Vendors With Real Enterprise Documents · Choosing a Document Extraction API When Every Incoming File Looks Different
Keeping it accurate in production
Classifiers drift for reasons that have nothing to do with the model: a supplier redesigns its invoice, a form gets a new revision, a new customer sends a document type nobody has seen. Watch the share of each label over time, the share sent to 'unknown' or to review, and the rate at which reviewers change the label. Feed reviewer corrections back into the test set, so the next evaluation measures the documents the pipeline sees now rather than the ones it saw at launch.
Go deeper: Production Monitoring for Document Extraction Pipeline Drift
Frequently asked questions
What is document classification in document AI?
It is the step that assigns each incoming document or page a type from a defined list, such as invoice, bank statement or pay stub, so the pipeline knows which extraction schema, validation rules and workflow to apply.
What is the difference between document classification and data extraction?
Classification decides what a document is. Extraction pulls specific values out of it, such as the invoice number or the statement period. Classification runs first, because the type decides which fields extraction should look for.
Do I need training data to classify documents?
Not to start. An LLM or vision-language model given clear label descriptions can classify without labelled examples. You do need a labelled test set to know how accurate it is, and labelled examples become valuable later if you move high-volume types to a cheaper trained model.
Should I use an LLM or a trained classifier?
An LLM is usually faster to set up and copes with a changing label set. A trained classifier is usually cheaper and faster per page once the label set is stable and you have examples. Compare both on the same test set built from your own documents, and check current per-page pricing for each option at your volume.
How do I handle PDFs that contain several documents?
Classify each page, detect where each new document starts, and group the pages between boundaries into separate documents. Keep a map back to the source pages, and evaluate splitting separately from labelling.


