docextract
Extract structured data from semi-structured documents — invoices, bills, tax forms, resumes, bank statements, shipment manifests — using any OpenAI-compatible LLM (OpenAI, Ollama, vLLM, Groq, etc.), with per-field grounding and confidence, not just raw extraction.
Why this, not just another parser
Most extractors give you a value and no way to know if it's real. This one tells you:
grounded— the value was found verbatim (or near-verbatim) in the source document text.ungrounded— the value doesn't appear in the source — likely a hallucination. Flag for human review.missing_required— a field you marked required came back empty.invalid_format— the value doesn't match a pattern/enum constraint you declared (e.g. a shipment status outside the allowed list).failed_check— a custom cross-field rule failed (e.g. line items don't sum to the stated total).
No extra LLM call for any of this — it's deterministic, string/rule-based validation against text you already extracted.
Where it fits: semi-structured documents with recurring fields (invoices, bills, tax forms, resumes, statements), and prose documents where proving a value came from the source matters (contracts, legal clauses, insurance claims). It is not a vision-LLM pipeline — it works from extracted text (digital PDF text layer, or local OCR for scans/images), which is what keeps it fast, cheap, and usable with small local models. Messy handwritten forms or complex multi-column layouts are a known weaker spot (see document-extractor-spec.md).
Two ways to use it
| Who it's for | How | |
|---|---|---|
| CLI | No coding needed | docextract extract <file> <schema.json> |
| Python API | Building it into your own app | DocumentParser(client).extract(document_bytes, schema) |
Defining what to extract also has two paths — hand-write a JSON/YAML schema file, or describe it in plain English and let the LLM draft the schema for you.
Install
pip install fastdocparse
(That's the PyPI distribution name — it was the closest available name once docextract turned out to collide with an existing project. The import name, the CLI command, and everything else stay docextract: from docextract import ..., docextract extract ....)
For local development instead:
git clone https://github.com/pranjalparmar/docextract
cd document-extractor
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -e ".[dev]"
You also need access to an LLM. Either:
- An OpenAI API key (
export OPENAI_API_KEY=...or pass--api-key), or - A local model via Ollama — no API key, no cloud, documents never leave your machine.
Quickstart — CLI (no coding)
# 1. Extract using one of the bundled example schemas
docextract extract sample_invoice.png src/docextract/schemas/invoice.json \
--model gpt-4o-mini --api-key sk-...
# Or with a local model via Ollama (no API key needed):
docextract extract sample_invoice.png src/docextract/schemas/invoice.json \
--model llama3.2 --base-url http://localhost:11434/v1 --api-key ollama
Output is JSON, printed to stdout (or saved with --output result.json):
{
"_meta": { "truncated": false, "truncation_reason": null },
"invoice_number": { "value": "INV-9011", "confidence": "high", "flags": ["grounded"] },
"total_price": { "value": 100.0, "confidence": "high", "flags": ["grounded"] }
}
Don't want to write JSON at all? Describe the fields in plain English instead:
docextract schema-from-text \
"I want the invoice number, total price, and vendor name. Invoice number and total are required." \
--output my_invoice_schema.json
# review my_invoice_schema.json, then:
docextract extract my_invoice.pdf my_invoice_schema.json
Quickstart — Python API
from docextract import Schema, Field, LLMClient, DocumentParser
schema = Schema(
name="Invoice",
fields=[
Field(name="invoice_number", description="The invoice number", required=True),
Field(name="total_price", description="Total amount due", type="number", required=True),
],
)
client = LLMClient(model="gpt-4o-mini", api_key="sk-...")
# or: LLMClient(base_url="http://localhost:11434/v1", api_key="ollama", model="llama3.2")
parser = DocumentParser(client=client)
with open("invoice.pdf", "rb") as f:
result = parser.extract(f.read(), schema)
print(result["invoice_number"]) # {'value': 'INV-9011', 'confidence': 'high', 'flags': ['grounded']}
Full documentation
- Getting Started — step-by-step install, CLI, and API walkthroughs
- Schema Guide — every field option (
type,required,pattern,enum,sub_fields, few-shotexamples), for JSON, YAML, and plain-English authoring - Output & Validation — the full result shape, what each confidence flag means, and how to write custom cross-check rules
- Architecture — diagrams of the pipeline, the module dependency graph, and where to plug in a contribution
- Project spec — architecture, phased roadmap, honest competitive positioning
Want to contribute? Start with docs/architecture.md for the map, then CONTRIBUTING.md for the process.
Status
Core extraction, grounding, chunking, both CLI/API paths, and real packaging are implemented and tested (74 tests, pytest -v). Published on PyPI as fastdocparse — pip install fastdocparse installs a working docextract command and a proper docextract.* import namespace, verified end to end with a clean-virtualenv install straight from the real public index. Not yet done: a hosted API — see document-extractor-spec.md for the roadmap.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastdocparse-0.1.1.tar.gz.
File metadata
- Download URL: fastdocparse-0.1.1.tar.gz
- Upload date:
- Size: 40.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2f5e43a1a4f8b31e63f183086c70340d985dc42c00a31e44f005a81c3fd5579
|
|
| MD5 |
38f4679a792e6ce2e5aed65b26ded99d
|
|
| BLAKE2b-256 |
9af1a8662712307a6c892fdb5fc468190a1d3bafb90b5e06a9930e704c4909a7
|
File details
Details for the file fastdocparse-0.1.1-py3-none-any.whl.
File metadata
- Download URL: fastdocparse-0.1.1-py3-none-any.whl
- Upload date:
- Size: 35.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6377a99e43d0513203d18ccb6bc781defc195d6d0523531cf6ce955759f03d3a
|
|
| MD5 |
87af51d2bb85f15285518dd1cd7a3511
|
|
| BLAKE2b-256 |
f424bd9615f5379e6c021c2d4e4bbf9748c3512e589a3d9e395f95efc736ed84
|