/v2/extract, polls its job, and collects the result. One failed document returns an error without stopping the rest of the batch.
This recipe builds on the Extraction quickstart. Read that first if you want a detailed explanation of the request, polling flow, or response fields for one document.
What We’ll Build
A Python script that:- Finds every PDF in a
documents/directory. - Processes documents concurrently, using four workers by default.
- Submits each PDF with one shared extraction schema.
- Polls each job until it completes or fails.
- Writes all results and per-file errors to
results.json.
Show the Full Script
Show the Full Script
Save this as
batch_extract.py, place your PDFs in documents/, and set UNSILOED_API_KEY before running it.batch_extract.py
Step 1: Set Up Your Documents and Dependency
We’ll create a project directory, add a group of similar PDFs, and install the only Python package the script needs.1.1 Get an Unsiloed API Key
Create an API key in the Unsiloed dashboard, then set it in your shell:1.2 Add PDFs to the Input Directory
Create a project directory with adocuments/ subdirectory:
documents/. The files should belong to the same document family because the script applies one schema to all of them. A batch might contain invoices from different suppliers, bank statements from different institutions, or claim forms from different customers.
For this example, we used these public fund fact sheets:
The State Street document below contains the kind of repeated fields we want to collect from every fact sheet: a fund name, ticker, report date, and expense ratio.

1.3 Install Requests
Create a virtual environment and install Requests:.venv\Scripts\Activate.ps1.
Step 2: Configure the Batch and Its Schema
Create a file namedbatch_extract.py in the project directory. We’ll build it in three pieces: imports, batch settings, and the schema for our example documents.
2.1 Import the Python Modules
Add these imports at the top ofbatch_extract.py:
batch_extract.py
2.2 Set the Batch Limits and File Locations
Inbatch_extract.py, add the following configuration immediately below the imports:
batch_extract.py
MAX_WORKERS to suit your workload and account limits.
The polling settings allow each job approximately five minutes to finish. They control how long the script waits for a result, not how many documents Unsiloed can process.
2.3 Define the Schema for Your Documents
Inbatch_extract.py, add a SCHEMA dictionary immediately below the configuration:
batch_extract.py
invoice_number, vendor_name, invoice_date, and total_due instead.
Only require a field when it should appear in every valid document. We keep gross_expense_ratio optional because some fact-sheet formats may omit it.
Step 3: Submit and Poll One Document
Before adding concurrency, we’ll define the three small functions that process one PDF from upload to completed result.3.1 Submit a PDF for Extraction
Inbatch_extract.py, add submit_document() immediately below SCHEMA:
batch_extract.py
gamma model is the default, recommended Unsiloed extraction tier. See the model parameter for the available tiers.
The enable_citations option adds a page number and bounding box to each extracted field, so a reviewer can see where every value came from. Confidence scores come back either way.
3.2 Wait for the Job to Finish
Inbatch_extract.py, add wait_for_result() immediately below submit_document():
batch_extract.py
3.3 Combine Submission and Polling
Inbatch_extract.py, add extract_document() immediately below wait_for_result():
batch_extract.py
Step 4: Run the Documents as a Batch
The remaining code isolates per-file errors, runs the worker pool, and writes one output file.4.1 Keep One Failure From Stopping the Batch
Inbatch_extract.py, add process_document() immediately below extract_document():
batch_extract.py
4.2 Find the PDFs and Start the Worker Pool
Inbatch_extract.py, add the following code immediately below process_document():
batch_extract.py
ThreadPoolExecutor calls process_document() once per PDF. The MAX_WORKERS setting determines how many of those calls the script runs concurrently.
4.3 Save the Results and Print a Summary
At the end ofbatch_extract.py, immediately below the worker-pool block, add:
batch_extract.py
results.json.
Step 5: Run the Batch and Inspect the Results
Run the completed script from the project directory:results.json to inspect every API result:
Where to Take This Next
The pattern stays the same when you replace the sample documents:- Put one document family in the input directory.
- Describe its shared fields in one schema.
- Tune the worker count for your throughput target, account limits, file sizes, and available memory.
- Keep each file’s error separate from the rest of the batch.
Extraction Response Format
Read values, confidence scores, and citations from each completed result.
Sort and Extract a Mixed Document Pile
Route different document types to different schemas before processing them.

