Context Windows and Model Limits
Budget prompts, conversation history, retrieved evidence, and output within an LLM context window. Learn why a larger window is not a guarantee of better answers.
Quick answer
A context window is a token budget for the model request. Budget instructions, the current question, history, retrieved passages, tool content, and output capacity according to the selected model and provider; fitting more text does not guarantee the model will use every detail reliably.
- Token counts depend on the tokenizer and exact request content.
- Reserve output capacity and count tool schemas and results as well as visible chat text.
- Trim duplicate or low-relevance context, preserve critical constraints, and make omissions observable.
Instructions 600
Current question 250
History 1450
Retrieved text 3500
Tools 650
Output reserve 900
----------------------
Total 7350 (350 above a 7000-token limit)Learning objective
Plan a request that fits without silently dropping the information the model needs.
Prerequisites: know what a language model predicts, how text is tokenised, and what an instruction prompt contains. If those ideas are new, start with What is Generative AI?, Tokenisation and Word Embeddings, and LLMs — Pretraining, RLHF, and Scaling Laws.
A context window is a request’s working set
A model processes tokenised input as context while producing an output. In a multi-turn application, the request may include instructions, the current question, selected conversation history, retrieved passages, and tool definitions or results. The model does not automatically remember text that your application did not send; some APIs offer managed conversation state, so inspect what that API includes on each turn.
A context-window limit is measured in tokens, not words or characters. Token counts vary with the tokenizer and the text: code, punctuation, uncommon names, and different languages can consume different numbers of tokens. Use the model or provider’s documented counting method when you need an exact budget.
Budget all parts of the request
Treat the following numbers as a planning example, not as a tokenizer estimate. Assume this model’s documented combined request and output limit is 7,000 tokens. The application’s planned request totals 7,350 tokens, so it is 350 over budget.
| Request component | Planned tokens |
|---|---|
| System and developer instructions | 600 |
| Current user message | 250 |
| Recent conversation history | 1,450 |
| Retrieved reference passages | 3,500 |
| Tool definitions and results | 650 |
| Reserved response budget | 900 |
| Total including reserved output | 7,350 |
One possible adjustment is to retrieve fewer, more relevant passages: reducing that component by 600 gives 6,750 planned tokens, leaving 250 tokens below the hypothetical limit. In a real application, keep additional headroom because estimates, tool output, formatting, and provider accounting can differ.
A reliable budgeting workflow
- Choose the model first. Limits and token accounting are model-specific.
- Reserve output capacity. Do not spend the entire allowance on input if the answer needs room.
- Count the actual request. Include instructions, history, retrieved content, tool schemas, and tool results.
- Trim by value, not by position alone. Remove duplicate history and low-relevance evidence; keep the user’s current task and required constraints.
- Make loss visible. If history or retrieval must be shortened, record what was omitted or summarised rather than silently dropping content.
- Evaluate answer quality. Test with relevant evidence in different positions and check whether the response uses it correctly.
Diagnose common failures
Practice: repair an over-budget request
Your request has an 8,000-token combined limit and currently uses 8,450 tokens, including a 1,000-token response reserve. The user’s latest question and a required safety instruction must remain. You have 3,200 tokens of retrieved documents, of which only two passages directly answer the question.
- Keep the reserve and the required instruction.
- Remove duplicate conversation turns before summarising the current question.
- Prefer the two relevant passages over unrelated retrieved text.
- Recount the actual request, leave headroom, and test that the answer still uses the needed evidence.
Check your result: trimming at least 451 tokens gets the planned request below 8,000, but a production request should leave more than one token of headroom. The exact amount depends on the provider’s accounting and request structure.
Key takeaways
- The context window is a token budget for the model request, not persistent memory.
- Budget instructions, user input, history, retrieved evidence, tools, and output together according to the chosen API’s rules.
- Fitting more text does not guarantee better recall; retrieval quality and evaluation still matter.
- When trimming, protect the current task and constraints, keep useful evidence, and make omissions observable.
Quick check
What should you do first when a request exceeds the selected model’s context budget?
HELP US IMPROVE
How was this lesson?
Your note is shared with the Chaduvuko team for review. Please don’t include personal or sensitive information.
Spotted a mistake or something unclear? Suggest a fix on GitHub or email us. Select the text first and it is quoted for you.
Discussion
0Have a better approach? Found something outdated? Share it — your knowledge helps everyone learning here.
