A Field Guide to Document Formats for LLMs (What Converts Cleanly, What Fights You)
HTML, CSV, JSON and EPUB files convert cleanly to Markdown for an LLM, while scanned PDFs and photos of pages convert worst. Word, Excel, PowerPoint and digital PDFs sit in between, and come out well when the converter maps their structure. Markdown is the best format for an LLM to read, so it is the target for every file.
A knowledge base often mixes these document formats: PDFs, Word files, spreadsheets, a few scanned contracts, saved web pages and the odd PowerPoint. How much work each file needs before an LLM can use it depends on how much of its structure is already stored as text.
Why Markdown is the destination
Markdown encodes structure (headings, lists, tables) in plain text, without the page layout and styling that PDF and DOCX files store alongside the words. It is compact, and it splits cleanly into chunks at its headings for retrieval. So the question for each format is how much work it takes to reach Markdown.
Document formats for LLMs that convert cleanly
HTML, Markdown, plain text, CSV and JSON are text with mostly explicit structure, so conversion loses little. CSV becomes a clean table. JSON's nested objects become nested headings, and lists of simple records become tables. HTML maps heading for heading, and the work is removing the navigation, ads and scripts around the content. XML, EPUB ebooks and Jupyter notebooks belong in this group too, since all three are structured text underneath.
The middle: office documents
Word (.docx), Excel (.xlsx) and PowerPoint (.pptx) files hold real structure underneath their styling. A good converter maps Word's heading styles to Markdown headings and rebuilds Excel's grid as a table. For PowerPoint, it pulls out the text and speaker notes of each slide. A careless converter turns headings into bold text and collapses tables into loose lines. MarkPrep has a converter page for each format, including Word and Excel.
The hard part: PDFs
Digital PDFs have a text layer, so most convert as easily as the first group. Multi-column layouts still need checking, because a converter can read the columns in the wrong order. Scanned PDFs are the hard case. They are images of pages with no text to extract. They need OCR (optical character recognition) to rebuild the words from pixels before any Markdown is possible. Accuracy depends on scan quality, so check the output. The .pdf extension doesn't tell you which kind you have. A clean digital PDF and a phone photo of a page are very different jobs.
The wildcards: images and the web
Images, such as screenshots and photos of documents, need OCR, the same as scans. Web pages by URL are HTML underneath, wrapped in navigation, ads and scripts. The work is separating the article from the page around it.
Two rules for every format
- Check the size in tokens, not pages. Format changes how much text fits on a page. A table-heavy spreadsheet and a prose report with the same page count can hold very different numbers of tokens. Measure the Markdown with the token counter before you give it to an LLM.
- Keep sensitive files local. The more confidential the document, the more it matters where the conversion runs. A converter that works in your browser doesn't upload the file, which suits contracts, records and internal data.
Next step
Start with your hardest format. Convert a sample with PDF to Markdown, or the converter for its type, and read the estimated token count shown next to the Markdown.
Try it on your own file
Convert a document and watch the token counter. It's free, needs no account and uploads nothing.