If you paste web tables, SaaS dashboards, or CSV exports into Claude, Cursor, or ChatGPT, you have probably noticed two maddening failure modes:

  1. Paste raw HTML <table> markup and your context window evaporates. Repeated <tr>, <td>, CSS classes, and wrapper <div> noise routinely burn 2x to 4x more tokens than the actual cell data.
  2. Paste raw CSV or wide Markdown pipe tables and the model starts hallucinating values from adjacent columns — or mis-summing revenue numbers by 15%.

When we upgraded SheetDock (our zero-tracking browser table extractor, now live on Firefox Add-ons) to v1.1.0, we dug into the actual benchmarks behind why LLMs fail on tables — and built a 100% browser-local optimizer to fix all three failure modes without uploading private data to any server.

The Accuracy vs. Token Trap (What Controlled Benchmarks Actually Show)

Most developers assume "fewer tokens = better prompt." Controlled tabular retrieval benchmarks (such as the 1,000-record structured lookup evaluations discussed across Improving Agents, Hacker News, and r/LocalLLaMA) reveal a much sharper trade-off:

Format Relative Token Footprint Tabular Retrieval Accuracy Why It Wins or Breaks
Raw HTML <table> Highest (2x–4x bloat) Degraded by tag noise Burns context budget on class="..." and DOM wrappers
Pretty JSON High (~66k tokens / 1k rows) ~52.3% Repeats every column key on every single row
Markdown-KV Medium (~52k tokens / 1k rows) ~60.7% (Highest) Explicit **Key**: Value binding eliminates column-shift errors
GFM Markdown Pipe Low (~25k tokens / 1k rows) ~51.9% Great for narrow tables; wide 8+ col tables cause pipe-counting drift
TOON Lowest (30–60% < JSON) ~47.5–51.2% Declares schema once (rows[N]{col1,col2}:) for huge savings on uniform data
CSV / Pipe-Delimited Lowest (~19.5k tokens / 1k rows) ~41.1–44.3% (Worst) No visual/key anchor — LLMs frequently misalign column index k on row n

Look closely at that table. There is no single universally "best" table format for an LLM:

  • On a wide 8-column CRM pipeline or a sparse table with long notes, CSV and pipe Markdown force the model to count commas or | characters across hundreds of lines. One unescaped comma or wrapped cell shifts every downstream column. Markdown-KV jumps accuracy by nearly +18 percentage points over CSV because every value sits directly next to its column label — and empty cells can be omitted cleanly.
  • On a uniform 25-row pricing or benchmark table with 3–5 compact columns, Pretty JSON wastes half your context window repeating "model_id", "provider", "input_price" on every row. TOON (Token-Oriented Object Notation) cuts 50%–60% of JSON tokens while keeping an explicit schema header right at the top.

Three Bugs Naive Converters Quietly Introduce

Before we even get to serialization format, raw HTML tables from real SaaS apps and financial portals break almost every quick copy-paste script:

1. Unmerged colspan and rowspan Matrices

Multi-row headers (<th colspan="2">Account Details</th> above SKU and Company) and grouped left columns (<td rowspan="2">North America</td>) leave holes in row 2 if you just iterate tr > td.

To preserve ground truth for an LLM, you have to maintain a 2D occupancy grid while walking the DOM, propagating spanned cells forward and joining multi-row <thead> headers into unambiguous paths like Account Details / SKU / ZIP:

for (let dr = 0; dr < rowspan; dr++) { if (!grid[r + dr]) grid[r + dr] = []; for (let dc = 0; dc < colspan; dc++) { grid[r + dr][colIdx + dc] = text; } } 

2. Leading-Zero Destruction

If a downstream script coerces "02139" (Boston ZIP) or "00481" (SKU) into integers 2139 and 481, both Excel and your LLM lose the true identifier. Any numeric classifier must explicitly guard /^0\d+$/ as literal strings:

if (/^0\d+$/.test(s)) { return { kind: 'string', value: s }; } 

3. Asking LLMs to Do Column Arithmetic From Scratch

Even frontier models occasionally miss a row when summing 40 currency strings like $12,450.50 and $8,900.00. Computing exact deterministic min, max, sum, non-empty, and distinct counts locally in JavaScript and prepending a 5-line Markdown schema header takes < 1 millisecond — and gives the LLM verified ground-truth anchors before it reads row 1.

How Our Auto-Recommender Chooses Between TOON and Markdown-KV

Instead of making developers guess, we wrote a deterministic zero-dependency engine (llm-formatter.js, ~220 lines of plain JS) that inspects the parsed matrix shape and picks the optimal serialization automatically:

export function recommendLlmFormat(headers, rows) { const colCount = headers.length; // Compute average cell length & emptiness ratio locally... if (colCount >= 6 || avgCellLen >= 28 || emptyRatio >= 0.35) { return { format: 'markdown-kv', label: 'Markdown-KV' }; } return { format: 'toon', label: 'TOON' }; } 

Here is what real local measurements look like across three everyday workloads:

  1. 4×5 HTML Billing Table (with colspan/rowspan):
    • Raw HTML: ~388 tokens
    • Pretty JSON: ~302 tokens
    • TOON: ~149 tokens (-62% vs raw HTML, -51% vs Pretty JSON)
  2. 5×8 Enterprise CRM Pipeline (wide + sparse notes):
    • Engine auto-switches to Markdown-KV to prevent column-shift hallucinations while omitting empty Blocker Notes fields.
  3. 24×5 LLM Inference Pricing Benchmark:
    • Pretty JSON: ~1,891 tokens
    • TOON: ~752 tokens (-60% token savings, with exact local min=0.08, max=3, sum=24.39 precomputed in TABLE_CONTEXT.md).

Try It Locally (Zero Upload, Zero Tracking)

We shipped this exact engine in two places — both 100% browser-local with zero server uploads and zero analytics:

  1. Free Zero-Upload Web Tool: HTML Table & CSV to TOON / Markdown-KV / LLM Prompt Optimizer Paste raw HTML <table>, CSV, TSV from Excel/Sheets, or JSON arrays to see live side-by-side token bars, test colspan/rowspan unmerging, and copy TOON, Markdown-KV, or full TABLE_CONTEXT.md prompts immediately.
  2. SheetDock v1.1.0 Browser Extension: Install on Firefox Add-ons Extracts live HTML tables, ARIA grids, and virtualized React lists from any authenticated page with unlimited free rows for CSV, JSON, Markdown, TOON, and Markdown-KV (and an optional $15 one-time Pro upgrade for native typed .xlsx, Multi-Page Basket, and full TABLE_CONTEXT.md / SQL / TypeScript / Zod / pandas codegen — no yearly subscription).

Part of Our 100% Local AI-Agent Developer Toolkit

This wraps up v1.1.0 across all four Kinto Labs local browser utilities designed for AI-assisted workflows:

Curious what table format you have found most reliable in your own Claude / Cursor / local Qwen4 pipelines — are you team TOON, Markdown-KV, or plain JSON? Drop your benchmarks in the comments.