Skip to content

IDP — Build Classifier

Type: idp-build-classifier  ·  Package: IDP Activities v1.20.4  ·  Output: object

Since: v1.2.0

Builds the schema that identifies which kind of document you are looking at, from the list of taxonomies you know. You run it through AI — Extract before extracting, and the playbook decides whether to carry on.

Because IDP — Ground does not cover this case, and it is worth understanding why.

Grounding verifies “this text is written in the document”. It does not verify “this document is the type I think it is”. If you give a purchase order to an invoice taxonomy:

  • If you are lucky, the model returns null for everything and the whole document goes to review. Costly (a person looks at it) but nothing bad is stored.
  • If you are not, the purchase order carries a number that looks like an invoice number. The model fills it in. And grounding confirms it, because that text really is in the document. High confidence, accepted automatically, wrong data stored without anyone seeing it.

That second case is what justifies classifying first.

It validates each taxonomy (the same rules as IDP — Build Schema), checks that no two share the same documentType and builds a JSON Schema with an enum of types that always includes unknown. It does not call the model: the log only says how many types it was built for.

ParameterTypeDefaultDescription
taxonomiesstring | List—The taxonomies to choose between: paths to .json files, the JSON as text or the objects. A single one is fine too. Their documentType and description are what the model reads to tell them apart.

None.

Returns an object with the JSON Schema, ready to pass as schema to AI — Extract. The model’s answer with that schema carries two fields:

FieldWhat it is
documentTypeOne of your taxonomies’ documentType values, or "unknown".
reasonWhat in the document made it decide that.

The list of types comes from the taxonomies themselves, so it cannot drift out of sync: you add a new type and the classifier knows it without you touching anything. Each taxonomy’s description is passed to the model as context to tell them apart, which is another reason to write it well.

IDP — Build Classifier taxonomies = [asset("taxonomies/invoice.json"), asset("taxonomies/purchase-order.json")] → output: classifier
IDP — Load Document path = docPath → output: doc
AI — Extract prompt = doc["text"]
schema = classifier
model = "claude-haiku-4-5"
→ output: kind
If condition = kind["documentType"] == "supplier-invoice"
...extract with the invoice taxonomy
Else
Log message = "Discarded: " + kind["documentType"] + " — " + kind["reason"]

Classifying is cheap: the document goes in once and the answer is two fields, so a small model is enough. What it really saves is what it prevents — not paying for the full extraction of a document that did not belong.

MessageCause and fix
'taxonomies' is required. / 'taxonomies' is empty; there is nothing to tell apart.No taxonomy was passed.
Two taxonomies declare the same documentType '…'. The model cannot tell apart two kinds with the same name.Two taxonomies with the same documentType (case-insensitive). Rename one.
'taxonomy' is not valid JSON: … / The taxonomy must declare a 'documentType'. / Field '…' has no 'description'. …A taxonomy is invalid. See the errors in IDP — Build Schema.