shipwithjev

Blog / 39

Document Classification: Sorting the PDF Mountain for Cents

Document classification with decision models: route contracts, invoices, forms, and reports by type, urgency, and risk, chunking realities included.

Somewhere in your organization there is a folder, or a drive, or a decade of email attachments, politely labeled "Documents." Inside: contracts beside invoices beside scanned forms beside the 2019 strategy deck, findable only by people who were there when it was filed. Document classification is the unglamorous discipline of making that mountain navigable, and it's historically been either a manual back-office function or an enterprise "intelligent document processing" contract with a six-figure floor.

The decision-model version is neither. A document is just long text (or text-extractable pixels) awaiting closed-set judgments: what type is this, which party, which workflow, how urgent, how risky. This page maps the pattern, including the length problem everyone hits in week one.

The judgment stack for documents

Type is only the first verdict, and rarely the valuable one. The stacks that pay for themselves per judge-question craft:

  • Type and subtype: contract → NDA / MSA / order form; correspondence → complaint / notice / inquiry
  • Routing facts: which counterparty, which department's workflow, which retention class
  • Presence checks: is a signature block present, is a date present, are payment terms stated
  • Risk flags: auto-renewal clause present, non-standard liability language present, deadline within 30 days
  • Duplicate and version verdicts: is this the same agreement as that one, which is later

Presence checks and risk flags are where classification quietly becomes review: not reading the contract for you (that's reasoning, see the limitations page), but ensuring no auto-renewal ever ambushes anyone again. The economics follow the standard shape (500 items for 3.5 cents is the reference from email; the cost table generalizes), and the materialize-a-column pattern from the database piece is exactly how verdicts become a searchable document index.

The part nobody's landing page mentions: length and extraction

Two engineering realities decide whether your pipeline works. Extraction first: scans need OCR before anything judges anything, and the local-OCR pattern from the screenshot-free build is the template: cheap local perception producing text, verdicts on the text. Then length: decision models judge what fits in a question's context, and a 90-page MSA doesn't. The working answers, in order of preference: judge the sections that carry the signal (first pages plus defined-terms plus the clause-bearing sections, located by cheap heuristics), run per-section verdicts and aggregate ("flag if any section contains non-standard indemnity"), and reserve whole-document reasoning for the frontier tier of a cascade. Per-section verdict stacks also debug beautifully: when a flag fires, you know which page fired it, which is the difference between a review queue and a mystery.

Compliance-grade uses (retention classes, privilege screens, regulatory filings) add the standing rules: version every question, log verdict plus confidence plus question version per document, keep humans on low confidence and on anything with legal weight, and audit samples forever per the labeling discipline.

Frequently asked questions

What is AI document classification?

Automated judgments over documents: type, routing, presence of required elements, risk flags, and duplicate status, turning unstructured piles into filterable, workflow-ready records.

How does it handle long documents?

By judging sections rather than swallowing wholes: signal-bearing pages get per-section verdicts that aggregate to document-level flags, with whole-document reasoning escalated to a bigger model only when needed.

Can it read scanned documents?

After OCR, yes; the pattern is local extraction feeding text verdicts. Judge the extracted text's quality too ("is this extraction legible?") so garbage scans route to humans instead of into confident nonsense.

Is this reliable enough for contracts and compliance?

As a screening and routing layer with confidence gates, logged versions, and human review on flags and low certainty: yes, and it beats the 20-percent-coverage status quo. As an unsupervised legal reader: no, and the limitations page explains why that boundary is permanent.

Numbers throughout are as reported by the build authors, not verified by shipwithjev. Code-shaped examples are pseudocode; the official docs live at docs.typesafe.ai.