When is prompt compression worth it, and how would you do it?
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
Usually it is not, and that is the first thing to say. Most teams reaching for compression have a curation problem, not a compression problem. Before compressing anything, do the boring wins: stop stuffing 50 chunks when 8 answer the question, trim tool outputs, delete few-shot examples that no longer earn their tokens, drop the dead tool definitions. That is normally a large reduction with zero quality risk.
Full worked answer with diagram
Usually it is not, and that is the first thing to say. Most teams reaching for compression have a curation problem, not a compression problem. Before compressing anything, do the boring wins: stop stuffing 50 chunks when 8 answer the question, trim tool outputs, delete few-shot examples that no longer earn their tokens, drop the dead tool definitions. That is normally a large reduction with zero quality risk.
If you still need it, the techniques fall into tiers:
- Structural: deduplicate, strip boilerplate and navigation chrome from scraped pages, field allowlists. Lossless-ish and always worth doing.
- Abstractive: summarise background material with a small cheap model. This is what agent compaction already does to conversation history.
- Token-level: LLMLingua-style approaches use a small model's perplexity to drop low-information tokens, producing text that looks mangled to humans but reads fine to the model. Real, and genuinely aggressive.
- Retrieval instead of compression: often the right answer. Do not compress the 40 documents, retrieve the 4.
When it pays: you are prefill-latency bound, you are token-cost bound on a context that is not reused (so caching cannot help), or you are running self-hosted where context length is a hard capacity constraint.
When it does not: if your long prefix is stable, prompt caching beats compression on every axis. Cache reads run at a fraction of input price with zero quality risk. Compression trades quality for cost; caching does not. Candidates who reach for compression before checking cacheability are optimising the wrong thing.
The risk is that compression is lossy adversarially: the token you dropped is the answer. It is most dangerous on extraction and exact-detail tasks, safest on background and history. So never compress the user's actual instruction or the output contract, only the background. And measure it as a frontier: quality on your eval against tokens saved, not tokens saved alone.
Worth sketching. The two gates before any compression happens are the answer, and drawing them stops you sounding keen to compress.
flowchart TD
A["Context is too big"] --> B{"Curation done: chunks,<br/>tools, dead examples?"}
B -->|"no"| C["Cut the obvious waste,<br/>zero quality risk"]
B -->|"yes"| D{"Is the long prefix stable?"}
D -->|"yes"| E["Cache it, compression<br/>loses on every axis"]
D -->|"no"| F{"What is actually in there?"}
F -->|"documents"| G["Retrieve fewer,<br/>do not compress"]
F -->|"history, background"| H["Summarise, or<br/>token-level compression"]
F -->|"instructions, contract"| I["Never compress"]
What a good answer covers
- Usually it is not, and that is the first thing to say
- Most teams reaching for compression have a curation problem, not a compression problem
- Before compressing anything, do the boring wins
- That is normally a large reduction with zero quality risk
- Structural: deduplicate, strip boilerplate and navigation chrome from scraped pages, field allowlists
Key terms: Structural · Abstractive · Token-level · Retrieval instead of compression
In the glossary: Few-shot · Compaction · Prompt caching
Interviewer follow-ups to expect
Why might token-level compression hurt an extraction task more than a summarisation task?
- Structural: deduplicate, strip boilerplate and navigation chrome from scraped pages, field allowlists. Lossless-ish and always worth doing.
- Abstractive: summarise background material with a small cheap model. This is what agent compaction already does to conversation history.
- Token-level: LLMLingua-style approaches use a small model's perplexity to drop low-information tokens, producing text that looks mangled to humans but reads fine to the model. Real, and genuinely aggressive.
- Retrieval instead of compression: often the right answer. Do not compress the 40 documents, retrieve the 4.
How would you decide between compressing history and offloading it to a file?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep