LlamaParse - Document Parsing for RAG Cheatsheet
LlamaParse is a document parsing service from the LlamaIndex team, built specifically for LLM and RAG pipelines. Its focus is the hard case: PDFs with complex tables, multi-column layouts, figures, and embedded charts that generic text extractors flatten into unusable text. It outputs clean Markdown that preserves structure, and its distinguishing feature is natural-language parsing instructions — you describe how the document is laid out and what to do with it, rather than configuring extraction rules.
LlamaParse is a hosted service with a free tier (API key required). For fully local parsing see Docling or Marker.
Installation
| Method | Command |
|---|
| pip | pip install llama-parse |
| With LlamaIndex | pip install llama-index llama-parse |
| API key | export LLAMA_CLOUD_API_KEY="llx-..." |
| Verify | python -c "from llama_parse import LlamaParse; print('ok')" |
Basic Parsing
from llama_parse import LlamaParse
parser = LlamaParse(result_type="markdown")
documents = parser.load_data("./report.pdf")
print(documents[0].text)
| Parameter | Purpose |
|---|
result_type | "markdown" (structure-preserving) or "text" |
num_workers | Parallel page processing |
verbose | Progress output |
language | Document language hint |
parsing_instruction | Natural-language guidance (below) |
Parsing Instructions (the differentiator)
parser = LlamaParse(
result_type="markdown",
parsing_instruction="""
This is a financial report. Preserve all tables as Markdown tables.
For each chart, write a one-paragraph description of the trend it shows.
Ignore page headers and footers.
""",
)
You describe the document and desired handling in plain language rather than writing extraction code — useful for domain-specific layouts (invoices, scientific papers, legal contracts) where generic parsers do poorly.
Async & Batch
import asyncio
async def parse_many(paths):
parser = LlamaParse(result_type="markdown", num_workers=8)
return await parser.aload_data(paths)
docs = asyncio.run(parse_many(["a.pdf", "b.pdf", "c.pdf"]))
| Method | Use |
|---|
load_data(path) | Single file, synchronous |
aload_data([paths]) | Async, multiple files |
get_json_result(path) | Structured JSON with page metadata |
get_images(...) | Extract embedded images |
| Format | Note |
|---|
| PDF | Primary target, including scanned (OCR) |
| DOCX / PPTX / XLSX | Office formats |
| HTML | Web documents |
| Images | PNG/JPEG via OCR |
Wiring into a RAG Pipeline
from llama_parse import LlamaParse
from llama_index.core import VectorStoreIndex
from llama_index.core.node_parser import MarkdownElementNodeParser
docs = LlamaParse(result_type="markdown").load_data("./manual.pdf")
# Markdown-aware chunking keeps tables and sections intact
node_parser = MarkdownElementNodeParser()
nodes = node_parser.get_nodes_from_documents(docs)
index = VectorStoreIndex(nodes)
Pairing Markdown output with a Markdown-aware node parser is the point: tables survive parsing and chunking, which is where most RAG pipelines lose tabular facts.
Handling Tables Well
| Technique | Why |
|---|
result_type="markdown" | Tables become Markdown grids |
| Parsing instruction for tables | Force consistent table handling |
MarkdownElementNodeParser | Keeps a table in one chunk |
| Row-per-sentence serialization | Makes individual rows retrievable |
Cost & Practical Notes
| Consideration | Detail |
|---|
| Hosted service | Documents are sent to LlamaCloud |
| Free tier | Limited pages per day |
| Caching | Re-parsing the same file can reuse results |
| Privacy | For sensitive documents prefer local parsers |
LlamaParse vs Local Parsers
| Aspect | LlamaParse | Docling | Marker |
|---|
| Hosting | Cloud service | Local | Local |
| Complex tables | Very strong | Strong | Good |
| Custom instructions | Natural language | Config | Config |
| Privacy | Data leaves your machine | Fully local | Fully local |
| Best for | Hard layouts, quick results | Self-hosted RAG ingestion | GPU bulk conversion |
For privacy-sensitive corpora use Docling; for bulk local conversion use Marker.
Resources