# What Happens When Input Is Longer Than the Window?

> Why a long chat or document breaks an AI request, what the API does about it, and the practical fixes, explained simply for your AI interview.

**In short:** When input is longer than the window, the request fails or the reply is cut short. Anthropic's API rejects an input that is too long on its own, and a reply can stop early if the window runs out. Teams count tokens first, then trim, summarise or search for only what the task needs.

AI and LLM interview question Q009, LLM fundamentals. Beginner, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/what-happens-when-input-is-longer-than-the-window

## Say it in 30 seconds

When my input is longer than the window, the model can't read all of it. The API may reject the request with an error, or the reply may stop early if it runs out of room. So I count tokens first, then trim the history, summarise older turns, or search for only the parts the task needs. Each fix loses something, so I say what it costs and keep key facts out of anything that gets dropped.

## Say it in 2 minutes

A model can only work with what fits in its context window. That window holds everything in one request: the system prompt, the chat so far, tool results, documents, and the reply the model is writing. If the total is too big, something has to change before the model can answer.

There are two ways it goes wrong. First, the input alone is too big, and the API refuses the request with an error, so the model never runs. Second, the input fits but the reply has no room left, so the answer stops early. Some apps also trim old messages without telling anyone, which is how a bot can forget a card number a customer gave ten minutes earlier.

So I plan for it. I count tokens before sending. I keep the rules and the newest turns, and I summarise older turns, or cut them by a clear rule. For a long contract, I split it, search for the matching clauses, and send only those with their page numbers, so the answer can be checked against the source.

A bigger window helps, but it doesn't remove the problem. Long inputs can make accuracy and recall worse, so I never rely on size alone. Each option loses some detail, so I test the answers on the facts that must survive.

## What happens when input is longer than the window, in plain words?

A model reads a request as one block of text. The context window is the most it can hold in one go. Everything counts toward that limit: the rules, the chat so far, any tool results, and the reply the model is writing.

Picture a claims clerk with a folder that holds 50 pages, and a case file of 80 pages on the desk. The clerk can't read it all at once, so they pick which pages go in the folder, or ask for a summary of the rest. An AI app faces the same choice with a long chat or a document.

A real case: a legal team sends a 300-page supplier contract with a question about liability. The whole contract may not fit, and the clause that matters may sit in the middle.

- **Context window:** The most text the model can hold in one request, reply included.
- **Token:** A small piece of text, often part of a word. Limits are counted in tokens.
- **API:** The web service your app calls to reach the model.
- **Compaction:** A summary of older turns, written so a long chat can go on.
- **Stop reason:** The reason the model stopped, such as reaching the limit.

## What exactly happens when the input is too long?

- **Too big alone: The request fails.** Anthropic's API returns a 400 error, and the model never runs.
- **Fits, but no room: Reply cut short.** On newer Claude models the reply stops at the limit. Older models return an error.
- **Trimmed quietly: Old text is gone.** If the app drops old turns without saying so, the model never sees them.

*Diagram, What a too-long request does: Your code counts the tokens before it sends anything. A request that fits goes straight to the model. One that is too long is trimmed, summarised or searched first, so the API never receives an oversize request.*
1. The whole chat goes to a token count before sending.
2. Small enough, so it goes to the model as it is.
3. Too big: the input alone is over the limit.
4. The model answers from the full input.
5. Trim, summarise or search to shrink it.

As of November 2026, Anthropic's docs say that on newer Claude models the request is accepted even when input plus the reply budget is over the window. If the reply then reaches the limit, it stops with a stop reason, instead of failing up front.

OpenAI's docs make a related point: a large prompt can exceed the allocated window, which might cut the output short. With OpenAI's API, earlier input in a chain is billed again on each turn, so long chats cost more.

## Does fitting in the window mean the model uses it well?

Not always. A bigger window does not guarantee good recall, which means finding the right fact in the input. Anthropic's docs warn about context rot, where accuracy and recall fall as the input grows. A 2023 study also found that answers got worse when the key fact sat in the middle of a long input.

> "As token count grows, accuracy and recall degrade, a phenomenon known as context rot." (Anthropic)
>
> "performance is often highest when relevant information occurs at the beginning or end of the input context, and significantly degrades when models must access relevant information in the middle of long contexts" (Liu et al., 2023)

Here is a worked case. A bank's support assistant gets its fee schedule, a made-up document several hundred pages long. A customer asks about a foreign transaction fee, and the rule sits on page 112, in the middle. Pasting everything may leave the model answering from the wrong section. The fix is to search for the fee section first, send that section with its page number, and check the answer against it.

> **Tip:** Asked whether a bigger window solves it? Say no. More context isn't automatically better, so keep the input small and relevant, then measure the answers.

## How do apps handle input that is too long?

1. **Count before you send:** Estimate the tokens first with the counting tool. Anthropic recommends this before any request that might be too big.
2. **Keep the rules and the newest turns:** Always keep the system rules and the latest messages. Trim or summarise the middle first, and never let a simple slice cut off the rules.
3. **Summarise older turns:** Anthropic's compaction feature (in beta on newer Claude models) writes a summary of the older turns on its servers, so the chat can go on past the limit. Your own code can summarise too. Either way, a card number or a date can get lost.
4. **Search instead of pasting:** For documents, split them, search for the matching parts, and send only those. Anything the search misses is lost, so test recall on real questions.

*Diagram, Three ways to fit a long input: A long input has three ways in: split it and read the parts, summarise the old turns, or fetch only the matching passages. Each one ends with a smaller input the model can read in one go. Each trades a little detail for a window that fits.*
1. Cut the input into pieces and read each one.
2. Replace old turns with a short summary.
3. Search for the matching parts and send those.
4. Each piece gives a partial answer that is combined.
5. The summary goes in, and recent turns stay whole.
6. Only the matching passages reach the model.

Here it is in plain Python. The newest turns fill a small budget and older ones go first, so the plain version loses the card number. Pinning the key fact into the rules keeps it, because the rules always stay. The cost is room: fewer turns fit.

```python
# A support bot keeps its rules and the newest chat turns inside a small budget.
# Made-up numbers: one word stands in for one token here. Real tokenizers differ.
BUDGET = 40
RULES = "Quote fees from the fee schedule only. Never promise a refund."
history = [
    "Customer: I was charged a foreign fee twice on card 4417.",
    "Bot: Sorry about that. Which merchant was it?",
    "Customer: A hotel in Lisbon, the same night.",
    "Bot: Thanks. Duplicate foreign fees are reviewed within 5 working days.",
    "Customer: Can you refund it today?",
    "Bot: Refunds are not promised here. I can open a review.",
    "Customer: Please open the review and tell me the reference.",
]
def size(text):
    return len(text.split())
def fit(rules, turns, budget):
    used, kept = size(rules), []
    for turn in reversed(turns):
        if used + size(turn) > budget:
            break
        kept.insert(0, turn)
        used += size(turn)
    return kept, used
kept, used = fit(RULES, history, BUDGET)
print("Plain: card seen", any("4417" in t for t in kept), "turns kept", len(kept))
pinned = RULES + " Pinned: card 4417, foreign fee charged twice."
kept2, used2 = fit(pinned, history, BUDGET)
print("Pinned: card in rules", "4417" in pinned, "turns kept", len(kept2), "words used", used2)
```

Output:

```text
Plain: card seen False turns kept 3
Pinned: card in rules True turns kept 2 words used 39
```

> **Tip:** In a chat app, keep the rules out of anything that gets trimmed, count tokens rather than messages, and log what was dropped so a wrong answer can be traced.

### How would you answer a question about a 300-page contract?

Don't paste the whole contract into one request and hope. Split it into sections, search for the clauses that match the question, and send those with their page numbers. Ask the model to cite the clause it used. Then check the answer against the cited text, because a missing clause is the failure you won't notice.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: the window is the most the model holds in one request.
- [ ] Two failures: an input too big on its own, and a reply with no room.
- [ ] Counting tokens before sending, so the request fits first.
- [ ] Trimming and summaries lose detail, so say what gets lost.
- [ ] Fitting in the window does not mean the model uses it well.
- [ ] On some APIs, long chats cost more each turn, so trim by a clear rule.

**Common traps**

- Trap: "Just use a model with a bigger window." Better: A bigger window helps, but accuracy can still drop on long input. Keep the input small and relevant too.
- Trap: "The app just cuts the oldest text, so nothing breaks." Better: Cutting can drop the rules or a key fact. Keep the rules out of the cut and log what was dropped.
- Trap: "Summarise everything, it is free." Better: Summaries cost a model call and lose detail. Keep exact facts, like fees and dates, in the source.

## Can you spot the problem?

**Spot the problem:** A support bot keeps its rules as the first item in its history list. Which line can silently drop the rules after a long chat?

A. history = history[-20:]  # keep the newest 20 messages
B. history = [RULES] + history[-20:]  # rules always come first
C. print('turns in chat:', len(history))  # log the size, drop nothing
D. reply = send(model, system=RULES, messages=history)

**Answer:** A. The rules sit at position 0 of the list. Keeping only the last 20 messages cuts them off. Keep the rules outside the cut, and count tokens rather than messages.

**Quick check:** The chat has grown past what the model can hold. What should your code do first?

A. Raise the reply budget so the answer has room
B. Count the tokens, then trim or summarise older turns before sending
C. Send it anyway and let the model read faster
D. Lower the temperature so the answer is shorter

**Answer:** B. Count first, then cut. A bigger reply budget makes the problem worse, because the reply shares the window. Temperature only changes how the model picks words, not how much it can hold.

## Can you answer these from memory?

**Flash cards**

- **What is the context window?** The most text the model can hold in one request, reply included.
- **What happens if the input alone is too big?** The API rejects the request with an error. The model never runs.
- **Why can a reply stop early?** The window holds the reply too, so writing can hit the limit first.
- **What is context rot?** Accuracy and recall fall as the token count grows, even inside the window.
- **What is compaction?** A summary of older turns, so a long chat can carry on.
- **What is the first step?** Count tokens before sending, then trim, summarise or search.

## Likely follow-up questions

- Q083 What is "context rot"? https://designervenkat.online/interview/ai/what-is-context-rot
- Q095 How do you handle very long documents? https://designervenkat.online/interview/ai/how-do-you-handle-very-long-documents
- Q096 What is compaction (summarising history)? https://designervenkat.online/interview/ai/what-is-compaction-summarising-history
- Q113 What is chunking, and why does size matter? https://designervenkat.online/interview/ai/what-is-chunking-in-rag
- Q138 RAG vs long context: which to use? https://designervenkat.online/interview/ai/rag-vs-long-context

## Learn it in depth

- [Context Window](https://designervenkat.online/learn/ai-engineering/context-window)
- [Long-Context Processing](https://designervenkat.online/learn/ai-engineering/long-context-processing)
- [Context Compaction](https://designervenkat.online/learn/ai-engineering/context-compaction)
