Large context windows make it tempting to send everything to the model: long system prompts, full conversation history, dozens of retrieved chunks, tool output and user documents. In production, that approach often increases cost and latency while making answers less predictable. Context should be treated as a budget rather than unlimited storage.
Split the window into explicit envelopes
A useful design reserves space for several categories: system instructions, user input, retrieved evidence, tool results, long-term memory, recent conversation and response generation. Each category gets a target and a hard maximum. This prevents one source, such as a verbose tool response, from unexpectedly consuming the entire context window.
Protect the highest-value tokens first. When the context is too large, not all information should be trimmed equally. System constraints, security rules and the current user request generally have higher priority than old conversation turns. Retrieved evidence can be ranked by relevance and recency. Historical conversation can be summarized. Tool output can often be reduced to the fields needed for the next decision.
Reserve output capacity before filling input
Teams sometimes use nearly the entire context for input and leave little room for the model to answer. The token budget should explicitly reserve response capacity based on the task. A short classification may need little output. A long report or code generation task may require a much larger response allocation.
Measure quality per token. More context is not automatically better. Run evaluations at several context sizes and measure task completion, hallucination rate, citation quality, latency and cost. The objective is to find the point where additional tokens stop improving outcomes. For some tasks, three highly relevant chunks outperform twenty mediocre ones.
Use summarization for history, not blind truncation
Dropping the oldest messages can remove important decisions. A better approach is to maintain a structured conversation summary containing goals, constraints, decisions and unresolved items. Recent turns remain verbatim while older material is compressed. This preserves continuity without repeatedly paying for the full transcript.
Tool output needs its own policy. APIs and browser tools often return far more information than the model needs. A search tool may return complete HTML, a database query may return dozens of columns, and a monitoring tool may return thousands of log lines. Filter or summarize tool results before adding them to the model context. This reduces both cost and prompt injection exposure.
Retrieval should stop when evidence is sufficient
RAG pipelines can use dynamic retrieval rather than a fixed number of chunks. If top results already answer the question with strong confidence, additional documents may add noise. For more difficult tasks, the system can retrieve again after identifying missing evidence.
Prompt caching changes economics, not governance. Repeated system instructions or shared reference material may be eligible for provider-side prompt caching. This can make large static prefixes cheaper, but it does not mean every cached token is useful. Our article on prompt-cache economics explains when caching reduces cost and when it simply hides an oversized prompt.
Set budgets by workflow
A customer-support agent, coding assistant and research workflow may need very different context policies. Avoid one global limit for the entire product. Track token usage by feature, tenant and workflow so teams can see which product behavior is driving cost. Our guide to LLM cost attribution provides a related measurement framework.
Log compression and truncation events. When information is removed, record what happened. If a user later reports that the model forgot an instruction, engineers should be able to see whether the relevant context was summarized, truncated or never retrieved.
Set budget alerts before costs become incidents
Token governance should include operational alerts. A sudden increase in average prompt size may indicate a retrieval regression, a tool returning unexpectedly verbose data or a conversation-summary failure. Alerting on context size by feature can detect these changes before they become a large billing surprise. Teams can also define soft and hard limits. Soft limits trigger compression or more selective retrieval; hard limits reject or reroute unusually large requests. This keeps one pathological workflow from consuming disproportionate model capacity.
Context is an infrastructure resource. Token governance is not just prompt engineering. It is capacity planning for the model’s working memory. Explicit budgets make latency, cost and behavior more predictable while reducing the chance that irrelevant information overwhelms the model. The strongest production systems do not ask, “How much context can this model accept?” They ask, “What is the smallest context that reliably completes this task?”