qaechi-parser
Evidence-first document extraction for RAG and business systems.
Every value comes back with the exact quote and page it was read from.
Quickstart | How it works | Parsing rules | Benchmarks | Plugins | API | Config | Contact | Maintainer | 한국어
Why qaechi-parser
LLM extraction is easy to demo and hard to trust. When a number is wrong, you need to
know where it came from. When the model is unsure, you want null, not a guess.
qaechi-parser is the extraction layer of the qaechi framework. It reads a document and proposes values with evidence. Your system (an ERP, a review queue, an agent) decides what to accept.
| qaechi-parser does | qaechi-parser does not |
|---|---|
| Load, chunk, index, extract, grade | Authenticate or authorize users |
Return each value with quote and page |
Approve, confirm or post anything |
| Report quotes it could not find in the source | Fix values so totals add up |
| Count what it skipped or truncated | Drop rows or sheets silently |
Features
- Provenance on every value.
quote,pageandchunkIdfor each field and line item. - Verbatim check. Each LLM quote is matched against the source text; misses are listed in
quoteCheck.notInSource. - Any document, one result shape. Fixed forms and free-form documents come back the same way, with evidence.
- Schema from your fields. You describe the fields you want; qaechi-parser builds the structured-output schema.
- Groundedness grade. A second pass labels results
yes/no/unknown. No key meansunknown, never an optimisticyes. - Runs without anything. With no keys and no storage it starts in stub mode and returns
nulls, so you can wire your UI first. - LangGraph optional. Same nodes and edges run on LangGraph or on a built-in sequential runner.
- Safe defaults. Loopback bind, constant-time token check, API docs off, path traversal blocked, input size limits.
Quickstart
pip install "qaechi-parser[parse]"
# Parse a local file (bundled sample ledger)
qaechi-parser parse examples/ledger.csv --doc-type ledger
{
"route": "parser",
"parser": "ledger",
"lines": [
{ "label": "Design work",
"amount": { "value": 1200000, "confidence": 1.0,
"provenance": { "page": 1, "quote": "Design work | 1 | 1,200,000" } } }
// ...
],
"total": { "value": 1225000, ... },
"groundedness": "yes"
}
Ask an LLM for free-form fields (needs pip install "qaechi-parser[all]" and OPENAI_API_KEY):
qaechi-parser parse contract.pdf --doc-type contract \
--field "party:text:the counterparty name" \
--field "fee:integer:monthly fee" \
--field "start:date:contract start date"
Or from Python:
import qaechi.parser as qp
result = qp.parse("contract.pdf", "contract",
fields=[{"name": "fee", "kind": "integer"}])
print(result.fields["fee"].value, result.fields["fee"].provenance.quote)
How it works
flowchart LR
F[fetch] --> D[select reader] --> L[load] --> C[chunk] --> R[retrieve] --> E[extract] --> G[grade]
G -->|"no (once)"| W[rewrite] --> E
G --> V[save]
- fetch: get the file from a local directory or an HTTP object store.
- select reader: plugins you register for a
docType+ extension (+sourceKind) take priority. With no source or nothing to read it, the job runs in stub mode. - load / chunk: PDF, PPTX, XLSX (every sheet), CSV, TXT, MD. Tables are never split.
- retrieve (opt-in): long documents are narrowed to the chunks that hold evidence.
- extract: structured output with a quote per value.
- grade: groundedness as a secondary signal; one widened retry on a clear
no(opt-in). - save: the result is stored as a proposal with its quote check.
Parsing rules
qaechi-parser decides what to read, how to cut it and what counts as evidence by fixed rules, not by model judgment. Same file in, same pages and chunks out.
1. Reader: who reads the document
qaechi-parser picks a reader for each document from its docType, its extension and, if the
reader declares any, its sourceKind. Plugins you register take priority over the built-ins, and
the most recently registered match wins. With no source or no way to read the document the job
runs in stub mode: every value null, the reason in notes. The reader used is reported in
route.
A parser that does not recognise the layout raises LayoutError rather than guessing.
2. Load: what each format turns into
Every loader returns pages, and the page number travels to provenance.page.
| Format | Page = | Rules |
|---|---|---|
| PDF page | Text layer via pymupdf4llm, tables kept as markdown. A page with no text is kept empty and reported in notes as no text on N page(s) (likely scanned; put OCR in front). Encrypted files fail unless QAECHI_PDF_PASSWORD opens them. |
|
| PPTX | slide | Title first as # title. Shapes in reading order (top-to-bottom, then left-to-right), including shapes inside groups. Tables become | a | b | rows. Charts become a series | category... table with their values. Speaker notes follow a [notes] marker. |
| XLSX / XLSM | sheet | Every sheet, hidden sheets too (marked (hidden)). Cached values, not formulas. Blank rows dropped and trailing empty cells trimmed; empty cells in the middle stay so columns line up. 1200000.0 prints as 1200000, a midnight datetime as 2026-01-31; nothing is rounded. Up to 20,000 rows are read per sheet for parsers; the first 300 non-blank rows go to the LLM, and the sheet header says so. |
| CSV | whole file | Delimiter sniffed (, ; tab |), UTF-8 with or without BOM. Same row rules as XLSX. |
| TXT / MD | whole file | As is. |
3. Chunk: how pages are cut
| Rule | Why |
|---|---|
| A sheet page is one chunk, however long. | A table split from its header loses meaning. |
Other pages are cut into table blocks (lines with 2+ |) and prose blocks. |
A PDF page often holds both. |
| Table blocks are never split. Prose blocks over 1,000 chars are split (100-char overlap). | Retrieval gets small prose chunks without breaking tables. |
| Small neighbouring blocks are packed together up to 1,000 chars. | A table keeps the sentence that introduces it. |
Each chunk starts with [doc: <type> | period: <p> | p.<n>]. |
The model can cite the page. |
| Chunk text is verbatim. | Quotes are checked against it. |
4. Evidence: when a quote counts
Each LLM quote is searched for in the chunk text. Before matching, both sides are normalized
only for: Unicode compatibility forms (full-width 1,000, NBSP), typographic quotes and
dashes (“ ” – −), markdown the loader added (|, **, __, <br>), and runs of
whitespace. Letters, digits and their order must match exactly, so a changed digit, a moved
decimal point or a dropped minus sign is reported in quoteCheck.notInSource.
5. Grade and save
- Groundedness is
yes/no/unknown; without an LLM key it isunknown, neveryes. Parser results areyesbecause their values are read, not generated. - A clear
noretries once with the full context, and only ifQAECHI_REWRITEis on. - Nothing is dropped silently: skipped rows, skipped sheets, truncated sheets, empty pages and quotes not found in the source are all counted in the result.
Benchmarks
What these rules buy you, measured on a seeded synthetic corpus (20 decks, 20 workbooks, 60 PDF-style pages, 380 quote trials). Each pipeline reads the same files:
- Naive baseline: what a quick RAG prototype does (text frames only, active sheet only, a fixed 1,000-char window, "is the number in the quote" check).
- qaechi-parser 1.1: the previous release's rules.
- qaechi-parser 1.2: the rules described above.
| Metric | Naive | v1.1 | v1.2 |
|---|---|---|---|
| PPTX text recovered (groups, tables, charts, notes) | 11% | 70% | 100% |
| XLSX values reachable (all sheets, incl. hidden) | 34% | 100% | 100% |
| XLSX text sent to the LLM (relative to 1.1) | 34%¹ | 100% | 22% |
| Tables kept whole with their header | 22% | 100% | 100% |
| Chunks within the 1,000-char budget | 100% | 0%² | 100% |
| Genuine quotes matched despite formatting | 100% | 75% | 100% |
| Invented quotes flagged (one digit changed) | 0% | 100% | 100% |
¹ Smaller only because it reads one sheet of three. ² 1.1 kept any page with a table as one chunk, prose included.
The corpus isolates one rule per metric; it is not a claim about any specific real-world document set. Reproduce or extend it with:
pip install -e ".[parse,dev]" langchain-text-splitters matplotlib
python benchmarks/run.py # writes benchmarks/results.json and docs/assets/benchmark*.png
Write a parser plugin
A plugin reads one fixed layout and never calls an LLM.
from qaechi.parser.registry import LayoutError, ParseInput, ParseOutput, register
from qaechi.parser.schemas import FieldValue, Provenance
@register("acme_invoice", doc_types={"invoice"}, extensions=(".xlsx",),
source_kinds={"acme"}, version="1")
def parse(doc: ParseInput) -> ParseOutput:
...
if header_not_found:
raise LayoutError("not an ACME invoice") # stop rather than misread
return ParseOutput(fields={"invoice_no": FieldValue(
value="A-001", confidence=1.0,
provenance=Provenance(document_id=doc.document_id, page=1, quote="Invoice No. A-001"))})
Load it with QAECHI_PLUGINS=my_package.acme, or ship it as a package with an entry point:
[project.entry-points."qaechi.parsers"]
acme = "my_package.acme"
See examples/key_value_parser.py for a runnable one.
HTTP API
pip install "qaechi-parser[parse,server]"
cp .env.example .env # sets QAECHI_INTERNAL_TOKEN and QAECHI_SOURCE_DIR
qaechi-parser serve # 127.0.0.1:3100
| Method | Path | |
|---|---|---|
GET |
/health |
status, engine, optional modules (no token) |
POST |
/jobs |
queue a job, returns 202 right away |
GET |
/jobs/{jobId} |
queued / running / succeeded / failed |
GET |
/results?documentId=&limit=&offset= |
list results (limit 1 to 200) |
GET |
/results/{id} |
full result with provenance |
GET |
/parsers |
registered parsers |
curl -X POST http://127.0.0.1:3100/jobs \
-H "X-Internal-Token: $QAECHI_INTERNAL_TOKEN" -H "Content-Type: application/json" \
-d '{"documentId":"doc-1","source":"ledger.csv","docType":"ledger"}'
JSON is camelCase. Full contract: docs/api.md.
Configuration
| Variable | Default | |
|---|---|---|
QAECHI_INTERNAL_TOKEN |
(required for API) | shared token for X-Internal-Token |
QAECHI_SOURCE_DIR |
read sources from this directory | |
QAECHI_SOURCE_URL / QAECHI_SOURCE_TOKEN |
read sources from {url}/{source} with a bearer token |
|
OPENAI_API_KEY |
enables model-based extraction and grading | |
QAECHI_LLM_MODEL |
gpt-4o-mini |
|
QAECHI_RETRIEVE / QAECHI_REWRITE |
off | narrowing and one retry (they change results) |
QAECHI_PLUGINS |
comma-separated modules to import | |
QAECHI_PDF_PASSWORD |
for encrypted PDFs |
All variables: .env.example.
Install options
| Extra | Adds |
|---|---|
| (none) | the library: CSV/TXT, parser plugins, stub mode |
server |
the HTTP service (qaechi-parser serve): FastAPI, Uvicorn |
parse |
PDF, PPTX, XLSX, HTTP sources |
llm |
LLM extraction, grading, LangGraph |
otel |
OpenTelemetry metrics and traces (Observability) |
kafka |
queue mode: qaechi-parser worker and POST /jobs publishing to Kafka (Queue mode) |
postgres, mysql, mongodb |
Job and result store shared by the API and workers: PostgreSQL (incl. Supabase, Neon), MySQL or MariaDB, MongoDB (incl. Atlas). Install the one you run |
all |
all of the above |
Docker: docker build -t qaechi-parser . && docker run -p 127.0.0.1:3100:3100 --env-file .env qaechi-parser
Roadmap
- Postgres / pgvector store
- More model providers
- OCR front end for scanned PDFs
- Evaluation harness with golden sets
Ideas and votes are welcome in Discussions.
Contributing
Issues and PRs are welcome. Read CONTRIBUTING.md first; commits follow Conventional Commits so releases are automatic. Security reports go through SECURITY.md, not public issues.
Contact
Questions, ideas and use-case reports: GitHub Discussions or email ddaeyongee@gmail.com. Bugs go to Issues; security reports follow SECURITY.md.
Maintainer
Taeyong Kang (@ddaeyongee), Seoul, South Korea
Application Architect at LG CNS (2021 to present) and Founder of CNTSOFT (2026 to present), previously at POSCO DX. 11+ years designing enterprise applications, focused on microservice architecture and real-time, high-volume event streaming.
- Microservice architecture: application architect for a platform of about 200 microservices on Amazon EKS serving about 50,000 concurrent users; reusable MSA application standards adopted across banking, insurance and public-sector programs.
- Event streaming: Apache Kafka and Amazon MSK with the transactional outbox pattern and change data capture, with no message loss or duplication. Designed and built parallel processing (a swimlane dispatcher) in the open-source Eventuate CDC framework together with its original author, to meet production TPS targets.
- Telemetry and observability: Kafka-based log pipelines (Amazon MSK + ELK), CloudWatch, Prometheus and Grafana, VictoriaMetrics and Grafana Alloy.
- AI document pipelines: RAG and LLM structured output with LangGraph, the groundwork for this project.
This background shapes qaechi's next modules: batch processing and event streaming for documents at scale.
License
Apache-2.0 © 2026 Taeyong Kang
Metadata
Release files for qaechi-parser 2.3.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| qaechi_parser-2.3.4.tar.gz | 70.4 kB | With provenance | Details for qaechi_parser-2.3.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| qaechi_parser-2.3.4-py3-none-any.whl | Python 3 | none | any | Details for qaechi_parser-2.3.4-py3-none-any.whl |
Total release size: 135.8 kB
Release files / qaechi_parser-2.3.4.tar.gz
| Download URL | qaechi_parser-2.3.4.tar.gz |
|---|---|
| Size | 70.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6f364785b1940c420656ce99c663bf46c7d7804fa9562ae751e2ad4878145986
|
|
BLAKE2b-256 checksum How to use checksums |
b42481225952ace657c54bf156a4331d69893e8fde30c36da416739860530316
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logRelease files / qaechi_parser-2.3.4-py3-none-any.whl
| Download URL | qaechi_parser-2.3.4-py3-none-any.whl |
|---|---|
| Size | 65.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e50bbdde6c5ba7405432f6275fd684e5b52413f3b74d4bf240980ec09fb87052
|
|
BLAKE2b-256 checksum How to use checksums |
6a090b0a511af530205740cb196060f7f3429b2829d8e9b882a851581f3c6b87
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logSecurity for qaechi-parser 2.3.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for qaechi_parser-2.3.4.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.