Sub topic 6
Why long inputs degrade quality
This chapter assumes you can send prompts to an LLM, read basic Python, and know that models read text as tokens. It covers why a document that fits in the context window can still produce a worse summary, and how to spot and reduce the problem.
Fitting is not the same as working well
The context window is the maximum number of tokens a model accepts in one call. A document that fits is accepted, but the model does not read every part with equal care. Quality often falls as the input grows, even when the limit is far away.
Three effects show up in practice.
- Position bias. Models tend to use information near the start and end of the input more reliably than information in the middle. Researchers call this "lost in the middle". A summary of a 60-page report may cover the introduction and conclusion well and skip a key finding on page 30.
- Dilution. The more text there is, the more the instruction competes with content. Constraints such as "use only the text" or "under 200 words" are followed less often.
- Coverage collapse. A summary has a fixed length, so a long input is squeezed into the same few sentences. The model picks what is easy to find or sounds central, not necessarily what matters to your reader.
The size of these effects depends on the model, the document and the task. Treat them as risks to test for, not fixed numbers.
Testing for position bias
You can measure this on your own data. Plant a distinctive fact at different depths in a document, ask for a summary, and check whether the fact survives.
def position_test(paragraphs, fact, call_llm, depths=(0.0, 0.5, 1.0)):
results = {}
for depth in depths:
index = int(depth * len(paragraphs))
doc = paragraphs[:index] + [fact] + paragraphs[index:]
prompt = (
'Summarise the following text in 5 bullet points. '
'Use only information in the text.\n\n' + '\n\n'.join(doc)
)
summary = call_llm(prompt)
results[depth] = 'violet heron' in summary.lower()
return resultsHere fact should contain a unique phrase, and the code checks for violet heron. For example, use fact = 'The audit was delayed by the violet heron incident.'. Run it several times per depth, because model output varies. If the middle depth fails more often than the ends, your document length is in the risk zone for that model.
A planted fact is only a probe. A real summary should include the fact only if it is important, so this test shows recall of a detail, not summary quality in general.
Common errors
- Assuming "it fits" means "it works". Check output quality at the lengths you actually use.
- Putting the instruction only at the top. In a long prompt, the instruction can be far from the end of the text. Repeating it after the document is a cheap fix.
- Judging by the opening of the summary. Compare the summary against the whole source, especially the middle sections.
- Testing with one short sample. Position effects appear mainly on long inputs.
Ways to reduce the problem
| Approach | What it does | Cost |
|---|---|---|
| Shorter inputs through chunking | Keeps each call small, so the middle is never far from an edge | More calls, and extra steps to combine results |
| Structured prompts | Asks for one bullet per section, which forces coverage | You need to know the document's sections |
| Repeated instructions | Keeps the constraints near the end of the prompt | A few extra tokens |
| Verification pass | Checks key facts against the source after summarising | An extra call |
The next chapters cover chunking and the map-reduce and refine strategies that apply the first row. Each trades the middle-of-the-document risk for others, such as lost cross-chunk context.
Exercise
A 40,000-token report fits in your model's context window. Your single-pass summary covers the introduction and conclusion well but misses a major finding from the middle. Name the likely cause and two changes you could try.
Show answer
The likely cause is position bias, often called "lost in the middle": models use information in the middle of a long input less reliably than information at the start and end. Two changes are to split the report into chunks and summarise each one (map-reduce), or to ask for one bullet per section so that the prompt forces coverage of the middle. Repeating the instruction after the document is another option. Verify any change by planting a known fact in the middle and checking that it appears in the summary.
Exercise
Why does the planted-fact test run each depth several times instead of once?
Show answer
Model output varies between calls, so a single pass or fail could be chance. Repeating each depth gives a rate of recall, which you can compare across start, middle and end positions.