← Back to modules

Prompt Engineering & Context Design — Core

How prompts become token predictions, the context budget, lost-in-the-middle, system prompts, framing, few-shot and chain-of-thought, structured outputs, and prompt injection.

Medium30 questions

Sample questions

1

What is the most accurate mental model of what a prompt does to a language model?

  • It sends a request to an assistant that consults its memory and returns the correct stored answer
  • It configures a text-completion machine so that the desired output becomes the most probable continuation
  • It compiles into fixed instructions that the model executes deterministically like a normal program
  • It searches a database of prior conversations and returns the closest matching reply it can find there

Why

A prompt is best understood as a configuration of a probabilistic text-completion machine. The model predicts the most likely continuation given the full context. Your job is to build a context that makes the output you want the most probable continuation. The assistant-consulting-memory option is misleading because the model is not looking up a stored answer; it generates a distribution over next tokens. The compiles-to-fixed-instructions option is wrong because the mapping from prompt to output is probabilistic and sensitive to small wording changes, unlike deterministic code. The searches-a-database option is wrong because there is no retrieval over past conversations happening inside the model itself. Thinking of the prompt as a program running on a probabilistic computer explains why phrasing, ordering, and examples all shift behavior. It also reframes prompt design from writing text to engineering an input distribution.

2

Why is the context window best treated as a fixed token budget rather than just a place to paste text?

  • Because the window silently grows to fit whatever you add, so budgeting is only a stylistic preference
  • Because only the system prompt counts against the limit, and everything else is billed and stored separately
  • Because the model reads the components in random order, so the total size is the only thing that matters
  • Because every included component displaces others within a hard token limit, so inclusion is a tradeoff

Why

The context window has a fixed maximum size measured in tokens. Everything you include competes for that space: the system prompt, few-shot examples, retrieved documents, conversation history, the user message, and room reserved for the output. Adding one component leaves less room for another, so every choice is a tradeoff. The silently-grows option is wrong because the limit is a hard architectural ceiling, not a soft preference. The only-system-prompt-counts option is wrong because all tokens in the window count, not just the system prompt. The random-order option is wrong because order matters for attention and is not random, and size alone does not capture that. Treating the window as an information-architecture problem under a budget is what separates engineering prompts from merely writing them. It also forces deliberate decisions about what earns its place per token.

3

Research on the 'lost in the middle' effect found what about where information sits in a long context?

  • Information in the exact middle of the context is retrieved most reliably, so key facts belong there
  • Information at the beginning or end is retrieved more reliably than information buried in the middle
  • Position has no measurable effect on retrieval once the model has a long-context training objective
  • Only the very last token matters, so all earlier context is effectively ignored by the model

Why

Studies of long-context retrieval found a U-shaped pattern. Facts placed near the beginning or the end of the context are recalled more reliably than facts placed in the middle. Accuracy drops noticeably when the needed information sits in the middle of many documents. The middle-is-best option is the opposite of the finding. The no-effect option is wrong because the effect persists even in models trained for long context. The only-last-token option overstates the case; earlier context still contributes, it is just weaker in the middle. The practical response is to place critical instructions first and the immediate question last. When you include many retrieved documents, re-rank them so the most relevant is not stranded in a weak middle position. This turns document ordering into a real design lever rather than an afterthought.

4

Why do instructions placed in the system prompt tend to be followed more reliably than the same instructions in a user message?

  • The system prompt occupies a privileged early position and is trained to carry the application's standing rules
  • The system prompt is encrypted, so the model treats its contents as trusted and immutable rules
  • The system prompt is the only text the model actually reads; user messages are summarized before input
  • The system prompt bypasses tokenization, so its instructions reach the model without any information loss

Why

The system prompt sits at the start of the context and is treated as the standing configuration for every turn. Models are trained to give these instructions strong, persistent weight, so behavioral rules and output formats placed there are followed more reliably. Its early position also aligns with the strong attention that beginning-of-context tokens receive. The encrypted option is fabricated; there is no encryption, and trust comes from training and position. The only-text-read option is wrong because user messages are absolutely part of the input, not summarized away. The bypasses-tokenization option is wrong because the system prompt is tokenized like any other text. This is why the system prompt is often called the constitution of an application. It is the highest-leverage place to put rules that must always hold. Even a single-word change there can shift behavior measurably.

5

For a structured extraction task, why does a specific system prompt usually beat a longer but vaguer one?

  • A specific prompt is always shorter, and shorter prompts are cheaper, which is the only real benefit here
  • A vague prompt confuses the tokenizer, which then produces malformed tokens that corrupt the output
  • A longer prompt always lowers accuracy because the model can only attend to a fixed number of words
  • A specific prompt constrains the output space, telling the model exactly what structure and values are valid

Why

Specificity works because it constrains the space of acceptable outputs. When you state the exact fields, the allowed values, the output structure, and what to do in edge cases, the model has far less room to drift. A vague prompt full of general encouragement leaves the output under-determined, so results vary. The always-shorter option is wrong because specific prompts are not necessarily shorter, and cost is not the mechanism. The confuses-the-tokenizer option is fabricated; vagueness affects the model's choices, not tokenization correctness. The longer-always-lowers-accuracy option is too absolute; length is not the problem, ambiguity is. Adding explicit output-format constraints measurably raises format compliance without hurting accuracy. The rule of thumb is that the model does not need motivation, it needs constraints. Precise, actionable rules outperform long, hedged guidance.

Free account

Take the full module

These are the first few of 30 questions. A free account opens the rest as a scored drill.

  • Every question in this module
  • Instant feedback and supporting reading
  • Your score and progress, saved

Free · your email is used for progress only.