# What Is Lost in the Middle?

> What lost in the middle means, why facts buried in the middle of a long AI input get missed, and what to do about it, explained simply for your AI interview.

**In short:** Lost in the middle is when an AI model uses facts well if they sit near the start or end of a long input, but misses or underuses them when they sit in the middle. Researchers measured it in 2023. Test where your key facts land before you trust a long prompt.

AI and LLM interview question Q084, Prompt and context engineering. Intermediate, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/what-is-lost-in-the-middle

## Say it in 30 seconds

Lost in the middle is when a model uses facts well if they sit near the start or end of a long input, but misses them when they sit in the middle. Researchers measured it in 2023, on questions over many documents, and on finding one value in a list. So I don't assume a big window is enough. I put key text at the start or end, send fewer and better sections, and test with the same fact moved to different places before anyone relies on the answer.

## Say it in 2 minutes

Lost in the middle is a name for a pattern in long AI inputs. When the fact an answer needs sits near the start or the end, a model tends to use it well. When the same fact sits in the middle, the model is more likely to miss it or use it weakly. The name comes from a 2023 research paper that tested two jobs: answering questions over many documents, and finding one value in a list of key-value pairs.

The paper found that performance can degrade significantly when the position of the relevant information changes. The effect showed up even in models built for long inputs. So a bigger context window does not solve it on its own. Anthropic makes a related point: as the input grows, accuracy and recall degrade, a problem it calls context rot. More text is not automatically better.

In an interview, say what you would do. Put the key text at the start or end, and the question last. Send fewer, better sections instead of the whole file. Then plant one fact at the start, the middle and the end, and score the answers. OpenAI's guide describes a test that hid one fact at varying depths in long-context documents, and that is the habit I would bring to the job.

Keep the claim honest. The paper measured this effect in its own tests, so test your own model and your own documents before you promise anything. The fixes lower the risk, and testing shows how much risk is left.

## What is lost in the middle, in plain words?

A model reads a long input as one stream of text. Lost in the middle describes a pattern: when the fact an answer needs sits near the start or the end, the model tends to use it well. When that same fact sits in the middle, the model is more likely to miss it or use it weakly.

Think of a hospital triage nurse taking over a 40-page handover note. The first lines and the last lines stick, and the middle gets skimmed. An AI contract assistant can behave the same way. If the liability cap sits on page 21 of a supplier agreement, the assistant may skip it, although the cap is on the page.

- **Long input:** Many pages, messages or tool results sent to the model in one request.
- **Position:** Where a fact sits in that input, from the first line to the last.
- **Retrieval:** A search step that finds and sends only the few sections that match the question.
- **Needle test:** A check that hides one fact at set depths in a long text, then asks for it back.
- **Context rot:** The name Anthropic uses for recall getting weaker as the input grows.

## What did the 2023 study find?

The paper is titled Lost in the Middle: How Language Models Use Long Contexts, and it was first posted in July 2023. It tested two jobs. One was answering questions over many documents. The other was finding one value in a list of key-value pairs, which is a simple lookup.

> "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, even for explicitly long-context models." (The Lost in the Middle paper, abstract)
>
> "An LLM's tendency to use information from the start and end of a long context window more effectively than information from the middle." (Google's machine learning glossary)

Here is a worked case. A made-up logistics firm loads a 40-page supplier agreement and asks what the liability cap is. The clause "Liability is capped at 2 times the annual fees." sits on page 1, where a model would usually quote it. Move the same clause to page 21, change nothing else, and the answer would often guess, or say the cap was missing.

*Diagram, Same clause, two places: The same clause, placed on page 1 and then on page 21 of a 40-page file. The chart shows the pattern the paper describes, with made-up stakes and no test of our own.*
1. The clause near the start is used well, so the answer usually finds it.
2. The same clause in the middle is used less well, so the answer often misses it.

## Why does it happen, and is it solved?

OpenAI's guide puts it this way: a model can't pay equal attention to every token it gets at one time. The paper shows the effect in its own tests. In an interview, I would avoid claiming one settled cause. I would say the sources describe the pattern and stop short of a full explanation.

Context rot is a related idea. Anthropic says that as token count grows, accuracy and recall degrade, and it calls this context rot. Lost in the middle is narrower. It is about where a fact sits in the input.

> **Tip:** Asked whether a bigger window fixes it? Say no. A bigger window can hold more text, and the position of a fact can still change the answer. Then say how you would test it.

## How do you work around it?

You cannot rely on a model to ignore position, so lower the risk and then measure. Four habits do most of the work.

1. **Put key text at an edge:** The paper found answers were often best when the key text sat at the start or end of a long input. So move the clause to one of those edges.
2. **Send fewer, better sections:** Retrieval, the search part of RAG (retrieval-augmented generation), picks the few sections that match the question. Less text means less for the model to skim past.
3. **Put the question last:** Anthropic's guide says queries at the end can improve response quality, so the question comes after the documents.
4. **Test with the fact moved:** Plant one fact at the start, the middle and the end, then score the answers. OpenAI's guide describes a test that hid one fact at varying depths in long-context documents.

*Diagram, Fixes that lower the risk: Three things you control shape what the model reads. The model's answer is then checked by moving the fact to other places. The arrows show what feeds the answer, and they promise no gain.*
1. Put the clause at the start or end, where the paper found answers often did best.
2. Fewer sections mean less text for the model to search through.
3. The question comes after the text it asks about, as Anthropic suggests.
4. Then the answer is tested with the fact moved to other places.

Here is the test idea in plain Python. It builds three versions of one 40-page input, with the same clause at the start, the middle and the end. A team would send each version to its model and compare the answers. This script calls no model, so its output only shows where the clause landed.

```python
# Build the test inputs for one 40-page supplier contract. No model runs here:
# the liability cap is planted at three depths, so each input can be checked.
CAP = "Liability is capped at 2 times the annual fees."
pages = [f"Page {n}: standard notices and terms." for n in range(1, 41)]
QUESTION = "What is the liability cap?"

for name, spot in [("start", 0), ("middle", 20), ("end", 39)]:
    doc = list(pages)
    doc[spot] = f"Page {spot + 1}: {CAP}"
    prompt = "\n".join(doc) + "\n\nQuestion: " + QUESTION
    line = next(i for i, p in enumerate(doc, 1) if CAP in p)
    print(f"{name}: cap on line {line} of {len(doc)}, prompt {len(prompt)} characters")
```

Output:

```text
start: cap on line 1 of 40, prompt 1528 characters
middle: cap on line 21 of 40, prompt 1528 characters
end: cap on line 40 of 40, prompt 1528 characters
```

### How would you test for it before launch?

Build a small set of test documents, each with one known fact. This is a needle test: hide the fact at set depths, then ask for it back. Plant the fact at the start, the middle and the end. Ask the questions, score each answer against the planted fact, and compare the three positions.

Then run the same check on real documents, since made-up text can flatter a model. Run it again after each change to the prompt, how the text is split, or the model, so a drop shows up in the tests before users see it.

> **Tip:** Asked how you would catch it? Plant facts at known depths, score the answers, and repeat after every change.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: a fact in the middle of a long input is often used less well.
- [ ] The 2023 paper and the two tasks it tested.
- [ ] Why a bigger context window does not fix it on its own.
- [ ] How you would test position: plant a fact at the start, middle and end.
- [ ] Fixes that lower the risk: key text first, fewer sections, question last.
- [ ] Honesty: the sources describe the pattern, and your own data decides.

**Common traps**

- Trap: "Models read the whole input equally well." Better: They often use the start and end better. Position matters, so measure it.
- Trap: "A bigger context window solves it." Better: A bigger window holds more text, but a buried fact can still be missed. Test it.
- Trap: "Adding more instructions will fix it." Better: A generic instruction does not move a buried fact. Ask the model to quote the relevant parts first, move the key text, then test.

## Can you spot the warning sign?

**Spot the warning sign:** A team plants one fact at three depths in a 40-page file. Which result shows lost in the middle?

A. Start 10 of 10 correct, middle 10 of 10, end 10 of 10.
B. Start 10 of 10 correct, middle 4 of 10, end 9 of 10.
C. Start 8 of 10 correct, middle 10 of 10, end 9 of 10.
D. Start 6 of 10 correct, middle 6 of 10, end 6 of 10.

**Answer:** B. The middle drops to 4 of 10 while the start and end hold up, which is the pattern the paper describes. The numbers are made up. The last option is a different problem: the test fails at every depth, so check the prompt and the model setup first.

**Quick check:** A bank's policy assistant keeps missing the fee rule on page 22 of a 40-page document. What is the first thing to try?

A. Use a bigger model
B. Move the fee rule to the start and put the question last
C. Lower the temperature
D. Add more instructions to the system prompt

**Answer:** B. Position is the first thing to test, and moving the key text to the start with the question last is a cheap change. A bigger model or a lower temperature does not change where the fact sits, and a generic extra instruction does not move it either.

## Can you answer these from memory?

**Flash cards**

- **What is lost in the middle?** A model uses facts well near the start or end of a long input, and less well in the middle.
- **Where did the name come from?** A 2023 paper, Lost in the Middle, which tested two tasks on long inputs.
- **Does a bigger window fix it?** No, not on its own. Where a fact sits can still change the answer.
- **Lost in the middle vs context rot?** Rot is recall falling as the input grows. Lost in the middle is about position.
- **First fix to try?** Put the key text at the start or end, the question last, then test.
- **How do you check it?** Plant one fact at the start, middle and end, and score the answers.

## 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
- Q138 RAG vs long context: which to use? https://designervenkat.online/interview/ai/rag-vs-long-context
- Q113 What is chunking, and why does size matter? https://designervenkat.online/interview/ai/what-is-chunking-in-rag
- Q008 What is a context window? https://designervenkat.online/interview/ai/what-is-a-context-window

## Learn it in depth

- [Long-Context Processing](https://designervenkat.online/learn/ai-engineering/long-context-processing)
- [Context Failure Modes](https://designervenkat.online/learn/ai-engineering/context-failure-modes)
