How Do You Handle Tables, PDFs and Images?
Why retrieval-augmented generation (RAG) breaks on tables, PDFs and images, and how to parse, keep and search them, explained simply for your AI interview.
In short
Parse the file with a layout parser, not plain text, so tables keep their headers and scans get OCR (reading the letters from a picture). Keep each table whole, describe each chart or keep its page picture, and keep the page number so answers can cite it. Then test on questions that need a table number.
12 min readIntermediateCommon · estimateFacts checked 26 November 2026
Say it out loud
Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.
Tables, PDFs and images are where RAG often goes wrong. A plain text dump loses the table's columns, and a scan has no text until you run OCR, which reads the letters. So I parse the file with a layout parser, keep each table whole with its headers, and store the page number so the answer can point back to it. Charts get a short description, or the page picture goes to a model that can see it. Then I test with real questions that need a number from a table.
The first mistake is treating every file as plain text. A PDF can hold a text layer, which is real text, or it can be a scan, which is only a picture of a page. A scan needs OCR, optical character recognition, to turn the letters into text. Either way, a plain text dump loses the table's columns, so a fee of 35 can end up with no label next to it.
So I parse first. A layout parser reads the page, finds the tables and headings, and returns each table as one unit with its column names. I keep a small table whole. If a table is too long for one chunk, I split it by row, and each piece repeats the table title and column names. Each chunk also keeps its page number and source file, so the answer can cite the page and a person can check it.
Charts and photos are different. I either write a short description of each useful chart when I index, which is cheap to search but can miss a detail, or I keep the page picture and send it to a vision model (an AI model that can look at pictures) when someone asks. The first is cheap per question, and the second reads the chart but costs more every time. I choose by how often people ask about that chart, and I test both on real questions.
Last, I test. I take real questions from the team, including ones that need a number from a table or a chart, and check each answer against the page. If the number is wrong, I look at the chunk first, because it may have lost its headers.
What do tables, PDFs and images have to do with RAG, in plain words?
RAG (retrieval-augmented generation) is when a bot searches your documents for the right chunk, then gives that chunk to the model to answer from. That only works if the chunk says what the text says. Many company files are PDFs with tables, scanned forms and charts, and plain text misses much of that.
Picture a new credit analyst who copies a rate table into a notebook, one line per rate and no column titles. By Friday they quote the wrong rate, because nothing on the line says which product it belongs to. A RAG bot has the same problem when a table is flattened into text.
Key words
- Parsing
- Reading a file and pulling out its text, tables and layout.
- OCR
- Optical character recognition: reading the letters in a scanned picture.
- Chunk
- One piece of a document, stored and searched as a unit.
- Page image
- A picture of a whole page, so its layout and charts survive.
- Index
- The searchable store the bot looks in to find chunks.
How do you get text out of a PDF without losing its structure?
First, check what kind of PDF it is. One made from a word processor has a text layer, meaning the words are stored as real text, so they can be read directly. A scan is only a picture, so it needs OCR before anything can be searched. Azure's document service describes this step as OCR that extracts text, tables, structure and key/value pairs.
Then parse the layout too. A layout parser keeps the page's structure, so a table comes out as cells with their headers, and a heading stays above the paragraph it belongs to. Google's Document AI also has a Gemini layout parser that returns text, tables and lists as context-aware chunks.
From a PDF to searchable chunks
A policy PDF
text pages, scans and tables
Layout parser
reads scans, with OCR where needed
Keep each piece whole
Table with headers
one table, column names kept
Chart or figure
a short description, or a page picture
Prose sections
cut at headings, not mid-table
Search index
every chunk keeps its page number
- 1The file goes to a parser first, not straight into the index.
- 2A table stays one unit, with its column names.
- 3A chart becomes a short description, or its page picture is kept.
- 4Plain prose is cut at its headings.
- 5The table chunks go into the index.
- 6Figure descriptions go in too.
- 7Prose chunks go into the index with their page number, so answers can cite it.
Tip
Plain text extraction is a common cause of wrong table answers. If the parser returns a table as a run of words with no cells, fix the parser before you touch the model or the prompt.
How do you store a table so the answer is right?
- Row alone
A number with no name
The chunk says International wire: 35. It does not say which account type or currency the fee is for, so the answer can be wrong.
- Row with headers
The table title and column names come too
Each row keeps the table title, the column names and the account type, so a reader or the model can tell what 35 means.
This is a context problem. Anthropic's engineers wrote that a chunk on its own can fail to say which company or period it covers. Their fix adds a short context line to each chunk before it is embedded. For a table, the simplest context is the title and headers, repeated on every row chunk.
# A made-up business fee table, split two ways: one chunk per row, or each row with its title and headers.
TITLE = "Business account fees, USD"
HEADERS = ["Service", "Fee"]
ROWS = [["Domestic wire", "15"], ["International wire", "35"], ["Cheque deposit", "2"]]
def naive_chunks(rows):
# The row alone: the number has no title or column names around it.
return [r[0] + ": " + r[1] for r in rows]
def kept_chunks(rows):
# Each row keeps the table title and column names, so it reads correctly alone.
return [TITLE + ". " + HEADERS[0] + " | " + HEADERS[1] + ". " + r[0] + " | " + r[1] for r in rows]
print("Naive: " + naive_chunks(ROWS)[1])
print("Kept: " + kept_chunks(ROWS)[1])
print(len(kept_chunks(ROWS)), "chunks, each with the title")Output
Naive: International wire: 35 Kept: Business account fees, USD. Service | Fee. International wire | 35 3 chunks, each with the title
Microsoft's chunking guide advises reformatting tables so they are easier to process. Its other option is to have a language model write a text description of each table. That works, but Microsoft marks its processing cost as high, so you pay for it at indexing time.
How do you handle charts and images?
Charts hold facts that text extraction often misses, like a fee trend or a limit shown as a bar. You have two routes, and the trade-off is cost against accuracy.
“Documents are visually rich structures that convey information through text, but also figures, page layouts, tables, or even fonts.”
ColPali, 2024 research paper
“For non-PDF files, the Responses API doesn't extract embedded images or charts into the model context.”
OpenAI
Two ways to make a chart searchable
Chart on page 14
the fee trend is only in the picture
Route 1: when indexing
Describe it once
a model writes text, stored in the index
Route 2: when answering
Send the page image
page text indexed, picture sent later
Cheap search
a description can miss a detail
Model reads the chart
costs more on every question
- 1Route 1: a model writes a text description when you index the file.
- 2Route 2: the page text is indexed, and the page picture is sent to the model when someone asks.
- 3The description is searched like any other text.
- 4The model looks at the picture on each question, so each answer costs more.
Some setups already send the page. Anthropic says each PDF page reaches Claude as an image with its text, so you can ask about charts and diagrams. OpenAI says that for PDFs the API extracts both text and page images and sends both to models that accept image inputs, but for other file types it does not pull embedded charts into the context. Check what your API really sends before you assume the model can see a chart.
A research line called ColPali goes further and searches page images directly, instead of the text pulled out of them. It is a newer approach, so test it before relying on it.
Page images cost more. Anthropic warns that dense PDFs, with many small-font pages, complex tables or heavy graphics, can fill the model's working memory (its context window) before the page limit is reached. Split big files into sections when that happens.
How would you build search over 3,000 scanned insurance policy PDFs?
Start by sorting the pages. Some have a text layer, some are scans, and some are scans of tables. Run OCR only where there is no text, and check a sample of pages by eye.
- 1
Parse with the layout
Find the tables and headings, and keep each table whole with its title and column names.
- 2
Describe only the charts people ask about
Read the question log first. Describe the few charts that matter. Keep the rest as page pictures, with the page text indexed so the page can be found.
- 3
Tag every chunk
Store the policy number, page and table id, so answers cite the page and access rules can filter by policy.
- 4
Test on real questions
Use 100 questions the claims team actually asked, and check each number against the page.
The model should take numbers from the table it retrieved, never from memory. If the table is missing from the results, the bot should say so, not guess.
What does the interviewer want to hear?
A strong answer covers
- Check whether a PDF has a text layer or is a scan.
- Use a layout parser, so tables keep their cells and headers.
- Keep each table with its title and column names on every chunk, and split it by row only when it is too big to keep whole.
- Handle charts with a description, or a page image, and name the cost of each.
- Keep the page number on every chunk, so answers can cite it.
- Test with real questions that need a number from a table.
Common traps
Trap"Just paste the PDF text into the prompt."
BetterPlain text drops table columns and misses charts. Parse the layout first.
Trap"Chunk every 500 characters, tables included."
BetterA cut through a table splits a fee from its label. Keep tables whole.
Trap"The model reads images, so there is nothing to do."
BetterOnly some setups send page images. Check what your API really passes on.
Can you spot the problem?
Spot the problem
A user asks the bank's assistant for the international wire fee on a business account. Which retrieved chunk can the assistant answer from?
Quick check
A claim form's fee table is a photo inside a scanned PDF. Which change lets the assistant read it?
Can you answer these from memory?
Flash cards · tap a card to flip it
What will they ask next?
- Q131Retrieval metrics: recall@k, MRR, nDCG?12 min
- Q135How do you add citations?11 min
- Q139How do you keep the index fresh?11 min
- Q442How do images become tokens?Coming soon
- Q448How do you extract structured data from documents and images?Coming soon
Learn it in depth
Last updated on 26 November 2026
Building search over PDFs, tables or scanned forms?
I design and build AI products and agents, including the document pipeline behind them. Book a short call and tell me what your files look like.