Ground AI answers in PDFs with PyMuPDF

Updated

Grounding means linking every claim in an AI answer to the exact place in the source document that supports it: the page, and the region on that page. PyMuPDF reads the position of every character in a PDF, so it can turn any model's citation into exact page coordinates, a highlighted passage or an evidence image that a reviewer can check in seconds.

Why grounding matters

AI answers about documents are only useful if people can check them. Language models often cite the right document but the wrong passage, and sometimes quote text that is not in the source at all: courts have now dealt with more than a thousand cases of AI-fabricated citations in legal filings. A citation that says "page 47" still leaves the reader searching. A highlight on the exact sentence, table cell or figure lets them confirm it.

What PyMuPDF adds

  • Exact coordinates. Positions come from the PDF's own text layer, not from a vision model's estimate, so evidence boxes are exact for born-digital PDFs.
  • Any model. Claude, OpenAI, Gemini or a local model: any answer that includes a quote and a page can be located and highlighted.
  • Runs locally. Locating, highlighting and checking citations need no extra model or cloud service.
  • The hard cases. Text across line breaks and hyphenation, table cells with their row and column labels, and text that came from OCR.

Articles

Cookbook recipes

AICitationsPDFGrounding

Fuzzy Number Matching with the PyMuPDF Grounding Skill

Match numbers in AI quotes against their word equivalents in a PDF

Intermediate · 5 min read
AICitationsPDFGrounding

Chunked Documents with PyMuPDF

Chunk blocks of text with bounding boxes using PyMuPDF.

Intermediate · 4 min read
AICitationsPDFGrounding

Build an Evidence Pack for an AI Answer

Turn an AI answer and its citations into one PDF that a reviewer, an auditor or a customer can check without any other tools.

Intermediate · 9 min read
AICitationsPDFGroundingHallucinations

Catch Hallucinated Citations

Run every quote an AI answer cites through the source PDF, and count the ones that are not there.

Intermediate · 12 min read
AICitationsPDFGroundingTables

Cite the Table Cell, Not the Page

When an AI answer quotes a number from a financial table, point to the exact cell, with its row and column, instead of the whole page.

Intermediate · 6 min read
AICitationsPDFGroundingOCR

Know Which Evidence Came from OCR

Not all text in a PDF is equally reliable. Tell born-digital text from OCR text, and flag OCR evidence for review.

Intermediate · 8 min read
AICitationsPDFGroundingLLM

Verify AI-Extracted Values Against the PDF

An LLM pulls fields out of an invoice or contract. Before anyone relies on them, check each value against the document and show where it is printed.

Intermediate · 9 min read
AICitationsPDFGroundingRAG

Keep Page Coordinates with Your RAG Chunks

Every chunk in your vector store can remember exactly where it came from in the PDF. PyMuPDF already gives you the coordinates; this article shows how to keep them.

Intermediate · 6 min read
AICitationsPDFGrounding

Cite Claude Answers

Sends a PDF to Claude with citations enabled, locates each cited passage on the page with PyMuPDF, highlights it, and exports coordinates for a web viewer.

Intermediate · 3 min read
AICitationsPDFGrounding

Ask a PDF and Highlight the Evidence

Answer questions from a PDF with page citations, verify each quoted passage, and create a copy with the evidence highlighted using PyMuPDF.

Intermediate · 7 min read

Frequently asked questions

PyMuPDF Logo

© 2026 Artifex Software Inc. All rights reserved.