Prompt and context engineering
Treat the context window as a budget you assemble per request: instructions, examples, retrieved data and state, each earning its tokens.
"Prompt engineering" has grown into context engineering: deciding what goes into each model call. Anthropic's Applied AI posts list "prompting, context engineering, agent architectures, evaluation frameworks" together (official, Sources A6).
A prompt that survives production
- Role and goal in one or two sentences.
- Rules as a short list. Say what to do, not only what to avoid.
- Data clearly delimited (for example in tags) and labelled as data, not instructions.
- Examples (few-shot) when the format or judgement is subtle. Two good examples beat ten mediocre ones.
- Output contract: a schema, or a tool the model must call.
<role>You triage customer support tickets for an internal IT team.</role>
<rules>
- Choose exactly one category from the list.
- If the ticket mentions a security incident, set urgent = true.
- If you are unsure, choose "other" and explain in one sentence.
</rules>
<ticket>
{ticket_text}
</ticket>
Respond by calling the classify_ticket tool.
Managing context over time
- Put stable content first (system prompt, tools, long documents) so provider prefix caching can reuse it.
- Compact long conversations: summarise older turns, keep recent turns verbatim.
- Retrieve, don't stuff: pull the five relevant chunks instead of the whole manual.
- Version prompts like code: in the repository, reviewed, and tied to eval results.
Practice
Written for this site to drill the lesson. Not reported interview questions.
- Rewrite a vague prompt ("Summarise this meeting") into one with role, rules, data and an output contract.
- A chat assistant gets slower and dumber after 40 turns. Propose a context strategy.
Check yourself
Why put stable content first?
So prefix caching can reuse it across requests, cutting cost and time to first token.
What is an output contract?
A schema or tool call the response must satisfy, validated by code.
Sources
Saved in this browser.