Pick the right fallback when the assembled prompt overflows the model's context window
The right overflow fallback is a documented eviction order: sacred (system prompt + current turn + output reservation) protected, evictable (extra chunks, summary levels) trimmed in declared order.
Imagine a suitcase that will not close. Three bad options. First, refuse to go on the trip until the traveler removes things; rude, and they did not pack most of it themselves. Second, just sit on the lid and squish whatever happens to be at the bottom; you smash the medicine and the passport. Third, secretly trade the suitcase for a bigger one without telling them; they did not budget for a bigger suitcase. The right way is a packing list with priorities. The passport and medicine always stay. The third pair of shoes, the extra snacks, those come out first, in that order, until the suitcase closes. That order is the eviction order, and it is decided before the trip, not on the curb.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Every LLM stack eventually hits the moment when the assembled prompt is bigger than the model's context window. How it responds in that moment defines whether the system is production-grade or a prototype. Four options come up in design reviews, and three of them are wrong in ways that only become visible weeks later when the failures correlate with high-context calls.
The right answer is the least exciting one: a documented eviction order that declares sacred tiers, declares an evictable hierarchy, and trims in declared sequence until the prompt fits. The other three options each fail differently, rejection blames the user, head-truncation decapitates the agent, silent model swap breaks the audit and the bill, but they share a common shape: they are decisions the system makes without informing the caller or the operator, and the consequences arrive in production rather than at design time.
This question is graded as medium difficulty because the wrong answers are tempting. Rejection feels safe; head-truncation is the cheapest to implement; silent model swap preserves the user experience. Each has a clean-sounding rationale and a hidden cost. The correct answer is boring on purpose: predictable, debuggable, and tested in CI.
Why rejection is rarely the right move
Rejection is the cleanest-feeling option. 'Your input is too long; please shorten it.' The user is responsible for what they sent; if it does not fit, that is their problem.
In practice the overflow is almost never caused by the user's literal input. A typical breakdown of an assembled prompt at the moment of overflow:
- System prompt: 2,000 tokens (fixed).
- Tool definitions: 2,400 tokens (fixed).
- Persistent memory or rolling summary: 4,000 tokens (system-managed).
- Recent conversation history: 12,000 tokens (grows with session).
- Retrieved evidence: 40,000 tokens (system-fetched).
- Current user turn: 200 tokens (the only thing the user controls).
The user's 200 tokens is 0.3% of the total. Rejecting because the assembly does not fit is shifting blame for an assembler decision onto a user who cannot influence it.
Rejection is correct in one specific case: when the user's literal turn alone exceeds the input budget after maximum eviction. That happens when someone pastes a 200k-token document into a model with a 128k window. The right response is a clear error code with specifics: 'Input exceeds the maximum supported length by ~72,000 tokens. Please shorten your message or use the document upload tool.' Generic errors ('too long') strand the user; specific errors give them a path forward.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
| Option | Failure mode | When (if ever) right |
|---|---|---|
| Reject the request | Blames the user for system-side overflow | Only when user input alone exceeds budget after max eviction |
| Silent head-truncate | Drops system prompt and safety rails | Never; antipattern |
| Documented eviction order | Quality degrades gradually under budget pressure | Default for any production system |
| Silent model swap | Changes price and behavior without notice | Never silent; ok with an explicit declared ladder and logging |
Real products, models, and research that use this idea.
- Anthropic Claude Code applies a compaction step before overflow: stale tool results and older summary levels are evicted from working context while CLAUDE.md and the active task block stay sacred.
- LangGraph's trim_messages with strategy='last' preserves recent turns and the system prompt while trimming older history.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhat does a good error message look like when reject is the correct response?
Specific: 'Your input exceeds the maximum supported length by ~N tokens. Please shorten to under M characters or split into multiple messages.' Generic errors ('too long') leave the user guessing. Specific errors give them an actionable shape.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Picking head-truncation as the simple default. It drops the system prompt first, which is exactly the tier that should be untouchable.
60 second bullets to scan on the way to the call.
Which option is the right default and why
What 'sacred tier' means in this context
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.