documents.classify scores one original file against caller-defined classes.
Classify the whole document once, or return one unit per selected page.
Classify reads the original file and does not accept
ParseResultSource.Basic usage
Method signature
Parameters
Unread pages are reported with a
classification_unread_pages disclosure.
Returns
AJob. After success, job.result is a ClassifyResult containing units
and any non-fatal disclosures.
Unread pages are disclosed as classification_unread_pages.
Define classes
Each class has a stableid, display label, and model guidance:
class_id.
Subclasses
Use subclasses when a broad class has meaningful variants:Document or page classification
The defaultdocument granularity returns one unit for the entire source:
page when a file contains different content on different pages:
Select pages
Handle unknown content
allow when the set of possible documents is open-ended. Use
force_best only when every input must belong to your closed class set.
Configure alternatives and reasons
max_alternatives defaults to 3, accepts 1–10, and includes the winner.
Reasons are included by default.
Response structure
rank=1 is the assigned class, or the top
candidate when unknown=True. The reserved other ID can appear when no
requested class matches.
confidence is DREX’s probability for the label, averaged over the menu
orders, when DREX decided it. When any other label in the unit lacks one,
every such label is the share of pages or sheets assigned that class.
Runner-up labels on an abstained unit keep DREX’s probability for that option.
Async classify
Complete example
Error handling
Best practices
Separate nearby classes
Explain how similar classes differ rather than repeating their labels.
Keep IDs stable
Treat
class_id as the durable join key and labels as display text.Allow unknowns first
Avoid forcing unrelated documents into a class while developing the taxonomy.
Use page mode deliberately
Page granularity is for mixed packets; document granularity is simpler for one logical file.