Prompts#
A prompt is the input that conditions the model. Prompt engineering is the discipline of writing prompts that produce the answer the operator wants, repeatably, under load. Treat prompts the way you treat code: version-controlled, tested, reviewed.
System prompt. Persona, scope, hard constraints, output format. Stable across calls; the natural unit of prompt caching.
Tools / schema. Available tools and their JSON schemas. Also stable; cache them.
Few-shot examples. Two to five concrete input/output pairs that show the model the expected structure.
User / context. The variable part: the question, the document, the case being processed.
Output prefix. Optional hint of how the response should start (a JSON
{, a section heading) to constrain decoding.
Patterns#
Be specific. Replace “summarize this” with “summarize this network capture in ≤ 8 bullets, one per host pair, ordered by bytes transferred”.
Show, don’t describe. Two examples of the desired output beat a paragraph of instructions.
Constrain the surface. When the answer is one of a fixed set, enumerate the set. When it is JSON, give a schema. When it is free text, give a length budget.
Prefer extraction over generation when both work. “Extract the IPs from this log” is more reliable than “describe the IPs in this log”.
Externalise the chain of thought when the answer needs reasoning. Either ask for a
<thinking>block before the answer, or use the model’s native extended-thinking mode.
Prompt as code#
A prompt that ships to production is operator-class code. Treat it that way.
Single source of truth. One file, one prompt; no copies.
Templated, not concatenated. Use a template engine (Jinja, f-strings with structure); never glue strings.
Versioned. Bump a version when the prompt changes. Log the version with every call.
Reviewed. Prompt diffs go through code review like any other diff.
Tested. Eval suite runs on every change. See Evals.
Anti-patterns#
“Pretty please”, politeness adds tokens, not accuracy.
Conflicting instructions. The model picks one and ignores the rest. Audit your system prompt for contradictions.
Unbounded context. Pasting an entire corpus into every call is expensive and degrades attention. Use retrieval (RAG).
Trusting the model with secrets. Anything in the prompt may be logged by the vendor. Keep secrets out.
Prompt injection blindness. User-supplied content can carry instructions. See AI Systems as Targets for the offensive view; the defensive answer is to (a) keep tool authorization outside the prompt, (b) constrain output, (c) review tool calls.
References#
Anthropic prompt engineering: https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering
OpenAI prompting guide: https://platform.openai.com/docs/guides/prompt-engineering
Evals, how to know the prompt change helped.
Agents, when prompts grow into multi-turn loops.