Every time you send a prompt to an LLM, you pay per token. And if your data is repetitive, you're paying for the same patterns dozens, hundreds, even thousands of times. Server logs. Event traces. Audit records. The same error message repeated 400 times with different timestamps. The same file path copied across every log entry.

A new paper from arXiv shows how to compress that redundancy away without losing a single fact. No fine-tuning. No model changes. No custom training. Just a dictionary and the LLM's existing ability to learn from context.

The paper is "Lossless Prompt Compression via Dictionary-Encoding and In-Context Learning" (arXiv:2604.13066), authored by Andresa Rodrigues de Campos, David Lee, Imry Kissos, and Piyush Paritosh. It was submitted in March 2026 and is currently under review at the MLSys Conference.

Here's what it does, how it works, and why it matters.

The Problem: You're Paying to Repeat Yourself

LLM APIs charge by the token. Context windows have hard limits. Both constraints hit hardest when your data is repetitive.

Think about system logs. A typical HDFS log has the same block allocation message appearing hundreds of times. A web server log repeats the same access pattern with only the timestamp changing. When you feed 50,000 lines of that into an LLM for anomaly detection, you're burning tokens on repetition, not information.

Traditional compression (gzip, LZ77) handles this well at the bit level. But LLMs can't read gzip. You'd need to decompress before sending, which defeats the purpose.

The critical question: can an LLM read compressed data directly, if you give it the key?

The Answer: Yes, and With Stunning Accuracy

The researchers show that LLMs can learn dictionary mappings from a system prompt and then correctly interpret compressed text that uses those mappings. No fine-tuning required. The model just reads the dictionary in its system prompt and does the rest.

The results are remarkable:

  • Up to 80% compression depending on the dataset
  • 0.99+ exact match rate on decompression for template-based compression
  • 0.91+ Levenshtein similarity for algorithmic compression, even at 60-80% compression ratios
  • Compression ratio explains less than 2% of variance in quality metrics

That last point is the surprising one. Pushing compression harder doesn't meaningfully degrade output quality. What matters is the dataset's characteristics, not how aggressively you compress.

How It Works: Dictionary Encoding Meets In-Context Learning

The approach combines an old compression idea with a new LLM capability.

Dictionary encoding is a classic technique. You find repeated subsequences in your text, replace each one with a short placeholder (a "meta-token"), and include a dictionary that maps placeholders back to originals. The decompressor reads the dictionary, swaps placeholders for originals, and recovers the text exactly.

The new insight: an LLM with strong in-context learning can serve as its own decompressor. You put the dictionary in the system prompt. The compressed text goes in the user prompt. The model reads the dictionary, internalizes the mappings, and processes the compressed text as if it were the original.

The Compression Algorithm

The algorithm operates in four stages:

1. Segmentation. Split input text at whitespace boundaries into word units.

2. Subsequence identification. Scan for frequently occurring subsequences at multiple length scales. The algorithm works hierarchically. It starts with the longest subsequences and works down to shorter ones. This matters because compressing a long repeated phrase saves more tokens than compressing its shorter sub-fragments.

3. Replacement. Swap selected subsequences with meta-tokens like ⟨M1⟩, ⟨M2⟩, etc.

4. Dictionary construction. Build the mapping from meta-tokens back to original text.

The Token-Savings Condition

Not every repeated pattern is worth compressing. The dictionary itself costs tokens. Each entry includes the meta-token label, the original subsequence, and formatting overhead. If a pattern appears only twice, the dictionary cost might exceed the savings.

The paper introduces a simple but effective criterion. A subsequence S appearing f times costs f × tokencount(S) tokens uncompressed. Using a meta-token M to replace S costs (1 + f) × tokencount(M) + token_count(S) tokens compressed (the dictionary entry, its label, and f occurrences of the meta-token).

Compression provides net benefit when:

(1 + f) × token_count(M) + token_count(S) < f × token_count(S)

Only subsequences satisfying this condition get compressed. This prevents the dictionary overhead from eating your savings. It also means the algorithm adapts to each dataset automatically. Data with higher repetition gets compressed more aggressively.

Overlap Prevention

Each token position gets compressed at most once. The algorithm tracks used positions and filters out overlapping candidates. It also prevents nested compression. A subsequence containing an existing meta-token gets skipped during scanning. This keeps things deterministic and production-safe.

Batch-Level Processing

For large datasets that exceed the context window, the approach applies compression per batch. Each batch gets its own optimized dictionary based on the patterns in that batch. The system prompt carries the batch-specific dictionary. The user prompt carries the compressed batch data. This means dictionaries evolve with your data. When log patterns shift, the next batch's dictionary shifts too.

Why This Is Different From Prior Work

Prompt compression for LLMs falls into two camps.

Lossy methods remove tokens entirely. LLMLingua uses a small model to find and drop low-perplexity tokens. LLMLingua-2 extends this with data distillation. XRAGLog compresses logs by up to 90% using structured templates and retrieval. These approaches sacrifice information. Sometimes that's fine. Sometimes it's not.

Lossless methods preserve everything. Prior to this paper, Harvill et al. (2025) introduced the first lossless input compression. They replaced repeated token subsequences with meta-tokens and achieved 18-27% token reduction. But their approach required fine-tuning the LLM to understand the placeholder tokens. That's a hard constraint. You need access to model weights. You need to retrain when patterns change. You can't use it with API-only models like Claude or GPT-4.

This new paper solves that constraint. The LLM's existing in-context learning ability replaces fine-tuning. You give the model the dictionary, and it figures out the rest. That makes this the first lossless prompt compression method that works with any API-based LLM.

The Evaluation: System Logs as a Testbed

The researchers evaluated their approach on LogHub 2.0, a benchmark of real-world system logs from diverse sources (HDFS, BGL, Thunderbird, Spirit, etc.). They tested with Claude 3.7 Sonnet.

They used two compression strategies:

Template-based compression leverages existing log parsing tools that identify templates. Each template becomes a dictionary entry. Variable portions remain uncompressed. This is deterministic and achieves clean compression with well-defined patterns.

Algorithmic compression discovers patterns without any prior knowledge of log structure. The hierarchical algorithm finds repeated subsequences on its own. This is more flexible but introduces more variation in decompression accuracy.

The Key Results

For template-based compression, exact match rates exceeded 0.99 across all datasets and compression levels. That means the LLM recovered the original text character-for-character over 99% of the time.

For algorithmic compression at 60-80% compression ratios, average Levenshtein similarity stayed above 0.91. That's not exact match, but it's remarkably close for text that was compressed to a fifth of its original size.

The variance analysis is the most telling finding. Compression ratio explains less than 2% of the variance in similarity metrics. Dataset characteristics, not compression intensity, drive quality differences. Some datasets compress cleanly. Others are noisier. But turning the compression dial up doesn't meaningfully hurt performance within the tested range.

What This Enables

Cost Reduction

The direct benefit is lower API costs. An 80% compression ratio on a 100K-token log analysis drops your input to 20K tokens plus dictionary overhead. That's a 4-5x cost reduction for the same analytical output.

Context Window Utilization

Compression lets you fit more data into a fixed context window. If your analysis needs 200K tokens of log data but your model supports 128K, compression can bridge that gap without chunking or retrieval.

Evolving Data Patterns

Because dictionaries are generated per batch, the approach adapts when data patterns shift. New log formats appear. New error messages emerge. Each batch's dictionary captures whatever is repetitive right now. No retraining. No model updates. The next batch gets the right compression automatically.

Production Deployment

The training-free nature is critical for production systems. You don't need GPU time. You don't need access to model weights. You don't need a custom fine-tuned model sitting alongside your API calls. You run the compression algorithm on your data, construct a prompt with the dictionary, and send it to whatever LLM you already use.

Limitations

The paper is honest about what it doesn't solve.

Decompression as a proxy. The evaluation uses decompression accuracy as a stand-in for analytical quality. Decompression has unambiguous ground truth. But real analytical tasks, like anomaly detection or root cause analysis, have fuzzier definitions of correctness. The paper doesn't evaluate whether compressed inputs degrade the quality of those analyses. The authors argue that if the LLM can recover the original text with 0.99+ fidelity, it should produce equivalent analytical outputs. That's a reasonable assumption, but it remains an assumption.

Repetitive data only. Dictionary encoding works on repetition. Natural language documents with diverse vocabulary compress poorly. A legal brief, a research paper, or a creative writing prompt won't have enough repeated subsequences to justify the dictionary overhead. This approach targets logs, traces, and structured event data.

Compression algorithm overhead. The hierarchical scanning algorithm has computational cost. For very large datasets, finding all repeated subsequences at multiple length scales takes time. The paper doesn't benchmark compression speed.

Single-model evaluation. All experiments use Claude 3.7 Sonnet. Whether weaker models handle in-context dictionaries as well remains an open question. Strong in-context learning seems to be a prerequisite.

No comparison to lossy methods. The paper doesn't compare against LLMLingua or similar lossy approaches on the same datasets. A direct comparison of cost savings vs. information loss would clarify when lossless compression is worth the potentially lower compression ratios.

The Bigger Picture

This work points to something broader than log compression. LLMs are surprisingly capable at learning structured mappings from context. The paper exploits this for compression, but the same principle applies elsewhere.

Any domain where data has regular structure and LLMs need to process it at scale could benefit. Genomic sequences. Financial transaction records. IoT sensor readings. Configuration file audits. The pattern is the same: repetitive data, token-based pricing, and a model that can learn a mapping on the fly.

The "less than 2% variance" finding is worth sitting with. We assume compression trades quality for efficiency. In this regime, that assumption is wrong. The quality floor depends on the data, not the compression level. You can push compression hard without meaningful quality loss.

That's a useful fact for anyone paying API bills.

Citations

  • Rodrigues de Campos, A., Lee, D., Kissos, I., & Paritosh, P. (2026). Lossless Prompt Compression via Dictionary-Encoding and In-Context Learning. arXiv:2604.13066. https://arxiv.org/abs/2604.13066
  • Harvill, A. et al. (2025). Lossless Prompt Compression for LLM Inputs. [Referenced in arXiv:2604.13066]
  • Jiang, H. et al. (2023). LLMLingua: Compressing Prompts for Accelerated Inference. [Referenced in arXiv:2604.13066]
  • Pan, Q. et al. (2024). LLMLingua-2: Data Distillation for Task-Agnostic Prompt Compression. [Referenced in arXiv:2604.13066]
  • Xu, J. et al. (2024). XRAGLog: Compression for Log Analysis. [Referenced in arXiv:2604.13066]
  • Zhu, J. et al. (2023). LogHub 2.0: A Large-Scale Benchmark for Log Analysis. [Referenced in arXiv:2604.13066]
  • Zhang, Y. et al. (2024). In-Context Former for Prompt Compression. [Referenced in arXiv:2604.13066]
  • Salomon, D. (2004). Data Compression: The Complete Reference. Springer. [Referenced in arXiv:2604.13066]

Suggested Title

Your LLM Prompt Is 80% Air: Lossless Compression That Works on Any API

Word Count

1,547

Fact-Check Notes

  • The exact match rate ">0.99" and Levenshtein similarity ">0.91" come directly from the paper's abstract. These were measured on LogHub 2.0 with Claude 3.7 Sonnet. Verified.
  • The "less than 2% of variance" claim also comes from the abstract. The paper states this means decompression quality depends on dataset characteristics rather than compression intensity. Verified.
  • The "up to 80% compression" claim is from the abstract. Verified.
  • The Harvill et al. (2025) numbers (18-27% token reduction, 33-47% compute savings) come from the paper's related work section. These are cited, not independently verified.
  • The LLMLingua "up to 20x compression" claim is cited from Jiang et al. (2023) in the related work. Not independently verified.
  • The XRAGLog "up to 90%" compression claim is cited from Xu et al. (2024). Not independently verified.
  • The statement about this being "the first lossless prompt compression method that works on any API LLM" is my synthesis based on the paper's claim that it's the first training-free lossless input compression approach. Prior lossless methods (Harvill et al.) required fine-tuning. This claim should be verified against any concurrent or subsequent work.
  • The authors are listed as "Anonymous Authors" in the paper (under review), but the PDF metadata reveals: Andresa Rodrigues de Campos, David Lee, Imry Kissos, and Piyush Paritosh. This metadata-based attribution should be treated carefully since the paper is under blind review.
  • The evaluation uses decompression as a proxy task for analytical quality. The paper acknowledges this limitation. The claim that equivalent decompression implies equivalent analysis is the authors' argument, not a proven fact.