Prompt Engineering

Writing instructions that get reliable, useful results from language models.

A prompt is the instruction and context you give a model. Small changes in wording, structure or examples can change the quality of the result a great deal. Prompt engineering is the practice of writing prompts that are clear, specific and reliable, and of testing them like any other part of a system.

Good prompts look a lot like good briefs to a capable colleague: what you want, why, what good looks like, and what to avoid.

Core techniques

A few techniques cover most needs.

Clear instructions
Say exactly what you want, the audience, the format and any constraints.
Zero-shot
Asking for a task without examples: "Classify this ticket as bug, feature or question."
Few-shot
Including a few examples of input and desired output to guide format and judgement.
Step-by-step reasoning
Asking the model to think through a problem before answering, which helps on complex tasks.

Context is everything

Models only know what is in their training data and the prompt. Provide the relevant context: the document to summarise, the code to review, the policy to apply, the definitions your organisation uses. Clearly separate instructions from content, for example with headings or tags, so the model knows which is which.

Structured output

When another system will use the result, ask for a defined structure such as JSON with specified fields, and validate it. Many model APIs now support structured output directly, which makes integration far more reliable than parsing free text.

System prompts and roles

In applications, a system prompt sets the model's role, rules and boundaries for every conversation. Keep it focused: who the assistant is for, what it should and shouldn't do, the tone, and how to handle uncertainty, such as saying "I don't know" rather than guessing.

Treat prompts like code

Prompts that run in production should be version-controlled, reviewed and tested against an evaluation set before changes go live. A wording change that improves one case can break another. Keep a record of which prompt version produced which results, so problems can be traced and rolled back.

Prompts are also an attack surface. User input and retrieved documents can contain instructions that try to override yours, so never put secrets in prompts and treat external content as untrusted.

Prompts for coding agents

Coding assistants and agents respond to the same principles, applied to a repository. Give them a context file with build and test commands, conventions and known pitfalls; ask for a plan before they change code; and state a checkable definition of done, such as "all tests in this folder pass".

The clearer the goal and the faster the agent can check its own work, the better the result, often in a single pass.

How to put it into practice

  1. Write the prompt as a brief: task, audience, context, format, constraints.
  2. Add two or three examples for tasks that need a specific format or judgement.
  3. Separate instructions from content clearly.
  4. Ask for structured output when another system consumes the result.
  5. Build an evaluation set of 20–50 real cases and test every prompt change against it.
  6. Version prompts in source control alongside the code that uses them.

Common mistakes

  • Vague prompts that leave the model guessing what good looks like.
  • Changing production prompts without testing.
  • Putting secrets or sensitive data in prompts unnecessarily.
  • Trying to fix every problem with longer prompts instead of better context or a different approach.

How to measure progress

  • Pass rate on the evaluation set for each prompt version.
  • Share of outputs needing human correction.
  • Tokens per request, as a cost and latency indicator.
  • Incidents caused by prompt changes.

Go further