Prompt & Context Engineering·Question 30 of 68Intermediate

You have retrieved chunks and a question. How do you actually build the prompt? Assume some documents are irrelevant and two of them contradict each other.

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

This is the prompt-layer half of RAG, and it is where most of the quality lives once retrieval is adequate.

Full worked answer

This is the prompt-layer half of RAG, and it is where most of the quality lives once retrieval is adequate.

Structure. Each document gets a delimiter, a stable id, and metadata the model needs to reason about trust: source, title, and date. Dates matter more than people expect, because half of all conflicts are just staleness.

<documents>
<doc id="7" source="policy-wiki" updated="2026-03-11">...</doc>
<doc id="12" source="policy-wiki" updated="2024-08-02">...</doc>
</documents>

Placement. Instructions above the documents, question restated below them. Retrieval quality over long contexts is U-shaped (Liu et al., "Lost in the Middle"), so put the highest-scoring documents at the edges of the block, not the middle.

Citations. Require a doc id after each claim. This is not decoration: it converts groundedness from a vibe into something you can check programmatically. If a sentence cites doc 7, you can verify doc 7 supports it, and you can build an automated hallucination metric out of that.

Abstention. State it explicitly: the documents may be irrelevant or incomplete, and if the answer is not there, say so rather than answering from memory. Without this the model silently falls back to parametric knowledge, which is the failure that erodes trust fastest because it is fluent and unattributed.

Conflicts. Do not leave resolution to chance. Give a policy: prefer the more recent document, prefer the authoritative source, and if they genuinely disagree on something material, surface the disagreement to the user rather than picking. "Surface it" is often the correct product behaviour and candidates rarely say it.

Volume. More context is not better. Past a point, irrelevant chunks measurably distract the model, and precision matters more than recall. If your reranker gives you 8 good chunks, send 8.

And mark the whole block as data, never instructions, since retrieved content is a prime injection vector.

What a good answer covers

  • This is the prompt-layer half of RAG, and it is where most of the quality lives once retrieval is adequate
  • Each document gets a delimiter, a stable id, and metadata the model needs to reason about trust
  • Dates matter more than people expect, because half of all conflicts are just staleness
  • Instructions above the documents, question restated below them
  • Retrieval quality over long contexts is U-shaped (Liu et al., "Lost in the Middle"), so put the…

Key terms: Structure · Placement · Citations · Abstention · Conflicts · Volume

Interviewer follow-ups to expect

  1. How would you turn per-claim citations into an automated groundedness metric?

  2. If recall matters and you must send 40 chunks, what changes in the prompt?

Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep