02 / 16
Prompting & Context Engineering
The cheapest lever you have: what goes into the window.
A prompt is a list of role-tagged messages: system for stable rules, user for data and the question, assistant for prior turns. Put long documents first, the question last, and stable parts before variable ones.
Zero-shot gives only instructions; few-shot adds a handful of input→output examples, which teach format and edge cases better than prose. The model also copies their quirks, so choose them deliberately.
Have the model write intermediate steps before the answer: it buys accuracy on multi-step problems at the cost of tokens and latency. Reasoning models do it natively, so set their effort knob instead.
Don't ask for JSON, enforce it: strict schema mode masks every token that would break your schema, so output always parses. It guarantees shape, not truth, so still validate values and retry.
Treat the model like a brilliant new hire with zero context: say exactly what you want and why, separate data from instructions, show an example, and specify the output format.
Deciding, at every step of an agent or pipeline, exactly which tokens enter the window (instructions, tools, documents, tool results, memory, history), aiming for the smallest set of high-signal tokens.
The provider keeps the computed KV state of a recently seen prompt prefix, so repeat calls skip that prefill: put static content first, variable content last, and cut repeated input cost by up to ~90–95%.
Stuff the whole corpus in the window when it's small, static and shared; use RAG when it's large, changing, permissioned or high-volume. Often you do both: retrieve whole documents, then reason in long context.
Models don't use long context evenly: facts in the middle get used worst, and quality decays as input grows even on easy tasks. Send less, better context, with key parts at the edges.
Treat every prompt as a deployable artifact: templated, versioned with its model and parameters, reviewed, eval-gated in CI, rolled out gradually and logged with every trace so you can roll back in seconds.
Sample several reasoning paths at temperature > 0 and keep the answer most of them agree on, or let a verifier pick the best. Buys accuracy and a confidence signal for N× the tokens.
Stop hand-tuning prompts: define the task, an eval set and a metric, and let an optimizer search instructions and few-shot examples that maximize the metric. Prompts become learned parameters you recompile per model.