…
…
AI Fundamentals · Lesson 21 / 31 · Writing and checking prompts
PreviewIn this lesson you will
You can read the explanation without an account. The exercises and quiz at the end of the lesson are for members.
Elena wants ready-made answer drafts for the scholarship questions that reach the desk most often. The intern's first prompt is "Write an answer about the scholarship," and the assistant returns a long, generic text with a wrong date. Elena hands the text back: "This will not go to a student, so rebuild the prompt from scratch."
In the previous unit you saw how the assistant works: it writes a likely continuation of the text you give it, it does not look at the university's records on its own, and it can make things up where it does not know. In this unit we turn the question around: if the assistant writes by looking at the text you give it, what should you give it to get a better draft?
By the end of this lesson you will have a table like the one below: two prompts for the same job, two outputs, and each prompt's score on a checklist. For now the second prompt and the scores are empty; we will fill them in as we go.
| First prompt | New prompt | |
|---|---|---|
| Prompt | "Write an answer about the scholarship." | ? |
| Output | A 74-word generic text, "Applications usually close in November." | ? |
| Checklist score | ? | ? |
Below are the Student Handbook lines you will use in this lesson. The Handbook and all of the assistant's answers were written for this lesson and are fictional sample data; the method works the same way in real life.
| Topic | Student Handbook |
|---|---|
| Scholarship | $150 a month, paid for 9 months a year; applications close on October 3; payments are made on the 15th of each month |
| Dorm | Applications close on September 12; Block A (double room) $210 a month, Block B (four-person room) $145 a month |
| Course add/drop | Happens in the first two weeks of the semester, with advisor approval |
| Enrollment renewal | Happens in the two weeks before the semester starts |
| Enrollment freeze | At most two semesters; the freeze petition goes to Student Services |
| Password reset | With your student number, on the IT services page |
In this lesson you will:
Let's start with the intern's first attempt.
Example 1 (case): "Write an answer about the scholarship."
Fictional assistant output (prompt: "Write an answer about the scholarship."):
OutputA scholarship is financial support that helps students cover their education
costs. At many institutions, scholarships are given based on merit or need.
Applications usually close in November. Documents such as proof of income and a
transcript may be requested during the application. The scholarship amount varies
from institution to institution. To keep your scholarship, it is important to do
well in your courses. For more information, you can contact your institution's
scholarship office.The text is polished and polite, but it does not help the desk. It has three problems. First, it is generic: it says "the scholarship amount varies from institution to institution," while the Handbook gives the amount (the scholarship is $150 a month). Second, it contains a made-up date: "Applications usually close in November." According to the Handbook, scholarship applications close on October 3. Third, it is not in the desk's format: the student expects a short answer and gets a seven-sentence brochure. By the end of the lesson you will be able to explain why this output came out this way, and how the same job becomes a short, correct draft that fits the desk.
Everything you write to the assistant is called a prompt: the instruction you give, the information you paste in, the example you add, all together. In lesson 17 you saw that the model writes a likely continuation of the prompt. In lesson 18 you saw that private information such as the school's Handbook is not in the model, but if you put it inside the prompt, the model can write by looking at it. Put the two together and the importance of the prompt becomes clear. Whatever is not in the prompt, the model has to guess. Who is asking? Which school? How many sentences? Formal or friendly? If the prompt does not say, the model writes the answer it has seen most often in the millions of texts it read. The most common answer is a generic one: "varies from one institution to another," "usually in November."
Why did the assistant write a generic text for the prompt "Write an answer about the scholarship."?
A very common misconception comes in here: "A good prompt needs the right magic words." Online you will find advice like "start with this sentence and the assistant will write like an expert." But a prompt is a job description. There is no magic phrase; most poor outputs come from missing information. A role sentence ("you are an expert") does no harm, but it does not tell the model the date in the Handbook.
The intern wants to improve the prompt "Write an answer about the scholarship." Which change helps the most?
We will think of a good prompt in four parts: context, task, format, example. First the first two.
Context is the setting of the job: who it is written for, in what situation, and based on what information. "I work at the campus help desk" answers who and where. Pasting the Handbook lines into the prompt is also part of the context; this is the document-giving you saw in lesson 18. The model cannot know the school's dates, but if it sees them inside the prompt, it writes by looking at them. Some sources count the "role" as a separate part ("you are a help desk agent"); we count the role inside the context, because both answer the same question: whose job is this, and in what situation?
Task is exactly what is to be done, with a single verb: "write an answer," "summarize in three bullets," "list the mistakes." "About scholarships" is not a task but a topic: the assistant cannot tell whether to give information, write a brochure, or answer a question. The clearer the task, the closer the output gets to the target: "Write an answer to a student's question 'When is the scholarship paid?'"
There is one more valuable sentence you can add to the task: "If the information is not in the text provided, say 'Not in the Student Handbook.'" You saw in lesson 19 that a model does not leave a question blank; where it does not know, it makes things up. This sentence tells the model what to do when it does not know, and it lowers the risk of made-up answers. It lowers it; it does not remove it: you will still compare the output with the Handbook.
Example 2 (case): A prompt with context.
OutputI work at the campus help desk. Based on the Student Handbook lines below, write
an answer to a student's question "When is the scholarship paid?" If the
information is not in the lines, say "Not in the Student Handbook."
Lines: The scholarship is $150 a month and is paid for 9 months a year.
Scholarship applications close on October 3. Scholarship payments are made on
the 15th of each month.This prompt has context (the desk, the Handbook lines) and a task (answer this question; say so if the information is missing). It has no format yet. Try the block below to see how context and format change the output. The program picks one of four ready-made assistant answers: context says whether the Handbook lines are in the prompt, and output_format says whether the prompt includes "At most 3 sentences, friendly but professional." You do not need to read the code line by line; change the two values and look at the answer and the word count.
First change context, then output_format. Which combination gives an answer that is both correct and short?
Pick a value; predict the output first, then look.
1context = "no"2output_format = "no"34answers = {5 ("no", "no"): "A scholarship is financial support that helps students cover their education costs. At many institutions, scholarships are given based on merit or need. Applications usually close in November. Documents such as proof of income and a transcript may be requested during the application. The scholarship amount varies from institution to institution. To keep your scholarship, it is important to do well in your courses. For more information, you can contact your institution's scholarship office.",6 ("no", "yes"): "Hi, the scholarship is paid on the 1st of every month. The amount depends on the type of scholarship. You can write again if you have other questions.",7 ("yes", "no"): "Dear Student, your question about scholarship payments has reached us, and the information in the Student Handbook is provided below for your attention. According to the Student Handbook, the scholarship is $150 a month and is paid for a total of 9 months within one academic year. Scholarship payments are made on the 15th of each month. The Student Handbook does not contain any information on how payments are handled when the payment day falls on a weekend or an official holiday; we recommend that you contact the relevant office on this matter. We would also like to remind students who wish to receive the scholarship in the new semester that their applications must be completed no later than October 3. You are welcome to contact our help desk at any time with any further questions, and we wish you success in your studies. Kind regards, Campus Help Desk",8 ("yes", "yes"): "Hi, the scholarship is paid on the 15th of each month and is $150 a month. It is paid for 9 months a year. You can write again if you have other questions.",9}10answer = answers[(context, output_format)]11print(answer)12print("Word count:", len(answer.split()))
A scholarship is financial support that helps students cover their education costs. At many institutions, scholarships are given based on merit or need. Applications usually close in November. Documents such as proof of income and a transcript may be requested during the application. The scholarship amount varies from institution to institution. To keep your scholarship, it is important to do well in your courses. For more information, you can contact your institution's scholarship office. Word count: 74
Faded lines didn't run with this value. Without context, both outputs have a wrong date: with a format added the text got shorter, but "the 1st of every month" is still made up, because a model that cannot see the Handbook writes a common date. With context the information is correct ($150, 9 months, the 15th), but without a format the result is a 149-word formal letter. With both, the result is a 33-word answer that is correct and in the desk's format: context changes correctness, format changes usability.
Look at all four combinations. Without context, the assistant wrote a wrong date both times: with a format added the text got shorter, but "the 1st of every month" is still made up. With context, the information became correct ($150, 9 months, the 15th), but without a format the result is a 149-word formal letter; the student has to read it and hunt for the answer. With both, the result is a 33-word answer that is correct and in the desk's format. In short: context changes correctness, format changes usability. One does not replace the other.
This block also corrects a second misconception: "The model understands what I want anyway." It does not; it writes according to what is in the prompt. If your wish "keep it short and use our school's dates" is not written in the prompt, it is not in the model either.
Format is the shape of the output: length (number of sentences or words), structure (plain text, bullets, a table), tone (friendly, formal), and language. If the format is not written, the model picks the format it has seen most often; for a scholarship question that is sometimes a brochure and sometimes a formal letter.
Example is one or two sample answers that look like the output you want. The model imitates the example's format, length, and tone. Some things are hard to describe ("friendly but professional" is not the same for everyone); a sample answer explains them better than words.
Example 3 (case): A prompt with an example. The intern first writes a short prompt for dorm questions.
Fictional assistant output (prompt: "Write answers to dorm questions."):
OutputDorms offer students safe and affordable housing. Dorm applications usually close
one month before the semester starts. Rooms can be single, double, or four-person.
Application results are announced by email.Again a generic text, and again two mistakes: according to the Handbook, applications close on September 12, and there are no single rooms. The intern rebuilds the prompt with four parts:
OutputI work at the campus help desk. Based on the Student Handbook lines below, answer
dorm questions; if the information is not in the lines, say 'Not in the Student
Handbook'. At most 3 sentences, friendly but professional. Example answer: 'Hi,
dorm applications close on September 12. You can write again if you have other
questions.' Lines: Dorm applications close on September 12. Block A (double room)
costs $210 a month; Block B (four-person room) costs $145 a month. Question: How
much does a four-person room cost per month?Fictional assistant output:
OutputHi, four-person rooms are in Block B and cost $145 a month. Do not forget that dorm
applications close on September 12. You can write again if you have other
questions.The output followed the example's pattern: it opened with "Hi," stayed short, and closed with "You can write again if you have other questions." It took the information from the lines.
The example has a cost: examples get copied too. If the sample answer contains a wrong date, the model may treat it as correct and carry it into similar answers. A single example can also be too narrow: if it always starts with "Hi," all answers will come out in the same pattern. So check the example against the Handbook, and if you do not like the pattern, change the example.
How do we arrange four parts in one prompt? The sentences below are scattered; put them in a readable order.
Put the sentences of a prompt about freezing enrollment in order of its parts: context, information, task, format, example.
Click the lines in order; to undo one you placed wrong, click it in the list below.
Shuffled lines
Your order
Now the other direction: which part does a sentence from a finished prompt belong to?
Match each prompt sentence with the part it belongs to.
For each row, pick its match from the list, then check.
It is easy to think "the more I write, the better." But a prompt's value is not in its length; it is in having the four parts in place. First an example from outside school.
Example 4 (outside the case): Dinner. A student living in a dorm asks the assistant for a dinner idea.
Fictional assistant output (prompt: "Suggest a dinner."):
OutputBaked chicken with vegetables is a great option for dinner. You can marinate the
chicken with spices and bake it with potatoes and carrots for 45 minutes. Bulgur
pilaf and a seasonal salad go very well with it.The student has no oven, so the suggestion is useless. The assistant did not know who it was writing for, so it suggested the most common recipe. The student rewrites the prompt:
OutputI live in a dorm, have no stove, and have a budget of $15 a week. Suggest 3
dinners I can make with a kettle and a microwave. For each, give an ingredient
list and an estimated cost, at most 4 lines.Fictional assistant output:
Output1. Couscous salad: couscous, tomato, cucumber, lemon; steeped for 5 minutes in hot
water from the kettle, about $3.00.
2. Microwave eggs and potato: 2 potatoes, 2 eggs, cheese; about $2.50.
3. Instant lentil soup: soup packet, bread, yogurt; made with the kettle,
about $2.25.
The three together come to about $7.75, which stays within your $15 weekly budget.The new prompt is only three sentences. It has context (dorm, no stove, $15), a task (suggest 3 dinners), and a format (ingredients, cost, 4 lines). You can check the total yourself: 3.00 + 2.50 + 2.25 = 7.75. A short prompt is enough when its parts are complete.
Now the opposite: a long but incomplete prompt.
Example 5 (case): The 84-word prompt.
OutputThe campus help desk has served students for ten years. Hundreds of questions
arrive every day, mostly about scholarships, dorms, and enrollment. Our supervisor
Elena likes short, friendly but professional answers. Last semester, students found the
answers long and confusing. New interns joined this year and are learning to use
the assistant. The Student Handbook says: The scholarship is $150 a month and is
paid for 9 months a year. Applications close on October 3. Payments are made on
the 15th of each month.What is the main thing missing from the 84-word prompt in Example 5?
Put Example 4 and Example 5 side by side: the three-sentence prompt got a good output, and the 84-word prompt cannot. Length is not the measure; the measure is whether the four parts are in place.
The way to turn the four parts into a habit is to check your prompt against a short list before you send it. Our prompt checklist has five questions:
1. Context: Is it clear who the answer is for and what it will be based on?
2. Task: Is the job single and clear?
3. Format: Is the length, structure, or tone written down?
4. Example: Is a sample answer given?
5. If no information: Does the prompt say what to do if the model cannot find the information?
When scoring, answer each question yes (1) or no (0) based on what is written in the prompt; there are no half points. If an item is not fully met, it counts as 0. Let's score Example 1: "Write an answer about the scholarship." Who for, based on what? Not written: 0. The task looks present ("write an answer"), but to which question? It is not single and clear: 0. No format, no example, no "if no information" sentence: 0, 0, 0. Total 0/5.
The score counts what the prompt says; you decide whether an item is needed for the job. The dinner prompt in Example 4 scores 3/5 (context, task, and format are there; example and "if no information" are not) and still brought a useful output: a dinner idea does not rest on a document, and there is no fixed format for it. For the help desk's answers, all five are needed: the answer must rest on the Handbook and always go out in the same format.
Example 6 (case): A 5/5 prompt. The intern builds the prompt for an enrollment renewal question with the checklist.
OutputI work at the campus help desk. Based on the Student Handbook line below, write an
answer to a student's question 'When should I renew my enrollment?'. If the
information is not in the line, say 'Not in the Student Handbook'. At most 2
sentences, friendly but professional. Example answer: 'Hi, scholarship
applications close on October 3. You can write again if you have other
questions.' Line: Enrollment renewal happens in the two weeks before the semester
starts.Fictional assistant output:
OutputHi, you should renew your enrollment in the two weeks before the semester starts.
You can write again if you have other questions.All five items are in place: the desk and the Handbook line (context), an answer to one question (task), at most 2 sentences and a tone (format), a sample answer (example), and the "Not in the Student Handbook" sentence (if no information). The score is 5/5 and the output matches the Handbook.
Now the most important point of the lesson: a 5/5 prompt does not guarantee a correct output. You saw in lesson 17 that the same prompt can give different answers on different tries. The checklist checks the prompt; checking the output is a separate job, and we will look at it separately two lessons from now.
The intern sent the 5/5 prompt from Example 6 once more. This time the output is: "Hi, you should renew your enrollment in the two weeks after the semester starts. You can write again if you have other questions." The Handbook says: "Enrollment renewal happens in the two weeks before the semester starts." What do you do?
Pick an option and see what happens. There are no points; you can try the other options too.
Giving context does not mean putting personal information into the prompt. Do not write the student's name, student number, phone number, or details about their situation; the answer draft does not need them. Instead of "Aisha Rahman, student number 20231234, asked about her scholarship," write "A student asked about their scholarship." You often cannot know where the text you give an assistant goes or where it is stored; you will see the details and the rule in lesson 26. For now the rule is simple: describe the job in the prompt, not the person.
The most common mistake is this: starting the prompt with one word and then spending time fixing the output. Writing "Write an answer about the scholarship" takes five seconds, but turning the generic text into the desk's format and removing the wrong date takes ten minutes. Writing the four-part prompt takes one minute and often saves those ten.
The table from the start of the lesson is now filled in:
| First prompt | New prompt | |
|---|---|---|
| Prompt | "Write an answer about the scholarship." | "I work at the campus help desk. Based on the Student Handbook lines below, write an answer to a student's question 'When is the scholarship paid?' If the information is not in the lines, say 'Not in the Student Handbook'. At most 3 sentences, friendly but professional. Example answer: 'Hi, dorm applications close on September 12. You can write again if you have other questions.' Lines: (scholarship lines)" |
| Output | A 74-word generic text, "Applications usually close in November." (made up) | "Hi, the scholarship is paid on the 15th of each month and is $150 a month. It is paid for 9 months a year. You can write again if you have other questions." (33 words, matches the Handbook) |
| Checklist score | 0/5 | 5/5 |
You can now explain the difference between the two outputs: the first prompt forced the assistant to guess everything, and the new prompt left nothing to guess.
Elena turns the prompt into a template for interns to use on every question. What is inside the square brackets changes with each question; the rest stays the same.
OutputI work at the campus help desk. Based on the Student Handbook lines below, write
an answer to a student's question "[the student's question]". If the information
is not in the lines, say "Not in the Student Handbook." At most 3 sentences,
friendly but professional; do not use the student's name. Example answer: "Hi, dorm
applications close on September 12. You can write again if you have other questions."
Lines: [the relevant Student Handbook lines]The template carries all five checklist items. You can build a template like this for your own jobs: write the fixed parts (context, format, example) once, and change only the task and the information each time.
A student wants an announcement draft from the assistant for the chess club's tournament. The first prompt is "Write a tournament announcement." The assistant makes up a date and a place and writes a flashy poster text. The four-part version:
OutputI volunteer at our university's chess club; the announcement will be shared in the
club's student group. Based on the information below, write a tournament
announcement; if you need a detail that is not in the information, do not make it
up, write "[information needed]". At most 4 sentences, friendly, no emoji.
Example: "Our club's book swap is this Friday at 15:00 in the cafeteria. Everyone
can bring at most two books."
Information: the tournament is on Saturday, March 14 at 10:00 in the library
meeting room; registration is free; participation is limited to 32 people.It has context (club, student group), a task (write an announcement), what to do without information (write "[information needed]"), a format (4 sentences, friendly), and an example: 5/5. The tournament information is fictional sample data.
The intern is about to paste a student's question into the prompt as it is. The two versions side by side:
Before: Aisha Rahman (student number 20231234, email aisha@example.com) is asking
when her scholarship will be paid. Write an answer.
After: I work at the campus help desk. Based on the Student Handbook line below,
write an answer to a student's question "When is the scholarship paid?"
If the information is not in the line, say "Not in the Student Handbook."
At most 2 sentences, friendly but professional.
Line: Scholarship payments are made on the 15th of each month.Blaming the assistant for a poor output and never changing the prompt. It is very common to say "this assistant does not understand," send the same one-sentence prompt again and again, or spend ten minutes fixing the output by hand. Most of the time the problem is not the assistant but a missing part of the prompt: without context the output is generic, without a task it has no target, without a format it is hard to use, without an example it does not hold the tone. The fix: run the prompt through the checklist, add the missing part, and then compare the output with the Handbook again.
Next lesson: The first prompt is rarely the final one. In the next lesson you will test a prompt, compare the outputs, and improve it by changing one part at a time.
Exercises and quiz are for members
This lesson has 6 coding exercises and a 10-question quiz. Sign up free to solve them, save your progress and move on to the next lesson.
The "before" version has a name, a student number, and an email address; none of them is needed for an answer draft. The "after" version describes the same job without personal information and scores 4/5 on the checklist (the example is missing). If the name and situation are needed, you add them yourself when you send the answer to the student. The name, number, and address in the example are fictional.