<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Guilherme Michels</title>
    <description>The latest articles on DEV Community by Guilherme Michels (@guilherme_michels).</description>
    <link>https://dev.to/guilherme_michels</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4211402%2F4bd87b74-e40b-4182-83e9-af4917207e4a.jpg</url>
      <title>DEV Community: Guilherme Michels</title>
      <link>https://dev.to/guilherme_michels</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/guilherme_michels"/>
    <language>en</language>
    <item>
      <title>Markdown vs JSON vs Raw Text for LLMs: Which Format Uses Fewer Tokens?</title>
      <dc:creator>Guilherme Michels</dc:creator>
      <pubDate>Tue, 27 Oct 2026 17:09:28 +0000</pubDate>
      <link>https://dev.to/guilherme_michels/markdown-vs-json-vs-raw-text-for-llms-which-format-uses-fewer-tokens-48ap</link>
      <guid>https://dev.to/guilherme_michels/markdown-vs-json-vs-raw-text-for-llms-which-format-uses-fewer-tokens-48ap</guid>
      <description>&lt;p&gt;Every prompt you send to a language model has a price and a failure mode. The format you feed in — and the format you ask the model to return — quietly decides how much you pay per document and how often the output breaks your automation downstream.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why token efficiency is more than "saving money"
&lt;/h2&gt;

&lt;p&gt;Tokens are the unit LLMs read and bill in. When you waste them, you don't just pay more — you push closer to context limits, slow every response down, and give the model more room to drift off the structure you actually need. On a workflow that processes thousands of documents a month, the format decision compounds into real cost and real accuracy.&lt;/p&gt;

&lt;p&gt;In short:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;3&lt;/strong&gt; formats compared: raw text, Markdown, JSON&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;4&lt;/strong&gt; habits that inflate a token count: repeated keys, nesting, long names, whitespace&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;1&lt;/strong&gt; schema to validate every result against&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Quick definitions: raw text, Markdown, and JSON
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Raw text&lt;/strong&gt; is the plain, unstructured dump of a document — everything the OCR or parser saw, in reading order, with no markup. It's the cheapest to produce and the hardest to trust: there's no signal about what a value &lt;em&gt;means&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Markdown&lt;/strong&gt; keeps a light layer of structure — headings, lists, tables — that humans read comfortably and models reason over well. It's the sweet spot for anything a person still reviews.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JSON&lt;/strong&gt; is machine-native. Every value has a named field, so downstream systems can consume it without guessing. It's the format you want the moment a document feeds an ERP, a database, or a payment run — as long as you design the schema deliberately.&lt;/p&gt;

&lt;h2&gt;
  
  
  The big trade-off: human readability vs. machine reliability
&lt;/h2&gt;

&lt;p&gt;There is no single "best" format — there's the right format for where the output is going. Raw text and Markdown are easy for people; JSON is reliable for machines. Push structure too early and you fight the model; push it too late and you hand a human a wall of text to reconcile by hand.&lt;/p&gt;

&lt;h2&gt;
  
  
  Token usage: what increases or reduces the count
&lt;/h2&gt;

&lt;p&gt;Token-heavy patterns are the usual culprits: repeated keys, deeply nested objects, verbose field names, and pretty-printing with lots of whitespace. Token-efficient patterns do the opposite — short but clear keys, flat structures where possible, and a stable schema the model can lean on instead of re-describing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Design JSON for token efficiency.&lt;/strong&gt; A compact, well-named schema can cut tokens versus a naïve verbose dump &lt;em&gt;without&lt;/em&gt; losing a single field you care about. In an illustrative one-page invoice, the same data takes 1,610 tokens as verbose JSON and 980 as a compact schema.&lt;/p&gt;

&lt;h2&gt;
  
  
  When to use each format (practical guide)
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Format&lt;/th&gt;
&lt;th&gt;Best for&lt;/th&gt;
&lt;th&gt;Watch out for&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Raw text&lt;/td&gt;
&lt;td&gt;Early exploration, simple Q&amp;amp;A, quick summaries&lt;/td&gt;
&lt;td&gt;No field-level meaning; hard to validate&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Markdown&lt;/td&gt;
&lt;td&gt;Human review layers, auditable outputs, semi-structured reasoning&lt;/td&gt;
&lt;td&gt;Tables still need parsing before a system can use them&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JSON&lt;/td&gt;
&lt;td&gt;Automation, integrations, reliable downstream parsing&lt;/td&gt;
&lt;td&gt;Verbose schemas burn tokens; drift breaks consumers&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  The missing link: why structured parsing beats "prompt-only" extraction
&lt;/h2&gt;

&lt;p&gt;Asking a model to "return the fields as JSON" in a free-form prompt works in a demo and fails in production. The schema drifts, a field goes missing, a number comes back as a string, and the automation that trusted it silently breaks. &lt;strong&gt;Structured parsing&lt;/strong&gt; pins the output to a defined schema and validates every result against it — so what reaches your system is predictable, not hopeful.&lt;/p&gt;

&lt;p&gt;An example result pinned to a schema (&lt;code&gt;invoice.json&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"supplier"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ACME Components Ltd."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"invoice_number"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"INV-2026-00814"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"issue_date"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2026-02-11"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"due_date"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2026-03-12"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"currency"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"USD"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"line_items"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"subtotal"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;4820.00&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"tax"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;385.60&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"total"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;5205.60&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because the shape is fixed, you can validate totals, normalize dates, and reject anything that doesn't fit — automatically — instead of trusting that "the model usually gets it right."&lt;/p&gt;

&lt;h2&gt;
  
  
  Best practices for prompts and outputs
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Keep schemas stable.&lt;/strong&gt; A consistent schema is easier for the model and for every consumer downstream.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Normalize and deduplicate.&lt;/strong&gt; Standardize dates, currencies, and identifiers at extraction time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prefer structured extraction over "creative" generation.&lt;/strong&gt; You want fidelity, not prose.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Validate totals and formats automatically.&lt;/strong&gt; Let the schema catch what a human would miss.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Common questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What format is best for LLM input: Markdown, JSON, or raw text?
&lt;/h3&gt;

&lt;p&gt;For most extraction workflows, Markdown is the best &lt;em&gt;input&lt;/em&gt; because it preserves structure the model can reason over while staying token-efficient. For &lt;em&gt;output&lt;/em&gt;, JSON wins whenever the result feeds another system.&lt;/p&gt;

&lt;h3&gt;
  
  
  Does JSON always use more tokens than Markdown?
&lt;/h3&gt;

&lt;p&gt;No. Verbose, pretty-printed JSON does — but a compact, well-designed schema can be comparable to or leaner than Markdown while remaining fully machine-parseable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why does structured parsing improve model performance?
&lt;/h3&gt;

&lt;p&gt;A fixed schema removes ambiguity. The model spends its effort filling known fields instead of inventing structure, which reduces drift, retries, and manual fixes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Putting it all together
&lt;/h2&gt;

&lt;p&gt;Use raw text to explore, Markdown to review, and JSON to automate — and pin that JSON to a validated schema so it stays reliable at volume. The format isn't a cosmetic choice; it's the lever that controls your token bill and your automation's failure rate at the same time.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on the &lt;a href="https://parserai.co/blog/markdown-vs-json-vs-raw-text-how-to-optimize-token-usage-and-model-performance-with-structured-parsing?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=crosspost" rel="noopener noreferrer"&gt;Parser blog&lt;/a&gt;. I work on &lt;a href="https://parserai.co/?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=crosspost" rel="noopener noreferrer"&gt;Parser&lt;/a&gt;, which extracts the fields you define from invoices, receipts, bank statements and contracts as JSON, Excel or CSV. There's a free plan if you want to try it on your own documents.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>json</category>
      <category>promptengineering</category>
    </item>
  </channel>
</rss>
