Skip to main content
PreviewAgent Builder is currently in preview and may change before general availability.

When to use

Use fan-out extraction when your app needs to process documents that vary significantly in structure and content. A single extraction prompt cannot handle the differences between an invoice, a bill of lading, and a fuel receipt β€” each has different fields, layouts, and validation rules. This pattern is the right choice when:
  • You receive mixed document types in a single pipeline (email attachments, bulk uploads)
  • Each document type has a distinct schema with specialized fields
  • You need high extraction accuracy per type rather than a generic best-effort pass
  • The number of document types may grow over time without rearchitecting the workflow

Architecture

The pattern follows two phases: classification, then type-specific extraction.
This pattern uses the document nodes because they accept files directly. The TEXT_UNDERSTANDING and TEXT_EXTRACTION nodes work on text input only β€” to use them here, you would first need to convert the file to text with the Extract Data from File node.

Phase 1: Classification

A DOCUMENT_UNDERSTANDING node receives the document file and classifies it into one of the known types. The classification instructions constrain the output to an enumerated list, so the Condition node can route deterministically.

Phase 2: Type-specific extraction

Each branch contains a DOCUMENT_EXTRACTION node configured with:
  • Instructions tailored to that document type, telling the model which fields to look for
  • A response schema defining the exact JSON structure expected for that type
  • An Extraction Method suited to the document format (text-heavy PDFs vs. scanned images)
The branches reconnect on a shared downstream node, which receives the output of whichever branch executed.

Implementation

Step 1: Configure the classification node

Add a DOCUMENT_UNDERSTANDING node and configure it to classify the document type. Example classification instructions:
Example response schema:

Step 2: Add the Condition node

Add a Condition node after the classification node. Configure branches based on the document_type value:

Step 3: Configure type-specific extraction nodes

Each branch gets its own DOCUMENT_EXTRACTION node with instructions and a schema optimized for that document type. The node works directly on the uploaded file.
Prompt:
Response schema:
Keep schemas as flat as possible for simple document types (like fuel receipts and lumper receipts). Reserve nested objects for complex types that genuinely have grouped fields (like BOL with shipper/consignee blocks).

Configuration reference

If you need the raw text rather than schema-based extraction, use the Extract Data from File node instead β€” it supports PDF, DOCX, XLSX, PPTX, HTML, CSV, Markdown, AsciiDoc, and image formats (JPG, PNG, TIFF, BMP, WEBP), processing images directly through OCR. Its text output can then feed TEXT_UNDERSTANDING or TEXT_EXTRACTION nodes.

Scaling to many document types

This pattern scales well because adding a new document type requires only:
  1. Adding the new type to the classifier’s enumerated list
  2. Adding a new branch in the Condition node
  3. Adding a new DOCUMENT_EXTRACTION node with the type-specific instructions and schema
No existing branches are modified. This makes the pattern suitable for domains with dozens of document types.

Variations

Parallel extraction

Instead of classifying first, run extraction for all document types simultaneously and pick the result with the highest confidence. This trades compute cost for lower latency and avoids classification errors.
Parallel extraction works best when you have a small number of document types (under 5). Beyond that, the cost of running every extractor on every document becomes impractical.

Hierarchical classification

For large document sets, classify in two stages: first into a broad category (financial, shipping, legal), then into a specific type within that category. This reduces the number of options the classifier evaluates at each stage.

Confidence fallback

Add a confidence threshold to the classification step. If the classifier returns a confidence below the threshold, route the document to a manual classification queue instead of risking an incorrect extraction.
Start with a confidence threshold of 0.8 and adjust based on your observed accuracy. Track classification accuracy over time to identify document types that need prompt refinement.

Patterns overview

All available AI patterns and how to combine them

AI node types

Reference for DOCUMENT_UNDERSTANDING, DOCUMENT_EXTRACTION, and other node types

Extract Data from File

Configuration guide for the Extract Data from File node

AI comparison and reconciliation

Compare extracted data against system-of-record values
Last modified on July 8, 2026