# MarkItDown for LLM and RAG pipelines

> Is MarkItDown good for RAG? Token counts against plain text and HTML, how to chunk its output at headings, and the gaps to plan for. Loaders were not tested.

Source: https://markitdown.dev/rag/ · Updated 2026-11-16·Upstream source ↗

MarkItDown produces Markdown that models read well, and that mostly helps retrieval: headings, lists and tables survive from Office files. The gaps are known: PDFs have no headings, scanned pages are empty, and Excel blanks become `NaN`. We measured tokens on three documents and tested a heading-based chunker; we did not test the LangChain or LlamaIndex loaders.

> **Short answer**
>
> -   **Word, PowerPoint, HTML:** good structure to chunk on.
> -   **Text PDFs:** clean text without headings: chunk by size or page.
> -   **Scans:** nothing without OCR ([OCR](https://markitdown.dev/ocr/)).
> -   **Excel:** tables with `NaN` to clean ([recipe](https://markitdown.dev/formats/excel/)).

Tested with markitdown 0.1.9 · Python 3.13 · markitdown 0.1.9 · three sample documents for token counts with two tokenizers (T22); LangChain and LlamaIndex loaders were NOT tested · 2026-11-16 · evidence: [token-counts.csv](https://markitdown.dev/data/token-counts.csv), [format-matrix-summary.csv](https://markitdown.dev/data/format-matrix-summary.csv)

## Tokens: Markdown against plain text and HTML

The same three documents as raw extracted text, as HTML and as MarkItDown Markdown, with two tokenizers
| Document | Form | Characters | Tokens (cl100k\_base) | Tokens (o200k\_base) |
| --- | --- | --- | --- | --- |
| `report.docx` | raw extracted text | 665 | 191 | 186 |
| `report.docx` | HTML | 1165 | 451 | 449 |
| `report.docx` | MarkItDown Markdown | 838 | 266 | 261 |
| `pdf-text.pdf` | raw extracted text | 927 | 189 | 188 |
| `pdf-text.pdf` | HTML | 1053 | 267 | 267 |
| `pdf-text.pdf` | MarkItDown Markdown | 926 | 188 | 187 |
| `workbook.xlsx` | raw extracted text | 291 | 133 | 131 |
| `workbook.xlsx` | HTML | 1770 | 708 | 716 |
| `workbook.xlsx` | MarkItDown Markdown | 526 | 209 | 218 |

*The same three documents as raw extracted text, as HTML and as MarkItDown Markdown, with two tokenizers Source: Test T22 · markitdown 0.1.9 · 2026-11-15 · token-counts.csv · Download CSV*

Markdown cost more tokens than raw text for the Word file (266 against 191) and the workbook (209 against 133), which is the price of keeping headings and table structure, and far fewer than HTML (451 and 708). The text PDF came out the same as raw text (188 against 189), because MarkItDown adds no structure there. Three documents are a small sample: do not extrapolate.

## Chunking MarkItDown output

### Split on headings where they exist

```python
import re
from markitdown import MarkItDown

md = MarkItDown()
text = md.convert("samples/report.docx").markdown
# split before every heading of level 1 to 3 and keep the heading with its text
chunks = [c.strip() for c in re.split(r"(?m)^(?=#{1,3} )", text) if c.strip()]
for i, chunk in enumerate(chunks):
    print(f"chunk {i}: {len(chunk):>4} characters, starts {chunk.splitlines()[0]!r}")
```

Output · markitdown 0.1.9 · Python 3.13.18 · 2026-11-16

```
chunk 0:   33 characters, starts 'Pilot Report: Field Station Alpha'
chunk 1:  113 characters, starts '# 1. Summary'
chunk 2:  147 characters, starts '## 1.1 Key findings'
chunk 3:   79 characters, starts '## 1.2 Next steps'
chunk 4:  224 characters, starts '# 2. Measurements'
chunk 5:   79 characters, starts '## 2.1 Chart'
chunk 6:  151 characters, starts '### 3. Deep heading level three'
```

[captured result](https://markitdown.dev/evidence/snippets/api-chunk-headings/result.json)

For PowerPoint, split on the slide-number comment ([PowerPoint page](https://markitdown.dev/formats/powerpoint/)); for Excel, on the `##` sheet headings ([Excel page](https://markitdown.dev/formats/excel/)).

### PDFs have no headings

Chunk by size or page; the output has no page markers, so citing a page needs another approach ([PDF page](https://markitdown.dev/formats/pdf/)). We did not test a page-range workaround.

### Keep tables whole

A chunk boundary inside a pipe table separates the header from its rows. We did not measure the effect on retrieval.

### Clean before embedding

Blank `NaN` cells, truncated image placeholders and repeated page headers and footers are in the output; see the format pages for the tested clean-up steps.

## LangChain and LlamaIndex

We did not test any loader or reader built on MarkItDown, so we cannot say which exist or whether they work with current versions.

## Metadata to keep

Source path, file type and the MarkItDown version, because output changes between releases ([releases](https://markitdown.dev/releases/)). The result object has `.markdown` and `.title`; we did not find per-page information in it.

## Doing many files

Reuse one converter in one process ([batch page](https://markitdown.dev/batch/)).

## Related

- [Supported formats](https://markitdown.dev/formats/): How each format converts, graded.
- [PDF to Markdown](https://markitdown.dev/formats/pdf/): PDF structure.
- [Excel (XLSX, XLS)](https://markitdown.dev/formats/excel/): Excel and NaN.
- [OCR and scanned files](https://markitdown.dev/ocr/): Scanned pages.

---
Independent guide to the open-source MarkItDown library. Not affiliated with or endorsed by Microsoft. Official source: https://github.com/microsoft/markitdown
