so much about agentic AI, and the precept is easy: let the mannequin determine.
- For a general-purpose assistant, that’s superb: let the agent attempt, watch what it does.
- For an enterprise RAG course of, it’s harmful. The solutions feed actual selections, so we’ve to know each step and management the stream between the steps.
This text applies that place to the step the place “let the mannequin determine” is most tempting: choosing the right parsing methodology for every doc. We construct that selection as a dispatcher we management. It reads the PDF’s nature, plans the strategies that match, executes them so as, and synthesizes each output into one enriched corpus for retrieval, era and analysis. Every choice is express and logged, so the plan might be learn and checked earlier than something runs.
This text extends the doc parsing brick of Enterprise Doc Intelligence, the collection that builds an enterprise RAG system from 4 bricks. It closes that brick by composing the strategies the collection constructed separately: fitz for the textual content layer, Azure Doc Intelligence and Docling for tables, a imaginative and prescient LLM for charts and diagrams, EasyOCR for pages with no textual content layer, picture captioning for what the pipeline would in any other case skip, and two methods of recovering a desk of contents, from the printed sommaire or from physique typography alone.
🧭 New to the collection? Begin with the map: Immediate, Context, Loop units out the three engineering layers each RAG system is constructed on, the immediate (the decision itself), the context (what fills the mannequin’s window), the loop (when the subsequent name fires and when it stops), and walks the entire collection by means of that lens, article by article. It’s the shortest option to see what is roofed and the place this one sits.

📓 The runnable pocket book runs parse_pdf_agentic() on the eye paper (information/paper/1706.03762v7.pdf), prints the detected nature, the four-step plan the dispatcher produced, and the merged corpus dict with a 15-row native toc_df and a 1048-row line_df: doc-intel/notebooks-vol1.
1. Why the scare quotes on “agentic”
Each RAG vendor now labels their document-parsing loop agentic. Open the code and it’s virtually all the time the identical factor: a rule-based dispatcher that reads a number of file indicators, picks an ordered plan of strategies, runs every in sequence, and folds the outputs. The LLMs dwell inside particular person leaves (a heading validation loop, a imaginative and prescient reader on figures, an OCR post-processor). No LLM on the dispatch layer decides what to run subsequent. No suggestions loop the place an agent watches an output and re-plans.
That’s precisely what the dispatcher on this article does. So calling it agentic is a stretch, and calling it agentic with out quotes can be promoting the identical buzzword-inflation the remainder of the market sells. The quotes keep.
The trustworthy image, perform by perform:
detect_document_nature(pdf_path): six deterministic flags learn fromline_df/span_df.is_scanned,has_native_outline,has_sommaire,is_composite,has_rich_figures,has_tables_signal. Docstring says it plainly: “deterministic; no LLM”.plan_parsing_methods(nature): pure Pythonif / elifon the character label. Each department returns a hard-coded ordered listing ofMethodStep. No LLM.parse_pdf_agentic(pdf_path, llm_parse=…): loops over the plan and calls one adapter per methodology. Thellm_parsekwarg is forwarded to strategies that use one (the body-structure loop, the longer term imaginative and prescient reader). The dispatcher itself makes zero LLM calls.synthesize_parsing_outputs(step_outputs): DataFrame merges + a_pick_richerheuristic. No LLM.
What true agentic parsing would add: an LLM that reads every methodology’s output, decides whether or not the corpus is accomplished or a way is price re-running with completely different parameters, and provides or drops strategies from the plan on the fly. Device use within the ReAct sense. Suggestions loops. That belongs to Quantity 3 (Agentic Bricks) of the collection, the place every brick will get an agent wrapper that observes, plans, and acts. This text stops one step brief.
So this text builds the trustworthy model of the sample that everybody calls agentic as we speak: rule-based routing plus LLM leaves. It is sufficient to shut the parsing brick with a single parse_pdf_agentic(path) name that returns an enriched corpus. Quantity 3 will add the actual agent on prime.
2. The doc we wish to use to its full extent
Consider the paperwork the place a single parsing methodology is rarely sufficient: a 200-page contract with price tables, a quarterly report stuffed with charts and footnotes, a grant software, a patent, a dense NIPS paper with equations and outcomes tables. Each defeats a distinct parser. Fitz will get the textual content however misses the desk cells. Docling will get the tables however the define is barely two ranges deep. Azure Structure is powerful on each however has no font measurement. Mistral OCR returns markdown at no cost however solely once you run it in opposition to a scanned web page. The staff wants every of those instruments on completely different paperwork, typically on completely different pages of the identical doc.
The reflex the collection has been constructing for eight articles is one methodology per drawback. That reflex is right on the particular person stage and it doesn’t scale to the doc. A manufacturing caller doesn’t wish to write a change assertion over parsers. They wish to name one perform and get again a corpus dict crammed to the extent the doc deserves. That’s what this text closes with.
Two regimes coexist and it’s price naming them earlier than the code lands. The primary is what this text builds: the “agentic” one above. Learn the doc as soon as, decide a plan, execute each step, fold the outputs. The doc will get all the things it deserves in a single go, even when that go prices a number of LLM calls and one OCR run. The second is adaptive parsing (a later article within the collection): the caller doesn’t enrich something up entrance; as a substitute, the retrieval brick asks for the pages it wants and parsing runs on demand. The primary is ex ante, the second is lazy. Each belong within the pipeline. This text is barely in regards to the first.
3. Nature, plan, execute, synthesize
The loop has 4 levels. Every is deterministic, low-cost, and inspectable; the selection of what to run is not an LLM choice. The LLMs enter every particular person methodology on the stage of its personal contract (mounted schema, injected callable, cached JSON), by no means on the dispatcher layer.

In: a PDF path. Optionally a pre-computed nature or plan. Optionally an
llm_parsecallable for strategies that use one. Out: an enriched corpus dict withline_df,span_df,toc_df,image_df,reference_df,table_df, plus thenatureandplanused to supply it, so the run is totally reproducible.
3.1 Nature: a rough learn of the doc
The primary go reads the file’s nature: a small Pydantic mannequin with categorical flags. Low-cost indicators solely. File probe plus a single line_df and span_df construct. No LLM.
The six flags are learn from the next indicators:
is_scanned:line_dfis empty or its row depend sits nicely beneathpage_count. No extractable textual content layer, OCR is required.has_native_outline:doc.get_toc()returns a non-empty listing.has_sommaire: an early web page carries 5 or extra dot-leader traces (Title ....... 12), the sign Article 5septies (TOC reconstruction from a sommaire) reads.is_composite:detect_document_boundaries(from the body-structure module of Article 5octies, TOC reconstruction from physique typography) fires on a numbering re-init, fashion rupture or cowl web page.has_rich_figures: picture density above the median for a prose doc.has_tables_signal: an inexpensive grid detector finds rows of three or extra brief whitespace-separated fields.
3.2 Plan: nature to an ordered listing of strategies
plan_parsing_methods reads the character and returns an inventory of MethodStep values. Every step names one parsing methodology, provides a one-line rationale, and carries an non-obligatory flag saying whether or not the dispatcher could skip it on error.

Two guidelines that maintain the plan trustworthy:
- Each plan begins with
fitz_native. Line and span frames feed each downstream methodology; there isn’t a case the place skipping them saves time. - Non-obligatory flags are used sparingly.
image_pipelineandvision_llm_figuresare opt-out as a result of they name out to a heavy instrument; the TOC and structure strategies are required as a result of they’re the load-bearing outputs.
3.3 Id playing cards for the parsing strategies
The open-source parsing panorama is huge and it retains rising, so deal with this as a catalog, not a hard and fast listing. Right here is one identification card per methodology: its household, its licence, an at-a-glance strip (the place it runs, its pace, whether or not it calls an LLM, whether or not it exposes typography), the enter it takes, the output it returns, and the place it shines or breaks. Learn them as a set, not a sequence. Each card shares the identical template, so you may examine throughout them and decide the best one for a given doc. Each methodology right here is open supply, and the licence sits on every card. The household is colour-coded: blue for native textual content parsers, teal for structure and desk fashions, amber for OCR readers, violet for construction and TOC restoration.
Native textual content parsers (blue) learn the textual content layer instantly, no mannequin. fitz is a budget baseline, PyMuPDF4LLM turns the identical learn into Markdown for RAG, pdfplumber provides you precise coordinates and dominated tables, and pdfminer.six is the basic low-level extractor beneath.


Structure and desk fashions (teal) run a deep-learning structure go and hand again construction. They differ on Markdown versus cell-level tables, and on how a lot GPU they need.


OCR readers (amber) learn pixels when there isn’t a textual content layer. They differ on accuracy and on whether or not they get well tables.


Construction and TOC restoration (violet) rebuild the define. Learn the native define first; get well it from a printed contents web page or from physique headings when the file has neither; or partition the entire doc into typed parts with Unstructured.


Easy methods to learn a card in a single look. The vitals strip is the comparability shortcut. Model tells you whether or not the body-typography indicators from Article 5octies (TOC reconstruction from physique typography) can have something to latch onto once you chain the body-structure loop after this methodology. LLM tells you if the strategy opens a socket. Runs and Pace set the finances. The diagram and rows beneath fill within the precise enter and output.
Every card can be saved as its personal PNG below book_1/_figures/05_9_agentic_parsing_synthesis/en/identity_cards/, so a single methodology drops right into a slide deck, an analysis report, or a LinkedIn carousel with out cropping a grid.
3.4 Execute: one name per methodology, so as
The dispatcher runs every step by means of a small _run_step(step) shim that adapts to the strategy’s personal signature. Each parsing module (fitz, azure_layout, docling, easyocr, mistral_ocr, toc, toc.body_structure, imaginative and prescient, pictures) is already prepared for this name; the dispatcher owns the glue, not the logic.
Two issues price spelling out in regards to the execution stage. First, every methodology carries its personal error dealing with. When an non-obligatory step raises, the dispatcher captures the exception into _error on the step output and retains going. A required step failure aborts the run so the caller sees the actual error instantly. Second, each methodology’s uncooked output results in step_outputs alongside the merged corpus. An audit doesn’t need to guess what every methodology returned; it will possibly learn the hint finish to finish.
3.5 Synthesize: fold the outputs into one dict
The final stage folds the per-step outputs into one dict with six frames: line_df, span_df, toc_df, image_df, reference_df, table_df, plus a sources listing saying which methodology contributed every body.
The merging rule is easy: protect each native body verbatim, and when two strategies produced the identical key, maintain the strictly-more-informative one (greater row depend with a suitable column set). Anything concatenates. The complete column-level reconciliation between, say, Docling desk cells and Azure Structure cells lives within the particular person modules; the dispatcher doesn’t re-implement it.
4. An actual run on the eye paper
Here’s what the dispatcher returns on information/paper/1706.03762v7.pdf, a 15-page NIPS paper with a local define. The character comes again as native-with-outline. The plan lists 4 steps: fitz_native (obligatory, low-cost), fitz_native_toc (obligatory, free from doc.get_toc()), toc_body_structure (advisory, catches the level-3 subsections the define missed) and image_pipeline (non-obligatory). The merged corpus dict carries a 15-row toc_df from the native define, a 1048-row line_df from fitz, and a 3480-row span_df from build_span_df. The picture and reference frames are empty on this run as a result of the paper has no charts and the reference-extraction methodology has not been wired into the plan but.
That run value one line_df construct, one span_df construct, one native TOC learn and one body-structure loop. No imaginative and prescient LLM, no OCR, no Docling. The plan matched the doc.
5. Price, and when to not use it
Agentic parsing is just not free. On a 15-page paper the four-step plan prices a number of hundred milliseconds. On a 300-page contract with tables, figures and no native define the plan grows to seven or eight strategies, a few of which name an LLM; a full run can take a minute and value actual cents. That is superb for paperwork you propose to make use of to their full extent. It’s wasteful for corpus-scale ingestion the place most pages are by no means queried.
The rule I observe: run agentic parsing on chosen paperwork, the contracts a reviewer will really stroll finish to finish, the papers a search outcome surfaced and a reader clicked. For all the things else, the adaptive path (a later article) parses on demand, pushed by the questions the pipeline really receives. The 2 regimes coexist; the caller picks which one the doc goes by means of.
6. What this closes and what comes subsequent
This text closes brick 1. A caller who has a doc and needs all the things it affords calls parse_pdf_agentic(pdf_path) and will get again an enriched corpus dict with line_df, span_df, toc_df, image_df, reference_df and table_df, every crammed to the extent the doc helps. Each methodology the sooner articles launched now has a spot in a single dispatcher and one enriched corpus. The selection of strategies is deterministic; each LLM lives inside its personal module with its personal contract, not on the dispatcher layer, so the plan is inspectable and the execution auditable. The synthesized dict is what Half III (retrieval) and Half IV (era) learn subsequent.
Two follow-ups. First, the module comes with stubs for azure_layout, docling_local, easyocr_scan, mistral_ocr, vision_llm_figures and image_pipeline. They name the present methodology modules however don’t but carry a full end-to-end integration check on actual paperwork; these assessments are on the identical ticket. Second, the adaptive parsing article (a later Vol.1 or Vol.2 piece) will describe the counterpart regime the place parsing runs lazily, pushed by retrieval demand.
Case 4 of Article 5octies (TOC reconstruction from physique typography), the body-structure loop, is among the strategies the dispatcher picks from. The parser matrix from that article (fitz / Docling / Azure DI / Mistral OCR / EasyOCR) is precisely the matrix this text’s plan reads. The 2 articles kind the closing pair of the brick.
7. Additional studying and sources
Earlier within the parsing brick:
Exterior sources (labored examples and prior artwork):
- Vaswani et al., Consideration Is All You Want, arXiv:1706.03762, NeurIPS 2017. The paper we run the dispatcher on in Part 3.4 (arXiv non-exclusive distribution).
- PyMuPDF (fitz) documentation,
web page.get_text("dict"). The API_call_fitz_nativereads. - Sculley et al., Hidden Technical Debt in Machine Studying Techniques, NIPS 2015. The “glue code” sample the dispatcher walks a superb line round.















