Prompting: clear instructions, examples, structured output

Prompting is writing the instructions, context and examples an LLM receives on each call; a good prompt is a complete, specific briefing that leaves the model little to guess.

Why it matters

The model knows nothing about your task, your users or your data except what is in the prompt. Vague prompts get vague, inconsistent answers that code can't parse. Prompting is the cheapest and fastest lever you have: improve it before reaching for RAG or fine-tuning, and measure the improvement on many inputs.

The idea

The prompt is the model's only briefing. Be clear and specific, give context, show examples of the output you want, and ask for a fixed format, like JSON, when code will read the answer.

Briefing a smart new colleague on their first day. They are capable, but they know nothing about your project unless you tell them.

A colleague asks when they are unsure. A model usually guesses instead, so leave less to guess.

How it works

  1. Say who the model is acting as and for whom: "You are a support triage assistant for engineers."
  2. Give the context it can't know: where the text comes from, what the product is, what matters.
  3. State the task precisely, with limits: "Summarise in 2 sentences", "list at most 3 risks".
  4. Show one or more examples of input and the exact output you want (few-shot prompting). Examples often beat paragraphs of rules.
  5. Ask for a fixed format when code reads the output: JSON with named fields, or text between tags.
  6. Put long documents first and the question last, and mark data clearly (for example inside <document> tags) so it isn't mistaken for instructions.
  7. Test the prompt on a set of real inputs, look at the failures, change one thing, and test again.

Key points

Common mistakes

Not true: A prompt that works on one example is ready to use.
In fact: One example proves little: a prompt can pass it and fail on many others. Judge every prompt on a test set of varied cases.

Not true: Asking for JSON: the model will choose sensible fields and types by itself.
In fact: Unless you name the fields, their types and the allowed values, each reply can come back in a different shape. Spell out the structure you want.

Part of Unit 5: AI engineering in the free ML Foundations course.