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

<table> markup<tr>, <td>, CSS classes, and wrapper <div> noise routinely burn 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.

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:

| characters across hundreds of lines. One unescaped comma or wrapped cell shifts every downstream column. "model_id", "provider", "input_price" on every row. Before we even get to serialization format, raw HTML tables from real SaaS apps and financial portals break almost every quick copy-paste script:

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;
  }
}

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 };
}

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.

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:

~388 tokens ~302 tokens ~149 tokens (Blocker Notes fields.~1,891 tokens ~752 tokens (min=0.08, max=3, sum=24.39 precomputed in TABLE_CONTEXT.md). We shipped this exact engine in two places — both 100% browser-local with zero server uploads and zero analytics:

TOON, Markdown-KV, or full .xlsx, Multi-Page Basket, and full This wraps up v1.1.0 across all four Kinto Labs local browser utilities designed for AI-assisted workflows:

DESIGN.md GeneratorVISUAL_DIFF.md Prompt 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.

原文来源:dev.to