Vocabulary for this course

The terms the chapters assume, in plain words. You can open this from any chapter.

constraint
A limit on the answer that a program can check, such as a length, an allowed label or a required citation.
context
The background material the model needs to answer well, kept separate from the thing it must act on.
continuation
The text a model writes next, given everything that came before it.
delimited block
Text wrapped by matching markers, such as triple backticks, so its edges are unmistakable.
distribution
The pattern of how often each possible value appears, or how likely each one is.
few-shot example
A worked input and answer pair placed in the prompt so the model can copy the pattern.
instruction
The sentence that names the task, usually starting with a verb.
JSON
A text format for structured data built from names, values, lists and nested braces.
model
The trained program that reads text and predicts what comes next.
output contract
The part of a prompt that states the shape of a valid answer, in words a checker can enforce.
parser
The code that turns the model's text into a value your program can use.
prompt
Everything sent to the model in one request: instructions, background, the input and the answer's required shape.
prompt injection
Text that tries to give the model orders, either typed by a user or hidden inside a document it reads.
register
The level of formality and the kind of wording suited to a particular audience or setting.
schema
A named set of fields with their types and allowed values, used to check an answer's shape.
system message
The opening instruction the model treats as standing policy for the whole exchange.
temperature
A setting that controls how much randomness the model adds when choosing each token.
token
A chunk of text — often part of a word — that the model reads and bills for.
user message
A turn written by the person using the app, treated as data rather than standing policy.

Prompt engineering from the ground up

What a prompt is

Four parts, not one blob: the instruction, the context, the input and the output contract. Most bad prompts are missing one of them.

Part 1 of 10

Beginner13 min readBack to Courses

The four parts

A prompt is usually described as “what you type”. That framing hides the structure that makes one reliable and another a lottery. Every prompt that works has four parts: an instruction saying what to do, context the model needs, the input to act on, and a contract describing what the answer should look like.

When an answer disappoints, one of those four is usually missing. The model guessed the format, or invented context, or answered a slightly different question because the instruction was a topic rather than a task.

Mechanically, the model receives one string and produces one continuation. Every dimension you leave open — length, register, format, what counts as relevant — is filled from the distribution of text it was trained on. That is not randomness; it is an average, and the average is usually longer and more cautious than a product needs. The four parts work because each one closes a dimension before generation starts.

Instruction is a verb

“Refunds” is a topic. “Summarise the refund policy in three sentences for a customer” is an instruction. The difference is a verb, an object and a constraint — the three things a model needs before it can do anything specific.

A useful test: could a new colleague follow the instruction without asking a question? If not, the model is guessing too, and it will guess differently on Tuesday.

The four parts, labelled

PROMPT = """You are a support assistant.          # role
Summarise the policy in three sentences. # instruction
Use only the text between the markers.    # constraint

<policy>
{policy}
</policy>

Return plain text. No headings, no bullets. # output contract
"""

Assemble the four parts

Run the builder, then remove the output contract and see what the assembled prompt is missing. Add a second constraint and check it appears in the right block.

Output
Click "Run" to execute your code

One request, four blocks

Take a request that arrives as “the customer wants to know about refunds”. The instruction is “answer the customer’s question about refunds”. The context is the refund policy and the customer’s plan. The input is the question itself. The contract is “at most three sentences, plain text, cite the policy section”. Written as one sentence, the same request leaves the model to decide whether it is writing a policy summary, an email, or an internal note — and it will pick one silently.

The symptom of a missing block is easy to recognise once you look for it: the answer is plausible but shaped for someone else. A reply that reads like documentation when you wanted a customer email usually means the audience was never stated. A reply that runs to five paragraphs when you asked for a summary usually means the length was never stated. Fix the missing block, not the wording of the instruction.

The contract is not decoration

The output contract is what makes a reply usable by code. “Answer in JSON with keys sentiment and confidence” is a contract; “reply in JSON” is a hope. If a parser runs afterwards, the contract and the parser are the same requirement written twice.

Contracts should be checkable. A length limit, a set of allowed labels, a required citation — each can be verified mechanically, which is what turns a prompt into something testable.

Write the contract in the same words the parser uses. If the parser expects a key called sentiment, the prompt should name that key rather than “a sentiment field”; if the parser rejects a trailing sentence, the prompt should say “return the object and nothing else”. When the two drift, the failure looks like a model problem but is a specification problem, and the fix belongs in the prompt.

Write the prompt as four labelled blocks even when you send it as one string. The labels are for you: they make the missing part obvious during review.

Context is not the same as input

The input is what the task is about — the sentence to classify, the question to answer. Context is what the model needs to do it correctly: a policy, a schema, a previous turn. Mixing them is how a document ends up being summarised instead of used as reference.

Keep context in its own delimited block and say what it is for. That single habit removes a large share of “the model ignored my instructions” reports, because the instructions are no longer buried inside a wall of text.

Diagnose a vague prompt

The prompt below is a topic, not an instruction. Rewrite it with a verb, an object and one checkable constraint, then compare the two strings.

Output
Click "Run" to execute your code

Check what you learned

One question at a time. A wrong answer explains itself — take another go.

Part 1 of 5

What are the four parts of a working prompt?