Skip to content
mentoor

Topic 2 of 5 · 4 min read

Ordering instructions, data and questions

Goal: Reorder a long-context prompt so documents come before the question and explain the effect on answer quality.

Put the role and goal first, the long documents next, and the specific question last. Where something sits in a long prompt changes how well the model uses it.

Check yourself · 1 of 3

You paste a 30-page report and then ask a question. Where should the question go?

Choose one answer

Why it matters

Models do not read a long context evenly. The "Lost in the Middle" study found that accuracy is highest when the needed fact is at the start or the end of the context and drops when it is buried in the middle. The effect is smaller in newer models, but it has not gone away. Vendors give similar advice. Claude's docs say to put long documents near the top and the query at the end. OpenAI's GPT-4.1 guide says that when context is very long, repeating instructions at both the start and the end works best.

For you this means the same words in a different order can give a better or worse answer, and nobody changed the content.

How to do it

  1. Start with role and goal. Two or three sentences: who the model is, what the output is for, who reads it.
  2. Add stable rules. Format, tone, limits, what to do when the answer is not in the documents.
  3. Then the long material. Documents, logs, transcripts, retrieved passages. Put the most important ones near the edges, not in the middle.
  4. Then examples, if you use them, after the rules they illustrate.
  5. Question last. Put the specific task right after the data, so it is the freshest thing in context.
  6. Repeat the one rule that must not fail. For a very long prompt, restate it in one line at the end.

Before and after

Before, the question comes first and the model has 40 pages to wade through:

Which clauses allow early termination? 
<documents> ...40 pages... </documents>
Be concise.

After:

You are a contract analyst helping a legal team find risk.
Answer only from the documents. If the answer is not there, say so.
<documents> ...40 pages... </documents>
<question>Which clauses allow early termination? Quote each one.</question>

What goes wrong

  • Burying the key document in the middle of a long list of retrieved passages.
  • Splitting the task. Half the instruction at the top, the other half hidden after the data.
  • Putting the question first and trailing it with "also, one more thing". The late additions often win, which is rarely what you meant.
  • Assuming a bigger context window removes the problem. More room is not the same as equal attention.

Examples

Reordering a retrieval prompt

Before: question, then 12 retrieved passages in score order, then style rules.
After:  role and rules, then passages (best match first, second-best last),
        then the question.

The best passage sits at the start, the next best at the end, and weaker ones fill the middle. The question follows the data directly.

Repeating the critical rule

<rules>Never include customer phone numbers in the summary.</rules>
<transcript> ...long call transcript... </transcript>
<task>Summarise the call. Reminder: no phone numbers.</task>

One short repeat costs a few tokens and protects the rule that matters most.

Key points

  • Order a long prompt as role and goal, rules, documents, examples, then the specific question.
  • Models tend to use the start and end of a long context better than the middle.
  • Put the question after the documents so it is the last thing the model reads.
  • In very long prompts, repeat the one rule that must not fail near the end.
  • A bigger context window is not a guarantee of equal attention to every part.

Common mistakes

  • Putting the question before 40 pages of documents and expecting it to carry through.
  • Leaving the best retrieved passage in the middle of the list.
  • Splitting one task across the top and the bottom of the prompt so the two halves disagree.
  • Assuming a larger context window means every part gets equal attention.

Check yourself · 2 of 3

What did the "Lost in the Middle" study find about long contexts?

Choose one answer

Check yourself · 3 of 3

A prompt is very long and one rule must never be broken. What is a sound way to protect it?

Choose one answer

Practice items, not counted towards your mastery.

Start here