prompt-eng
Glossary ↗Prompt Compression
Prompt compression is the practice of reducing the token count of a prompt — through summarization, redundancy removal, structural simplification, or specialized compression algorithms — while preserving the information actually necessary for the model to complete the task accurately. It has become an increasingly important production concern as applications lean more heavily on large contexts (long conversation histories, RAG-retrieved documents, extensive few-shot examples), because every token in a prompt directly costs money and adds latency on every API call, and unnecessarily long prompts can also, per the context-stuffing problem, actively hurt accuracy rather than help it. Compression approaches range from simple to sophisticated: manual pruning (removing redundant instructions, trimming verbose examples down to their essential pattern, summarizing long conversation history into a running summary rather than resending every prior message verbatim); automated summarization (using a cheaper, faster model to compress a long document or context block into a shorter version before it's included in the main prompt, sometimes called a "map" step in a map-reduce chain); and dedicated prompt-compression research techniques and tools (e.g., Microsoft's LLMLingua) that use a smaller model to identify and remove tokens that contribute least to the target model's ability to complete the task, achieving significant compression ratios with minimal accuracy loss on benchmark tasks. A related and increasingly important complementary technique is prompt caching, offered by major providers (Anthropic, OpenAI), which doesn't reduce token count but caches the processing of a static prompt prefix (a long system prompt, a large reference document) across repeated calls, dramatically cutting the cost and latency of the cached portion on every call after the first — a different lever (cost/speed of reprocessing) than compression (raw information density), and the two are often used together. For SaaS builders, prompt compression and caching become priorities once an AI feature reaches meaningful production volume, where a token-count reduction directly translates to proportional cost savings at scale, and where a snappier response time is a real product-quality differentiator. Concrete worked example: an AI coding assistant that includes an entire 8,000-token style guide document in every single prompt call switches to a compressed 800-token summary of the style guide's key rules (generated once via a summarization prompt, then cached), plus prompt caching on that summary block so it's only fully reprocessed once per session rather than on every message — cutting the cost of that portion of every call by roughly 90% combined, with no measurable drop in the assistant's adherence to the style guide's core rules on their evaluation set.
Related terms