I Beyond Prompting
Parts 1 and 2 taught you the constraints: context windows are finite, position matters, and memory is an illusion you build. This article is about the craft of building that illusion well.
The shift is bigger than it sounds. Context engineering is the new prompt engineering. Prompt engineering is crafting a single string of instructions. Context engineering is designing the entire system that assembles what the model sees — instructions, history, retrieved documents, tool definitions, user data, output constraints — dynamically, per request, at runtime.
Tobi Lütke, CEO of Shopify, defines it precisely: "Context Engineering is the art of providing all the context for the task to be plausibly solvable by the LLM." Not just a good prompt. All the context. Assembled correctly. At the right time.
This matters because most agent failures are not model failures anymore — they're context failures. Two products using the same model on the same task can produce dramatically different results. One feels magical; the other feels like a cheap demo. The model is identical. The context isn't.
II System Prompt Design
The system prompt is the most expensive real estate in your context window. It's sent on every request, sits at the position of highest attention (the top), and defines every behavior the model exhibits. And most teams write it once and never think about it again.
A well-designed system prompt has four layers, in order:
1. Identity and role.Who is the model? Not "You are a helpful assistant" — that's the default. "You are a senior tax advisor specializing in US corporate tax for companies with $10M-100M revenue. You are cautious about edge cases and always cite specific IRS code sections." Specificity constrains the trajectory. A model told it's a tax advisor will refuse to write poetry; a model told it's "helpful" will try anything and do most of it badly.
2. Capabilities and constraints.What can this model do and what can't it? "You have access to the company's financial database via the query_financialstool. You do NOT have access to employee personal data. If asked about personnel matters, say so and redirect to HR." Explicit boundaries prevent the model from hallucinating capabilities it doesn't have.
3. Output format and style.How should responses look? "Respond in JSON with keys: answer, confidence, sources. Keep answers under 200 words. Use a professional but approachable tone." Format constraints are the cheapest way to improve consistency — they cost a few tokens and save hours of post-processing.
4. Error handling and edge cases.What should the model do when it doesn't know? "If you are uncertain about a tax ruling, say 'I'm not confident about this — please verify with a CPA' rather than guessing. Never fabricate an IRS code section." This is where most system prompts fail. They define the happy path but not the failure path.
III Few-Shot Examples
Parts 1 and 2 never mentioned few-shot examples. They're one of the most powerful context engineering tools you have, and they're chronically underused.
A few-shot example shows the model a completed input-output pair: "Given this input, here's what a perfect response looks like." The model pattern-matches against the examples and produces output that follows the same structure, tone, and level of detail. It's teaching by demonstration rather than instruction.
How many? 2–3 examples hit the sweet spot. One example is often misread as a rigid template. Four or more consume too many tokens for diminishing returns. Exception: classification tasks, where 5–10 examples covering each category dramatically improve accuracy.
Which ones?Select examples that cover your most common case, your hardest edge case, and the output format you want. Don't pick three examples that all look the same — pick three that show the range of acceptable responses. If your model writes customer support replies, include: a straightforward answer, a response that politely declines, and a response that escalates to a human.
Where to place them? After the system prompt, before the conversation history. Examples in the system message get high positional attention and consistent treatment across turns. Placing them in the user message works for single-turn tasks but gets pushed further from the top as conversation grows.
Format matters. Use a clear delimiter between examples and the actual task. A simple pattern works:
## Example 1User:What's the return policy for damaged items?Response: {"answer": "Damaged items can be returned within 30 days with photos of the damage. We'll cover return shipping.", "confidence": "high", "sources": ["returns-policy-v3.md"]}## Example 2User: Can I get a refund in Bitcoin?Response: {"answer": "We only process refunds to the original payment method. We don't support cryptocurrency refunds.", "confidence": "high", "sources": ["payment-methods.md"]}## Now handle this:
IV Retrieval Quality Control
Part 1 covered where to put retrieved documents in the context window (edges, not middle). This section covers what to retrieve and when to retrieve nothing.
Relevance thresholds.Every retrieval system returns a similarity score. Most teams use the top-K results regardless of score. This is wrong. A query about "parental leave policy" might return "parking policy" as the third-best match if your corpus is small. Set a minimum similarity threshold and return fewer results when nothing is truly relevant. Three good chunks beat five chunks where two are noise.
Chunk size selection.Too small (100 tokens) and you lose surrounding context — a sentence about a return policy without the conditions that apply. Too large (1,000 tokens) and you waste budget on irrelevant content surrounding the relevant sentence. 200–500 tokens per chunk is the pragmatic range for most use cases. Overlap chunks by 10–20% so you don't accidentally split a key sentence at the boundary.
Retrieval isn't just search.A basic RAG pipeline embeds the user's query and finds similar chunks. Better pipelines add: query expansion (rephrase the question to catch different formulations), reranking (a second model scores the top-20 results and returns the top-5), and metadata filtering (only retrieve chunks from the relevant department, date range, or document type).
When to suppress retrieval.If no chunk exceeds your relevance threshold, don't inject anything. An empty retrieval result is better than a misleading one. The model is more likely to say "I don't know" with no retrieved context than with bad retrieved context — because bad context gives it something plausible to confabulate from.