Markdown output that agents actually parse — one dropped fence hint taught me

Markdown output that agents actually parse — one dropped fence hint taught me

When I shipped the universal document-to-Markdown endpoint, the first integration I tested was feeding a 40-page PDF (full of code samples) into an agent's context window via RAG. The retrieval half worked fine; the generation half gave me garbage. The culprit: every fenced code block had lost its language hint. instead of python . The chunking logic in several retriever variants splits on language-tag boundaries, and without the hint, chunks bled into prose and the model hallucinated imports that matched the surrounding text.

I traced it to a single line in the HTML-to-Markdown step: the language-* class on <pre> blocks was being stripped before code-block emission because I'd assumed agents don't care about syntax hints. They do — both directly, for context, and indirectly, in downstream tools that re-chunk. I fixed the emitter to carry through class="language-python" and any data-lang, then re-tested end to end. Quality jumped.

The takeaway I keep retelling myself before every release: output format is a contract, not presentation. Agents downstream parse what you write, and silent losses — a missing hint, a dropped newline, a list-marker change — compound quietly because no exception is ever raised. I packaged the fixed converter as https://x402.freeq.one/tools/document_to_markdown.html only after running it against PDF, DOCX, PPTX and HTML inputs and checking round-trip parse against a couple of embedding models. If you ship a writer, diff its output against what a parser expects, not just what looks pretty.