Prompt structure — study guide
The concept's fragments, read in order.
For your capstone A self-driving RC car you build from bare metal
When the car's planner consults a model, the prompt is the whole task. The model knows nothing about your chassis, your track or what the controller will accept, so the instructions and the output contract have to say it, and whatever they leave open the model settles with a guess.
The fixed part reads: you plan for a small RC car on an indoor track; reply with one action from forward, left, right or stop and a speed from 0 to 40 percent, because the controller rejects anything faster. If the distance reading is missing, reply stop. The variable slot holds this call's state inside <state> tags, such as distance_cm=45 heading_deg=88, kept apart from the instructions that say what to do with it.
Everything the model gets
A model call has exactly one input: the prompt. The model keeps nothing between calls, and it produces its answer by continuing the text it is handed, so whatever the prompt says, and only what it says, is the task. It brings no knowledge of your project and no memory of the correction you made last time. If the answer depends on something, that something has to be in the prompt.
That makes a prompt less like a question typed into a box and more like a specification. It says what the job is, supplies the material to work on, may show worked examples, and states what shape the answer should take. Each of those parts does a different job, and a prompt that runs them together into one paragraph is harder to get right and much harder to fix when it goes wrong.
This concept is about those parts: what each one is for, how examples steer what comes back, why instructions should be kept visibly apart from the data they act on, and why a prompt that a program depends on deserves the care given to any other source code. It teaches structure rather than tricks, because the tricks shift from one model generation to the next and the structure does not.
The parts of a prompt
Prompting guides and research describe much the same building blocks, offered as a toolkit rather than a mandatory template. Instructions say what the job is and the rules for doing it: the task, the audience, the constraints. Context is background the model needs and cannot know, such as a definition, a policy or the facts of the situation. Examples are worked pairs of input and output that show what a good answer looks like. The task input is the material for this one call: the document to summarize, the message to classify, the question asked. The output contract says what shape the answer must take.
Many model interfaces let you send text under different roles: a system or developer role for standing instructions, and a user role for the request of the moment. The split mirrors a real difference, since standing instructions stay the same across thousands of calls while the request changes on every one. Treat it as a way of organizing the prompt, though, not as an enforced rank. System instructions are meant to win when the two conflict, and evaluations across many models have found that they do not reliably do so.
The more useful split for an engineer is fixed versus variable. Instructions, context that applies to every call, examples and the output contract form a template that changes only when someone edits it on purpose; the task input fills a slot in that template on each call. All of it ends up as one sequence of tokens for the model to continue, but keeping the parts distinct in how you write and store them is what lets you change one without disturbing the rest.
Instructions a stranger could follow
A model cannot stop halfway through a call to ask what you meant. Whatever the instructions leave open, it settles by producing a plausible continuation, a guess shaped by what usually follows text like yours rather than by your intent. Writing instructions is therefore like writing a work order for a capable contractor who has never seen the site and cannot phone back with questions: anything left unwritten gets filled in with a guess.
Specific beats general. "Summarize this email" leaves the length, the reader and what counts as important to chance; "summarize this customer email in two sentences for the support lead, starting with what the customer is asking for" does not. Name the task, who the output is for, the constraints, and what a finished answer looks like. When a rule matters, give its reason: "keep it under 30 words, because it appears in a phone notification" tells the model what the rule protects, which helps in the cases the rule did not anticipate.
Say what to do, not only what to avoid. "Don't be wordy" rules out one kind of answer and leaves countless others open; a word limit plus a short list of what to cover gives a single path. A good test for any set of instructions is to imagine handing them to a capable person who has never seen your project and cannot ask a question. Whatever that person would have to guess, the model will guess too.
Keeping instructions apart from data
To the model, the whole prompt is one stream of tokens. Your instructions and the material you paste in arrive through the same channel, text, and nothing in that text marks where one ends and the other begins unless you put the mark there. If the material happens to contain a sentence phrased as a request, say a customer email that ends "please reply in French", the model has no built-in way to know that sentence is part of the thing to process rather than part of the job.
The remedy is to mark the boundary in the text and say in the instructions what the marks mean. Put the material inside clearly labeled sections or delimiters, such as a line of ###, triple quotes, or XML-style tags like <email> and </email>, and refer to it by that name: "summarize the email inside the email tags". It works like quoting someone else's letter inside your own memo, with clear marks around it, so the reader knows which words are your request and which are the material you are asking about. The marks reduce ambiguity, and in a prompt carrying several pieces of material they let the instructions point at each one precisely.
The same separation pays off in code. The instructions live in a fixed template and the material is inserted into a named slot at call time, so the program never splices outside text into the middle of an instruction. One limit needs saying plainly: delimiters are a clarity aid, not a security boundary. A tag tells the model which text is meant to be data; it does not stop instructions planted in that data from influencing the result. Defending against text written to hijack a model is a separate problem, and a harder one.
Showing instead of telling
An example, a worked input paired with the output you want, often pins down a task more precisely than a paragraph of description. Putting a handful of them in the prompt is called few-shot prompting; a prompt with none is zero-shot. Examples earn their place when the pattern is easier to show than to describe: a tone, a level of detail, an exact layout. Prompting guides commonly suggest starting zero-shot and adding examples when the instructions alone fall short.
Examples steer harder than they look, and not only in the intended ways: the model learns from them like a newcomer shown three finished forms before a blank one, who copies whatever the finished ones have in common, including habits nobody meant to teach. It imitates their format, length and style, so three one-line examples tend to produce one-line answers whatever the instructions say about detail. It also picks up incidental patterns. Research on classification tasks found that models leaned toward whichever label appeared most often among the examples, and toward labels that appeared near the end of the list. Another study found that swapping the examples' correct labels for random ones often cost surprisingly little accuracy: much of what the examples taught was the format and the range of possible answers, not the right answer for each case.
Those are findings about the models tested at the time, but the lesson behind them holds up: a model treats whatever the examples have in common as part of the instructions. So choose them deliberately. Make them varied enough to cover the inputs the prompt will really meet, including an awkward case or two; balance the labels rather than letting one dominate; and check that they agree with the instructions, because a model shown one thing and told another has to pick, and you do not get to choose which.
Saying what the answer looks like
Downstream of every model call is a reader: a person scanning the answer, or often a program that has to do something with it. The output contract is the part of the prompt that tells the model what that reader needs: the format (plain prose, labeled lines, JSON), which fields must be present, how long the answer may be, and which values are allowed, such as a closed set of labels for a classification. It is the prompt's equivalent of a function's return type, written in words.
A good contract also covers the case where the task cannot be done. Without a stated way out, the model's job is still to continue the text, and the natural continuation of a question is an answer, whether or not the material contains one. Saying what to return instead, a specific value such as unknown or a short note naming the missing information, gives that case a defined shape the reader can check for, rather than a confident invention it has to catch.
Stating the contract is a request, not a guarantee. The model generates text that usually honors it, and a program that depends on the result still has to check, because fluent output is not verified output. Making output reliably parseable and validating it on arrival is a concept of its own; the point here is that the contract belongs in the prompt, stated once, explicitly, and in agreement with the examples.
What lasts and what dates
Prompting advice has a short shelf life. Much of it was found by trial on one model, generalized into a rule, and passed along long after the models it was tested on had been replaced. The useful habit is to sort advice by the reason behind it. Advice that follows from how a model works tends to last. Advice that is a measured quirk of one model generation tends not to.
Two well-known tips show the second kind. Opening a prompt with a persona, such as "you are an expert", is a popular tip; one 2024 study tried 162 personas on 2,410 factual questions across four families of open models and found that adding a persona usually made no statistically significant difference to accuracy. The phrase "let's think step by step" produced large gains on arithmetic problems for a model of 2022; a 2025 evaluation on a graduate-level science benchmark found that models built to reason before answering gained about 3 percent at most, one lost accuracy, and all took 20 to 80 percent longer, while other 2025 studies found larger gains on harder math tasks. Neither result is a permanent law either, and that is the point: both are measurements of particular models, and measurements move.
The sharper lesson is that changes which should not matter can matter a great deal. One 2023 study varied only formatting details that left a prompt's meaning untouched and found accuracy gaps of up to 76 points for one open model on few-shot classification tasks, and about 10 points on average across more than 50 tasks. Another, from 2022, found that reordering the same few-shot examples could move a model from near the best published result to near random guessing on classification tasks. A prompt's behavior is a property of that prompt on that model, and the only way to know it is to test it.
What lasts is the structure: clear instructions, material set apart from them, representative examples, an explicit output contract. Those follow from what a model is, a system that continues the text it is given, and no model generation repeals that. Everything else is a hypothesis to test on the model you actually run.
A prompt is source code
A prompt that a program sends is part of that program. It decides what the system does as surely as any function, and changing one word can change the behavior, so it deserves the same treatment as code: kept in version control, reviewed when it changes, and tested before the change ships. A prompt assembled from string pieces scattered through a codebase cannot be reviewed as a whole, and one edited live in production has no history to roll back to.
Keep the prompt as a template: a file holding the fixed parts, with named slots where the per-call values go. The code fills the slots and checks that every one was filled, so a missing input fails loudly instead of producing a prompt with a hole in it. Record alongside the template the things that shape its behavior as much as its wording does, such as the model it was tested against and the generation settings. Log which prompt version produced each output, so a bad answer can be traced to the exact text that caused it.
Then change it the way you change code. Keep a fixed set of test inputs drawn from real cases and past failures, and rerun all of them after every edit, comparing against what the previous version produced. Change one thing at a time, so that when results move you know why. The same loop applies when the model changes and the prompt does not: a prompt tuned on one model version is an untested prompt on the next. Deciding what counts as a better answer, and measuring it repeatably, is a discipline of its own; the habit to build here is that no prompt change ships without a rerun.
Where every model call starts
Every system that uses a language model, whatever surrounds it, comes down to text sent to a model and text coming back. A pipeline of agents, a feature in an app you run in production, a planning step that consults a model: each call is a prompt, and what comes back can be no better specified than what went in.
Structure is what makes those prompts maintainable. With instructions, material, examples and output contract kept distinct, you can see what a prompt asks for, change one part without breaking another, and tell from a test run whether a change helped. Without it, each prompt is a one-off paragraph that works until it does not, and nobody can say why it stopped.
The concepts that follow lean on this one directly. Getting output a program can parse reliably, letting a model call tools, running it in a loop as an agent, and measuring whether its answers are any good all assume a prompt built from these parts, with a contract it is asked to meet and a version you can point to.
Next on your path to A self-driving RC car you build from bare metal: Structured output ▸