Lesson 2 of 3 Document Extraction with Content Understanding

Producing Clean, Grounded Document Representations for RAG and Agents

This lesson explains how Content Understanding produces Markdown that preserves document structure and links content to its source, avoiding the lost headings, scrambled columns and broken tables of raw extracted text.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain why Markdown suits retrieval and language models.
  • Use spans and structural elements to ground content in its source.
  • Describe the prebuilt analyzers designed for RAG.
  • Fix common document representation problems at ingestion.

Why Markdown

A PDF stores characters and their positions on a page, not the reading order or the structure that a person sees. When plain text is extracted from it, a two-column page can come out as alternating half-lines from each column, a table becomes a run of numbers without row or column labels, and headings look like ordinary sentences. A model that receives this text has to guess at the structure, and a chunker that splits it by length cuts through tables and sections. Both problems lower answer quality before retrieval or generation even begins.

Markdown keeps a document's structure in plain text: headings (#, ##), lists, tables in pipe format and figure placeholders or descriptions. Language models read Markdown well, chunkers can split it at headings, and tables remain intact as single units. A clean representation also removes page headers, footers and page numbers that would otherwise repeat in every chunk.

The following screenshot shows the Markdown tab for the same invoice. Headings, key-value lines and the line-item table keep their structure, so a chunk of this text still shows which value belongs to which label.

Markdown output of the invoice analyzer with the invoice heading, key fields and the line-item table
Tables kept as Markdown tables stay readable for a model after chunking.

Grounding information

Content Understanding returns, alongside the Markdown, structural elements (pages, paragraphs, sections, tables, figures) and spans that map each element to its offset in the Markdown and its position in the source document. When content is chunked and indexed with these page and position details, an answer can cite "Contract 2291, page 7, section 4.2" and link to the exact region. Fields carry the same grounding, so an extracted value can be shown with its source.

Prebuilt analyzers for RAG

An analyzer is the Content Understanding configuration that defines what to extract from a type of content. Prebuilt analyzers are supplied by Microsoft and need no configuration. Some target business fields, such as invoice totals, while the search analyzers target retrieval: they produce a clean, structured representation of the whole file that can be chunked and indexed for RAG and agents.

prebuilt-documentSearch is designed for retrieval: it returns Markdown with layout, descriptions of figures (charts and diagrams described in text) and a document summary. The image, audio and video search analyzers do the same for other modalities. The following list shows how the output is used.

  1. Analyze

    Analyze each new document with the search analyzer.

  2. Chunk

    Split the Markdown at headings into chunks, keeping tables whole.

  3. Index

    Index chunks with the summary, title, page numbers and source path.

  4. Retrieve and cite

    Agents and RAG applications retrieve chunks and cite page and section.

The following screenshot shows the prebuilt-documentSearch analyzer on a two-column résumé. The Markdown follows the reading order, keeping each column's headings and paragraphs together instead of mixing lines from both columns.

Document search analyzer with a two-column résumé and its Markdown output in reading order
Reading order matters for RAG: a chunk that mixes two columns cannot be cited reliably.

Common representation problems

Poor document representations are a frequent root cause of weak RAG answers, and they are easier to fix at ingestion than at query time. Each typical problem has a recognizable symptom and a standard fix. The following table lists them.

ProblemSymptomFix
Repeated headers and footersMany chunks share the same boilerplate text and rank highly for unrelated queriesUse layout output that labels and removes page headers and footers
Tables split across chunksAnswers miss values or mix rows from different tablesChunk at headings and keep each table whole
Charts and diagrams ignoredQuestions about figures return nothingUse an analyzer that generates figure descriptions
Multi-column text out of orderSentences from different columns are joinedUse layout analysis that reads columns in order
No page or section metadataAnswers cannot cite their source locationIndex spans, page numbers and section headings with each chunk
Match the pairs

Fix the representation

Exam skills 5.2.2

Match each document representation problem with its fix.

Log in to try this activity Interactive activities are free with an account.
Worked example

An agent that reads uploads

Users upload 50-page technical reports to an agent and ask questions about their tables and charts. The agent's answers about charts are often wrong because the extracted text contains only axis labels.

Process uploads with prebuilt-documentSearch (exposed to the agent as a tool or run on upload), so charts are described in text and tables are preserved in Markdown, and give the agent the Markdown with page references. Increasing the model size would not recover information missing from the extracted text.

Check yourself

Why convert documents to Markdown for RAG?

Show answer

Markdown keeps headings and tables, which helps chunking and lets models read the structure.

Exam Tips

Remember for the exam

  • Markdown preserves headings and tables for chunking and model reading.
  • Spans and page numbers let answers cite exact sources.
  • prebuilt-documentSearch adds figure descriptions and a summary for RAG.