← All lessons
How LLMs work · Lesson 2 of 7

Prompting

The prompt is everything you send. Most APIs split it into a system prompt, with standing instructions (the job, the rules, the format), and a list of messages from the user and the assistant.

Most bad answers come from vague prompts. Say what the task is, who the answer is for, what format and length you want, and what to do when the model can't answer. "If the answer isn't in the policy, say you'll pass the question to a person" prevents a lot of made-up answers.

Examples beat descriptions. Two or three examples of input and the output you want (few-shot prompting) show the format and tone better than a paragraph about them. Choose examples that differ from each other, or the model will copy their quirks.

Keep instructions and data apart. Wrap documents, emails and user input in clear markers, like XML-style tags or headings, and say what's inside them. Then the model can tell the text it should work on from the instructions it should follow.

System: You answer questions for a garden shop's customers. Answer in at most three
sentences. Use only the policy below. If the answer isn't there, say you'll pass the
question to a person.

<policy>
Returns are accepted within 30 days of delivery with proof of purchase.
Sale items can be exchanged but not refunded.
</policy>

User: Can I return a bird bath I got six weeks ago?

For harder problems, ask the model to work through the steps before giving its final answer, or split the job into several smaller prompts. Many current models also have a built-in reasoning mode that does this for you; check your model's docs.

Treat prompts like code. Keep them in version control, test each change against a fixed set of examples (the last lesson covers this), and change one thing at a time so you know what helped.

Practice

Which prompt is most likely to get a useful answer?

More info

Quick reference

System promptStanding instructions for the whole conversation.
Few-shotShowing a few examples of input and the output you want.
DelimitersTags or headings that mark where data starts and ends.
Fallback instructionWhat to do when the answer isn't known.
Prompt versioningKeeping prompts in source control and testing each change.

The other AI and data engineering courses