Prompt engineering for everyone: role, context, format and examples

Practice7 min read

Prompt engineering is the practice of phrasing instructions so that a model responds predictably and usefully. It does not require programming, and it is handy for writing, analysis, learning and, of course, code.

A simple template with five elements

  1. Role: who the model should be, for example "an experienced programming teacher".
  2. Task: what exactly should be produced.
  3. Context: for whom, what you already know, what the constraints are.
  4. Format: a list, a table, a short paragraph, code in a single file.
  5. Quality criteria: length, tone, what to avoid.
You are an experienced programming teacher. Explain what a variable is to someone who has never programmed. Use one everyday comparison and one short example in JavaScript. Answer: 150 words at most, no jargon.

Show an example instead of describing

One or two samples of the desired answer often work better than a long description. If you want a specific format for notes, paste a short example of such a note and ask for the same structure for a new topic.

Separate instructions from material

When you paste text or code to be processed, separate it from the instructions, for example with a heading or triple quotation marks. That way the model will not confuse the material with the instruction.

Ask for a plan on complex tasks

Instead of "do it", write "first propose a plan in a few steps". Fixing a plan is cheaper than fixing a finished result.

Iterate specifically

The first result is a draft. Refine it precisely: "cut it in half", "make the tone less formal", "add handling for empty data". A generic "improve this" usually improves nothing.

System prompt: a standing instruction

In many tools you can set an instruction that applies throughout the conversation, often called a system prompt or project instructions. It is a good place for the role, style and rules, for example "answer in English, briefly, with examples". Keep it concise and concrete, because it affects every answer.

What to avoid

Rules focused on code can be found in the guide how to write prompts for code.