Intermediate

Visualizing Your Context Window

The context window is prime real estate. Every token you send occupies a slot that costs money and shapes model attention. Learn to read token heat maps, density charts, and flow diagrams that make context structure visible and actionable.

✍️ AI School Editorial Team · Lilly Tech Systems 📅 Published Jul 13, 2026 · Reviewed Jul 13, 2026

The Context Window as a Budget

Every LLM call has a context window - a fixed number of tokens that can be passed in a single request. Current leading models support anywhere from 8,000 to 200,000 tokens. That range is wide enough that teams often treat the context window as essentially unlimited. This is a mistake. Even a 200,000-token context window has a per-token price, and every token in that window competes for the model's attention. Filling it with low-value content does not just cost money - it can reduce the quality of responses as the model's attention gets distributed across more material.

A useful mental model: the context window is a whiteboard in a meeting room. You have 60 minutes and a fixed-size whiteboard. Every piece of information you write takes up space and meeting time. The question is not "can I fit everything on the board" - it is "what is worth putting on the board given what I need this meeting to produce."

Token Heat Maps: Your First Visual Tool

A token heat map assigns a color intensity to each sentence or paragraph in a prompt based on how many tokens it contributes relative to the whole. High-density zones appear in a warm color (red, orange), low-density zones in cool colors (blue, green). When you view a prompt as a heat map instead of as text, the distribution of token cost becomes immediately visible.

Common patterns visible in heat maps:

  • Hot header, cold body: The system prompt and initial instructions are token-heavy, but the actual user query is tiny. This signals the instructions may be over-specified or include documentation that could be moved to a cached position.
  • Evenly warm RAG block: Multiple retrieved chunks all show similar token density, suggesting the retrieval step is returning chunks of uniform size regardless of relevance. Top-k filtering by token count rather than pure similarity score often helps here.
  • Hot history tail: The most recent conversation turns are warm, but older turns in the history are just as warm. This reveals a missing history truncation or summarization step - old turns carry the same token cost as recent ones even when they are rarely relevant to the current query.
  • Isolated cold islands: Sections of the context that consistently contribute no tokens to relevant model outputs. These are candidates for removal with no quality impact.
📚
Example: A support ticket classification pipeline had a 3,800-token average context. The heat map showed: system prompt 22%, examples block 41%, conversation history 28%, user message 9%. The examples block was the dominant cost driver. Removing 5 of the 8 few-shot examples (keeping only the 3 most representative) reduced context to 2,200 tokens with no classification accuracy change - a 42% reduction from a single edit.

Token Density Charts: Comparing Pipelines

A token density chart plots the token distribution across all requests to a pipeline, showing average, median, and 90th-percentile context sizes. This is distinct from a heat map (which shows distribution within a single request) - a density chart shows distribution across many requests over time.

Key things to look for in a density chart:

  • Bimodal distribution: Two distinct peaks (e.g., one at 1,000 tokens and one at 8,000 tokens) usually indicate two different user behaviors or code paths that are currently handled by the same pipeline. Splitting them and optimizing each separately often yields large gains.
  • Long right tail: Most requests cluster under 2,000 tokens, but occasional requests spike to 15,000. These outliers drive disproportionate cost and are usually caused by a specific input pattern (long documents, multi-turn edge cases) worth treating separately.
  • Flat uniform distribution: Every request is the same size. This is often a sign the context is being padded to a fixed size regardless of content - a template pattern that wastes tokens for short inputs.

Context Flow Diagrams

For agentic or multi-step pipelines, a context flow diagram is more useful than a heat map. It shows the token budget at each step of the pipeline, how tokens accumulate as history and tool results are appended, and where the budget is exhausted or where truncation occurs.

StepTokens AddedRunning TotalSource
Initial prompt450450System + user message
Tool call 1 result8001,250Web search result
Intermediate response3001,550Model output, turn 1
Tool call 2 result1,2002,750Database query result
Intermediate response2503,000Model output, turn 2
Tool call 3 result9003,900Document retrieval
Final response4004,300Model output, final

Reading this diagram reveals that tool call 2 (the database query result at 1,200 tokens) is the largest single step addition. If the database result can be summarized or filtered before being injected, that step could drop from 1,200 to 200-300 tokens without losing the relevant information. The flow diagram makes this opportunity visible in a way that reading the code does not.

Interpreting What You See

A token visualization is only useful if you know what to do with the findings. Here is a decision tree for the most common visual signals:

  • Large static section (same tokens every call) → Add to prompt cache. If the section is early in the context and rarely changes, it is a prime caching target.
  • Repeated content across sections → Deduplicate. One authoritative version, referenced by multiple downstream steps.
  • Long history with low recency-weight → Truncate or summarize. Keep the last N turns; replace older turns with a rolling summary token.
  • Over-sized tool results → Compress at injection. Summarize or filter the result before adding it to context, not after the model sees it.
  • Uniform high density across a retrieved block → Tighten retrieval. Reduce top-k or add a re-ranking step that penalizes long chunks.

The next lesson goes deeper on one of the most powerful structural interventions: replacing flat-text context with graph-based representations that express the same information in far fewer tokens.

Ready to Go Deeper?

Live instructor-led courses from our partners. Affiliate disclosure.