mineru-refine
🌏 中文文档:README.zh-CN.md
A post-processor (linter / fixer) for MinerU parse results.
MinerU parses a PDF into content_list.json — an array of item objects, each item a
paragraph of body text, a heading, a table, or an image. The parse quality is good, but
there is a class of high-frequency structural problems:
- Pseudo-headings — an ordinary line of body text mislabeled as a heading
- Missed headings — same-level numbered siblings are all headings, yet this one is labeled body text
- Cross-page sentence breaks — one sentence cut into two items by a page boundary
- Cross-page split tables — one table cut into multiple tables across pages
- In-table continuation rows — a record's long cell cut into several
<tr> rows where only one column has text
- Page furniture — headers, footers, and page numbers mixed into the body
- Residual markup — parse debris like markdown links, LaTeX commands,
\$/\* escapes
- Giant blocks — several sections glued into one extra-long item
- Trailing adhesion — a cross-page merge sucks a standalone structural block like "[Related documents]" onto the end of the previous paragraph
- Table noise — all-empty
<tr>, OCR spaces inside cells (including URLs broken by spaces), pseudo-LaTeX wrapping ($\text{...}$ around plain text; known symbol commands are converted to Unicode, while real formulas like \frac are left untouched)
- Minority spellings of look-alike characters —
SWOT×24 coexisting with SW0T×6 in the same document (0↔O look-alike misread); a document-wide frequency vote rewrites the minority
- Section headings swallowed into a table caption — MinerU stuffs "4.6 Application of core organizational performance" into an adjacent table's
table_caption, which after rendering looks like a missed heading promotion but is really a structural misplacement
- Header/footer furniture swallowed into a table caption — MinerU stuffs a running header "Appendix 3: …" or a footer "Prepared by: Zhang Wei" into the
table_caption of a cross-page table fragment, mergeTable faithfully preserves it, and it renders as residue (identified via same-text furniture corroboration and removed)
Of these, unambiguous table noise and the frequency vote are handled directly by the
mechanical cleaning pass (deterministic code, self-verifying, no LLM); the rest go to
the LLM to judge.
mineru-refine takes the content_list, fixes these problems, and returns a content_list
with the same schema. Downstream still reads "a MinerU result" — plug it into an
existing pipeline as a transparent filter, with zero changes on the consumer side.
Two core promises:
- Never adds a single character: it only reduces and reorganizes (merge, split,
delete, demote); every content character in the output comes from the input, and each
step is verified by machine — not by prompting the LLM, but by rolling back
automatically on any violation. In the default configuration the only character
replacement is the mechanical cleaning pass's document-wide frequency vote
(
SW0T→SWOT: document-wide majority ≥4 occurrences and ≥3× the minority, differing
by exactly one look-alike character; the evidence is self-evident across the document,
deterministic, and each case is recorded in report.removedSpans with
reason=mech:token_vote→…).
- Never breaks the upstream (fail-open): any exception, timeout, or LLM
unavailability returns the input items unchanged, logs loudly, and marks
report.failOpen as true.
The fix decisions are made by the LLM ("should this suspected pseudo-heading be demoted,
or is it a false positive?"), but the LLM only picks one of the predefined fix
operations — execution, verification, and termination are all controlled by deterministic
code, and whether the result passes is decided by machine gates, not by LLM
self-assessment.
Install
The core is a single Rust implementation; each language binding imports the same code, with
structurally identical options and return values:
| Language | Install | Form |
|---|
| Python | pip install mineru-refine | PyO3 native extension (docs) |
| JS/TS | bun add mineru-refine / npm i mineru-refine | napi-rs native addon, Bun / Node ≥18 (docs) |
| Rust | cargo add mineru-refine | core crate (docs) |
| Any language | cargo install mineru-refine --features bin | HTTP server / CLI (see below) |
| Claude Code | /plugin install mineru-refine | end-to-end skill: file in, clean markdown out (docs) |