Markdown 4 min read

Markdown, JSON or HTML: Choose an LLM Input Format

Choose an LLM input format by what the task must preserve. Compare Markdown, JSON, plain text and HTML without assuming training or token savings.

(Updated: ) • 680 words

Markdown is useful when an LLM needs to read a document that a person also needs to inspect. Headings, lists, links and fenced code remain visible in a text file, without carrying all the layout markup of the original webpage. That makes Markdown a practical interchange format for retrieved articles, notes and documentation.

It is a format choice, not a requirement imposed by language models. A JSON response, a plain-text passage or an HTML fragment may be the better input for a particular task. The important question is what must survive the conversion.

Choose a representation for the next operation

Consider a documentation page containing installation steps, a parameter table and a warning about deleting data. A useful extraction keeps the warning attached to the operation it qualifies. Removing navigation is helpful; removing the warning is a data loss, even if the output looks cleaner.

Next operation Useful representation Check before accepting it
Read or summarize an article with sections and examples Markdown with source metadata Headings, qualifications, code and meaningful links remain present
Validate fixed fields such as product ID, price and currency JSON with an application schema Required fields, types and units are explicit; missing is different from zero
Pass a short quotation with no structural dependencies Plain text with a source locator The quotation remains verbatim and has enough surrounding context
Inspect selectors, attributes or a table the conversion damaged Retained HTML or the original document The required element and its attributes can be inspected directly

These formats can coexist. A RAG record can store Markdown as its readable body, JSON for URL and revision metadata, and the original HTML for checking extraction failures. The body format does not replace the source record.

Markdown keeps some structure, not every detail

The CommonMark specification defines headings, lists, links and fenced code. Tables require a compatible extension, such as GitHub Flavored Markdown. A renderer that supports one dialect may display another differently.

A simple pipe table can work well for a few columns. A table with merged cells, multi-level headers, footnotes or embedded line breaks needs closer inspection. Flattening it into text can separate a value from its unit or associate it with the wrong row. Keep the original when those relationships matter.

Links need similar care. A label such as “download” may be understandable in a browser but unhelpful after the destination is dropped. Relative links also need the original page URL if the application will resolve them later.

Parsing a document and tokenizing a prompt are separate steps

An application can parse Markdown into an abstract syntax tree to inspect its headings or tables. That is application preprocessing. It does not mean a language model’s tokenizer receives that tree or automatically validates Markdown grammar.

For example, tiktoken encodes text strings into token IDs. The count depends on the exact string and encoding. Characters are not interchangeable with tokens, and converting HTML to Markdown does not establish a fixed saving across documents.

For a reproducible count, use the HTML versus Markdown token-count example. Keep that measurement separate from answer quality: a smaller input can still omit the sentence needed to answer the question.

Check the conversion against the task

Before sending extracted content to a model, choose a few things that the downstream task must retain. For the documentation example, those might be the installation command, the parameter’s unit and the deletion warning. Compare them with the original rather than judging the output by its length.

  • Keep the source URL, retrieval time and revision identifier outside the prose.
  • Check a table cell together with its row label and unit.
  • Check code as code, including indentation and punctuation.
  • Distinguish an empty extraction from a document that genuinely has no answer.

The SearchCans Reader API returns extracted Markdown in data.markdown. Receiving that field is a starting point for these checks, not proof that every source detail survived. The Markdown formatting guide shows how to test document structure before model evaluation.

Choose Markdown when it preserves what the reader and application need. Keep structured data structured, retain originals for difficult cases, and measure model behavior separately from the format conversion.

Tags:

Markdown AI Data Format LLM Training Data Standards
SearchCans Team

SearchCans Team

SERP API & Reader API Experts

The SearchCans engineering team builds high-performance search APIs serving developers worldwide. We share practical tutorials, best practices, and insights on SERP data, web scraping, RAG pipelines, and AI integration.

Ready to build with SearchCans?

Test SERP API and Reader API with 100 free credits. No credit card required.