What is prompt engineering, and which techniques matter most?
Learning path, stage 2 of 5: Prompting and model features · question 1 of 10Prompt engineering is writing and iterating on a model's instructions and context so it reliably does what you want. In practice it means being clear and specific, giving context and examples, structuring the input, and measuring the results against test cases. Clever phrasing tricks matter much less.
Techniques that consistently help
- Be explicit: say the goal, the audience, the constraints and what "done" looks like.
- Give context and the reason: "This goes to non-technical customers, so avoid jargon" works better than "be simple".
- Separate parts with delimiters or XML tags:
<docs>,<instructions>,<example>. - Show examples (few-shot) of the output you want, including edge cases.
- Let it think before answering on hard tasks (chain-of-thought or reasoning modes).
- Specify the output format, or enforce it with structured outputs.
- Break big tasks into steps (prompt chaining).
The part most people skip
Write an eval set first: 20–100 real inputs with expected outcomes. Then change one thing at a time. Prompt engineering without measurement is guessing.
Sources
Code example
1// A structured prompt: role, context, tagged input, explicit format.2import Anthropic from "@anthropic-ai/sdk";34const client = new Anthropic();56export async function reviewPR(diff: string) {7 const res = await client.messages.create({8 model: "claude-opus-5-5",9 max_tokens: 2048,10 system:11 "You are a senior TypeScript reviewer. The author is a junior dev, so explain *why* " +12 "each issue matters. Only report real bugs and security issues, not style nits.",13 messages: [14 {15 role: "user",16 content: `<diff>\n${diff}\n</diff>\n\n` +17 "List each issue as: `file:line` - problem - suggested fix. " +18 "If there are no real issues, reply 'LGTM'.",19 },20 ],21 });22 return res.content.flatMap((b) => (b.type === "text" ? [b.text] : [])).join("");23}
To run it: follow the one-time setup guide, add npm i @anthropic-ai/sdk zod, save the code as a .ts file and run npx tsx file.ts. Anything marked declare is a part you supply.
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the AI Agents & LLMs set.