PDF to grounded Markdown with bounding box annotations
Project description
groundmark
Grounded Markdown for PDFs
groundmark is a thin, batteries-included wrapper around anchorite. It provides concrete implementations of anchorite's provider protocols — Pydantic AI for LLM-based Markdown generation and pdfplumber for bounding box extraction — so you can go from PDF bytes to annotated Markdown in a single call. All the heavy lifting (Smith-Waterman alignment, annotation, stripping, quote resolution) lives in anchorite.
Give it a PDF and a model string, get back Markdown with embedded bounding box coordinates that trace every text span back to its location in the source PDF.
Architecture
The library processes documents in two streams that are then merged:
-
Semantic Stream: The PDF is sent to an LLM (via Pydantic AI) to produce clean Markdown with
<!--page-->markers between pages. -
Positional Stream: The PDF is parsed locally by pdfplumber to extract line-level text segments and their bounding boxes.
-
Alignment: Smith-Waterman alignment (via anchorite) maps each parsed line to its position in the Markdown, constrained by page boundaries.
-
Annotation: Bounding box coordinates are injected as HTML span attributes:
<span data-bbox="120,45,180,890" data-page="3">The patient presented with</span>
Quick Start
import asyncio
import groundmark as gm
async def main():
pdf_bytes = open("document.pdf", "rb").read()
config = gm.Config(model="bedrock:au.anthropic.claude-sonnet-4-6")
# PDF -> annotated Markdown (one call)
result = await gm.process(pdf_bytes, config)
print(f"Coverage: {result.coverage_percent:.2%}")
print(result.annotated_markdown[:500])
# Strip for LLM consumption
stripped = gm.strip(result.annotated_markdown)
# stripped.plain_text: clean Markdown with spans removed
# stripped.validation_map: list of (start, end, Anchor) ranges
# Resolve verbatim quotes to PDF coordinates
resolved = gm.resolve(result.annotated_markdown, ["the patient presented with"])
# -> {"the patient presented with": [(page, BBox), ...]}
if __name__ == "__main__":
asyncio.run(main())
Debug Visualizer
The included visualizer overlays extracted bounding boxes onto the source PDF, useful for diagnosing alignment issues. Blue highlights show raw extracted boxes from pdfplumber; red highlights show aligned boxes from the annotated Markdown.
python -m groundmark.visualize input.pdf output.pdf --model "bedrock:au.anthropic.claude-sonnet-4-6"
# Or with cached Markdown:
python -m groundmark.visualize input.pdf output.pdf --markdown cached.md
Screenshot from Santoro et al., "Health outcomes and drug utilisation in children with Noonan syndrome: a European cohort study," Orphanet J Rare Dis 20:76 (2025). doi:10.1186/s13023-025-03594-7. CC-BY 4.0.
Configuration
Timeouts
The LLM call for PDF-to-Markdown conversion can take several minutes for large documents, especially with Opus on Bedrock. Timeout defaults by provider:
| Provider | Default | Environment Variable |
|---|---|---|
| Bedrock (boto3) | 300s | AWS_READ_TIMEOUT |
| Anthropic (httpx) | 600s | — (use ModelSettings(timeout=...)) |
For Bedrock with Opus, 300s may not be enough. Set a higher timeout:
export AWS_READ_TIMEOUT=600
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
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 groundmark-0.2.1.tar.gz.
File metadata
- Download URL: groundmark-0.2.1.tar.gz
- Upload date:
- Size: 567.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44bbecadbf31295248f36ec46a973f78ff67d911c0d32d1f878b003a2383fe64
|
|
| MD5 |
ce0919c475b4e4c36fa0d3b9fe73b78c
|
|
| BLAKE2b-256 |
a4864b307cd097cc5b916b1d1faf698da9d47b59812f1e14ce281a3a23befc01
|
Provenance
The following attestation bundles were made for groundmark-0.2.1.tar.gz:
Publisher:
release.yaml on populationgenomics/groundmark
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
groundmark-0.2.1.tar.gz -
Subject digest:
44bbecadbf31295248f36ec46a973f78ff67d911c0d32d1f878b003a2383fe64 - Sigstore transparency entry: 1118639505
- Sigstore integration time:
-
Permalink:
populationgenomics/groundmark@e4187be0ea30b8529a77b46d9f2b969bdc0638aa -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/populationgenomics
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@e4187be0ea30b8529a77b46d9f2b969bdc0638aa -
Trigger Event:
release
-
Statement type:
File details
Details for the file groundmark-0.2.1-py3-none-any.whl.
File metadata
- Download URL: groundmark-0.2.1-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3b5d2962f038c5f140d3f20ed48a49ce54f36916fc736251724d97cebb37e40
|
|
| MD5 |
33ed4a98e698f7e59e635dc3b636011a
|
|
| BLAKE2b-256 |
f80686dc2b57d91b0689da66c3f1e7c53a32f4ee5895ccc6d229fe1b05a391bf
|
Provenance
The following attestation bundles were made for groundmark-0.2.1-py3-none-any.whl:
Publisher:
release.yaml on populationgenomics/groundmark
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
groundmark-0.2.1-py3-none-any.whl -
Subject digest:
d3b5d2962f038c5f140d3f20ed48a49ce54f36916fc736251724d97cebb37e40 - Sigstore transparency entry: 1118639518
- Sigstore integration time:
-
Permalink:
populationgenomics/groundmark@e4187be0ea30b8529a77b46d9f2b969bdc0638aa -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/populationgenomics
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@e4187be0ea30b8529a77b46d9f2b969bdc0638aa -
Trigger Event:
release
-
Statement type: