…
…
AI Fundamentals · Lesson 22 / 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.
The prompt the desk uses for enrollment freeze questions is long and gives formal answers, and sometimes it adds "at most three semesters", which is not in the Student Handbook. Elena asks you for one thing: "Find the version the desk will use within a week." You will test three versions in order, change only one thing each time, and write the results in a table.
In Lesson 21 you saw the four parts of a good prompt: context, task, format, example. You also saw the five-item checklist you run before sending a prompt. A well-built first prompt is a solid start, but you only learn whether it fits the desk's work by testing it. In this lesson you will learn how to improve a prompt by testing: what to change and when, and how to tell whether a change worked.
By the end of the lesson you will have a prompt log: one row per prompt version, with the part that changed, the score of the output, a short observation, and a "keep" or "revert" decision. For now it is empty; we will fill it in as we go.
| Version | Changed part | Score (out of 4) | Observation | Decision |
|---|---|---|---|---|
| 1 | ? | ? | ? | ? |
| 2 | ? | ? | ? | ? |
| 3 | ? | ? | ? | ? |
The only information you will rely on is the enrollment freeze item of the Student Handbook (g-11): "Enrollment can be frozen for at most two semesters; the freeze petition goes to Student Services." The Handbook, all the prompts in this lesson, and the assistant outputs are fictional example data made for this lesson; the method works the same way in a real tool.
In this lesson you will:
We have the first two versions of the desk's prompt and their outputs. Which one is better? Before answering, you need to step back, because "better" does not say anything on its own. One person finds a long text "detailed", another says "it is unreadable". Both are tastes.
The way out of taste is to write output criteria: three to five items, written before you look at the output, each answered with yes or no. Is it correct? Is the length right? Is the tone right? Is the requested information complete? The reason to write them in advance is simple: if you write criteria after seeing the output, they bend toward the output without you noticing, and you end up writing items that justify the text you already like.
One more distinction. The checklist in Lesson 21 evaluates the prompt: before sending, are context, task, and format in place? Output criteria evaluate the output: does the answer that came back do the job? Neither replaces the other; a prompt that passes all five checklist items can still produce an output that misses a criterion.
| Prompt checklist (Lesson 21) | Output criteria (this lesson) |
|---|---|
| Checked before sending the prompt | Checked when the output arrives, but written before you see it |
| Are the parts in place? | Does the answer do the job? |
| The same five items for every job | Written separately for each job |
Here are four criteria for the enrollment freeze answer:
| # | Criterion (yes/no) |
|---|---|
| 1 | Does it give only information from the Student Handbook? (at most two semesters) |
| 2 | Is it at most 3 sentences? |
| 3 | Is the tone polite and respectful? |
| 4 | Does it state the next step? (the petition goes to Student Services) |
Each "yes" is one point; the highest score is 4. No half points: a criterion is either met or not.
Example 1 (case): Two versions, two outputs. Version 1 is the one-sentence prompt used at the desk. In version 2 the intern added the Handbook item and a format, as learned in Lesson 21.
Version 1 prompt: "Write a reply to a student who wants to freeze their enrollment."
Fictional assistant output (version 1):
OutputDear Student, we would like to inform you about your enrollment freeze request. At our institution, students can freeze their enrollment if they have a justified and valid excuse. The enrollment freeze period is at most three semesters over the course of study. For your request to be evaluated, you are required to prepare the documents showing your excuse in full. When the evaluation process is complete, you will be informed separately. We thank you for your understanding and wish you success in your studies.Version 2 prompt: "Write a reply to a student who wants to freeze their enrollment. Rely only on the Student Handbook item below; if the information is not in the item, say 'Not in the Student Handbook'. At most 3 sentences, friendly but professional. Item: Enrollment can be frozen for at most two semesters; the freeze petition goes to Student Services."
Fictional assistant output (version 2):
OutputHi, you can freeze your enrollment for at most two semesters. The freeze period cannot exceed this limit. You can write again if you have other questions.The output of version 1 is 85 words and six sentences; it reads like a formal letter. Its third sentence says "at most three semesters", while the Handbook says two: this is a made-up fact, like the ones you met in Lesson 19. The output of version 2 is three sentences and correct, but something is missing. Before looking at the criteria, make a prediction.
We have not written any criteria yet. Looking at the outputs of version 1 and version 2, which one looks better?
Now compare the same two outputs against the four criteria, one by one.
Match each criterion to the result of version 1 and version 2 on it.
For each row, pick its match from the list, then check.
The criteria showed two things at once. Version 1 looks like "effort went into it" because it is long and formal, but it loses on the most important criterion: accuracy. Version 2 is better (3/4), but it does not tell the student where to submit the petition. The first two rows of the prompt log are filled.
Improving a prompt does not happen in one move; it is a loop. We will call it the iteration loop: write the prompt, get the output, evaluate it against the criteria, change one part, test again, and record every round. Each round teaches something the one before did not.
What changed between version 1 and version 2? Two things: context (the Handbook item and "rely only on this item") and format ("at most 3 sentences, friendly but professional"). Which one fixed the accuracy? Probably the context, but we cannot be sure, because both changed at the same time. Maybe the format limit also kept the model away from made-up details. This may look like a small problem, but when something breaks tomorrow you will not know which part to take back. So our rule is: one part per round.
The same thing happens outside prompts.
Example 2 (outside the case): Editing a photo. On your phone you brighten a photo, warm up its color, and crop its edges. The result is nicer. Your friend says "How did you do that? I want mine to look like this." You cannot say which setting did the work; maybe the crop made the photo nicer, and the brightness blew out one corner. If you had tried the three settings one by one, you would see which one helped and which one hurt.
Now it is your turn to close the gap in version 2.
Version 2 is correct, short, and polite, but it does not tell the student where to submit the petition (3/4). Elena says "fix this." What do you do?
Pick an option and see what happens. There are no points; you can try the other options too.
The good path in the scenario had two rounds, and one part changed in each: first the task ("also state the next step"), then the format ("at most 3 sentences in total"). You could have written both at once; but if you had not seen the output grow to four sentences in the first round, you would not know why you tightened the format. The thought "if the output is bad I rewrite the prompt" looks fast, but every rewrite puts you back at zero: you are left with no knowledge of what worked.
Improving a prompt often means adding something, but not every addition improves it. There are two traps.
The first is the conflicting instruction. If "write short" and "give every detail" sit in the same prompt, the model cannot satisfy both. You also cannot predict which one it will follow; often it lands somewhere in between and misses one of the two criteria. The second is the forgotten instruction. You saw in Lesson 18 that in a long conversation the instruction at the start can fall behind. The longer the prompt, the less weight each instruction carries.
That is why even two strong changes, adding a sample answer or saying "write step by step", are tested separately. Each is a single change and goes into the log as its own row.
Example 3 (case): Version 3 and a counterexample. The intern combines the two rounds of the scenario in one row: adds the next step to the task part of version 2 and rewrites the total length. The changed part is the task.
Version 3 prompt: "Write a reply to a student who wants to freeze their enrollment. Rely only on the Student Handbook item below; if the information is not in the item, say 'Not in the Student Handbook'. At most 3 sentences, friendly but professional. Item: Enrollment can be frozen for at most two semesters; the freeze petition goes to Student Services. Also state the next step (the petition goes to Student Services); at most 3 sentences in total."
Fictional assistant output (version 3):
OutputHi, you can freeze your enrollment for at most two semesters. You only need to submit your freeze petition to Student Services. You can write again if you have other questions.All four criteria hold: the information is correct, three sentences, polite, the next step is there. 4/4.
For comparison, let's look at another intern's attempt. This intern also started from version 2, but thought "more instructions is better" and added "Keep it short. Give every detail." at the end of the prompt.
Fictional assistant output (version 2 + "Keep it short. Give every detail."):
OutputHi, you can freeze your enrollment for at most two semesters. You must submit your freeze petition to Student Services. You must also attach the documents that show the reason for your freeze. You cannot take courses or pay tuition during the semesters you freeze. You can write again if you have other questions.To follow "give every detail", the model added two pieces of information that are not in the Handbook (a document requirement, tuition) and went to five sentences. Score: accuracy 0, length 0, tone 1, next step 1, so 2/4. More instructions, lower score.
But is the 4/4 of version 3 permanent? To see, you need to run the same prompt once more. The program below holds six ready outputs: two attempts for each version. The criteria dictionary keeps, for each output, which of the four criteria it meets as 1 and 0; the score is their sum. You do not need to read the code line by line: change the two values and look at the last two lines.
First change version, then attempt. Which version gets the same score on both attempts, and which does not?
Pick a value; predict the output first, then look.
1version = 12attempt = 134outputs = {5 (1, 1): "Dear Student, we would like to inform you about your enrollment freeze request. At our institution, students can freeze their enrollment if they have a justified and valid excuse. The enrollment freeze period is at most three semesters over the course of study. For your request to be evaluated, you are required to prepare the documents showing your excuse in full. When the evaluation process is complete, you will be informed separately. We thank you for your understanding and wish you success in your studies.",6 (1, 2): "Dear Student, your enrollment freeze request has reached us. According to our regulations, enrollment can be frozen for at most three semesters over the course of study. We kindly ask you to prepare the documents that support your request. You will be informed after your application is evaluated. We wish you success.",7 (2, 1): "Hi, you can freeze your enrollment for at most two semesters. The freeze period cannot exceed this limit. You can write again if you have other questions.",8 (2, 2): "Hi, you can freeze your enrollment for at most two semesters. Freezing for longer than two semesters is not possible. You can write again if you have other questions.",9 (3, 1): "Hi, you can freeze your enrollment for at most two semesters. You only need to submit your freeze petition to Student Services. You can write again if you have other questions.",10 (3, 2): "Hi, you can freeze your enrollment for at most two semesters. To do this, you need to write a freeze petition. You must submit your petition to Student Services. You can write again if you have other questions.",11}12# Criteria order: accuracy, at most 3 sentences, polite tone, next step (1 = met)13criteria = {14 (1, 1): [0, 0, 1, 0], (1, 2): [0, 0, 1, 0],15 (2, 1): [1, 1, 1, 0], (2, 2): [1, 1, 1, 0],16 (3, 1): [1, 1, 1, 1], (3, 2): [1, 0, 1, 1],17}18key = (version, attempt)19print(outputs[key])20print("Score:", sum(criteria[key]), "/ 4")
Dear Student, we would like to inform you about your enrollment freeze request. At our institution, students can freeze their enrollment if they have a justified and valid excuse. The enrollment freeze period is at most three semesters over the course of study. For your request to be evaluated, you are required to prepare the documents showing your excuse in full. When the evaluation process is complete, you will be informed separately. We thank you for your understanding and wish you success in your studies. Score: 1 / 4
Faded lines didn't run with this value. Version 1 gets 1/4 on both attempts, version 2 gets 3/4 on both. Version 3 gets 4/4 on the first attempt and 3/4 on the second: the second output grew to four sentences, so it misses the length criterion. Same prompt, different attempt, different score; if you had looked only at the first attempt, you would have thought version 3 was perfect.
What you saw in the block is perhaps the most important idea of this lesson. Version 3 got 4/4 on the first attempt; on the second attempt the same prompt gave a four-sentence answer and missed the length criterion.
Fictional assistant output (version 3, second attempt):
OutputHi, you can freeze your enrollment for at most two semesters. To do this, you need to write a freeze petition. You must submit your petition to Student Services. You can write again if you have other questions.Why? You saw in Lesson 17 that the model picks the next word by probability; the same prompt gives different answers with different dice. So one good output does not prove the prompt is good; it can be a lucky roll. The rule of one change and repeat attempts has two parts: change only one part per round (to know what worked), and run every version at least twice (to see whether a single output was luck). Three times if you can.
Version 3 scored 4/4 on the first attempt. What do you do before you save it as the prompt the desk will use?
If a prompt misses a criterion in one of two attempts, there are two ways: tighten the prompt, or make checking that criterion mandatory. Often both are done together.
Example 4 (case): Version 3b. The intern looks at the missed criterion (length) and makes one change: adds a sample answer on a different topic, with the length wanted, to the end of the prompt. The example makes the model imitate the length and structure (you saw this in Lesson 21).
Added part: "Example answer: 'Hi, you can add or drop courses in the first two weeks of the semester. All you need is your advisor's approval. You can write again if you have other questions.'"
Fictional assistant output (version 3b, two attempts):
OutputAttempt 1: Hi, you can freeze your enrollment for at most two semesters. You only need to submit your freeze petition to Student Services. You can write again if you have other questions.
Attempt 2: Hi, you can freeze your enrollment for at most two semesters. Submitting your freeze petition to Student Services is enough. You can write again if you have other questions.Three sentences in both attempts, both 4/4. This is not a new version, it is a tightened form of version 3; it goes into the log as "3b". The information in the example comes from the add/drop item (g-05) and is consistent with the Handbook: if the example had an error, the model could have imitated that too.
The iteration loop does not work only at the help desk. Imagine you are preparing a news summary for a presentation.
Example 5 (outside the case): Summary for a presentation. The source text is a five-sentence news item about bike lanes in the city (fictional). You write the criteria beforehand: (1) exactly 5 bullet points, (2) each bullet at most 12 words, (3) numbers the same as in the source text, (4) no comments that are not in the source.
Version 1 prompt: "Summarize this text: Bike lanes opened in the city last year reached 18 km. According to the city's count, the share of people cycling to work or school rose from 7% to 12%. Traffic accidents on streets with bike lanes fell by 30%. Building the new lanes took 9 months. Another 10 km of lanes is planned for next year."
Fictional assistant output (version 1):
OutputBike lanes in the city have drawn great interest, and travel habits are starting to change. The lanes opened last year reached 18 km, and the share of people cycling to work or school rose from 7% to 12%. Accidents on streets with bike lanes fell by 30%. Another 10 km is planned for next year for the lanes, which took 9 months to build. These developments show that healthier and safer transport is possible in the city.No bullets, a plain paragraph; the first sentence ("have drawn great interest") and the last sentence are comments that are not in the source. The numbers are correct. Score 1/4. Most of the missed criteria are about format, so the change goes into the format: version 2 adds "for a presentation: 5 bullet points, each at most 12 words".
Fictional assistant output (version 2):
Output- Bike lanes opened last year reached 18 km.
- Cycling to work or school rose from 7% to 21%.
- Traffic accidents on streets with bike lanes fell by 30%.
- Building the new lanes took 9 months.
- Another 10 km of bike lanes is planned for next year.Five bullets, the longest has 11 words, no comments. But the second bullet says 21%; the source text says 12%. Score 3/4. The missed criterion is numbers; the change goes into the task: version 3 adds "Use the numbers exactly as in the text".
Fictional assistant output (version 3):
Output- Bike lanes opened last year reached 18 km.
- Cycling to work or school rose from 7% to 12%.
- Traffic accidents on streets with bike lanes fell by 30%.
- Building the new lanes took 9 months.
- Another 10 km of bike lanes is planned for next year.Score 4/4. Still, the job is not finished: the instruction "use the numbers exactly" lowers the risk, it does not remove it. Before putting it in the presentation, you compare every number with the source once more. Running version 3 a second time is needed for the same reason.
Put all the steps of the loop in order.
Put the steps of the prompt improvement loop in order.
Click the lines in order; to undo one you placed wrong, click it in the list below.
Shuffled lines
Your order
The step that does the most work in the loop is looking at the missed criterion and deciding which part to change. For this you use the four parts from Lesson 21.
Match each missed criterion to the prompt part to change.
For each row, pick its match from the list, then check.
The prompt log is now full:
| Version | Changed part | Score (out of 4) | Observation | Decision |
|---|---|---|---|---|
| 1 | (the desk's first prompt) | 1 and 1 | Long, formal; "three semesters" made up | Revert |
| 2 | Context and format (both at once) | 3 and 3 | Correct and short; no next step | Keep, improve |
| 3 | Task: state the next step | 4 and 3 | Four sentences on attempt 2 | Keep, tighten |
| 3b | Example: short sample answer | 4 and 4 | Three sentences in both attempts | Keep, propose to the desk |
The note "(both at once)" in the second row is there on purpose: in that round the rule was broken, and it was written in the log. A good log records not only successes but also what is not known.
The log has one more job. However good the prompt is, someone at the desk reads and sends every answer that goes to a student; the responsibility belongs to the sender. "The prompt scored 4/4" does not mean "this answer is correct". The log is also the record of the question "did we use AI in this answer, and how?"; you will see why this record matters in Lesson 27, on transparency.
In Lesson 21 you saw that a role sentence like "You are an expert" does not fill in missing information. The intern wants to test this: as a single change, they add "You are an experienced student services officer." to the start of version 2 and run it twice.
Fictional assistant output (version 2 + role sentence, two attempts):
OutputAttempt 1: Hi, you can freeze your enrollment for at most two semesters. This limit cannot be exceeded. You can write again if you have other questions.
Attempt 2: Hi, enrollment can be frozen for at most two semesters. You cannot go beyond this limit. You can write again if you have other questions.Both attempts score 3/4: there is still no next step. The role sentence did not change the score for this job. Log row: "Context: role sentence · 3 and 3 · no difference · revert". Because they made a single change, the intern now knows that adding a role does not help in this prompt; what was missing was the task.
A student asks the total fee for staying 9 months in Block B. With the first prompt the assistant writes only a result, and to check it you have to redo the calculation from the start. As a single change, "Write the calculation step by step: first the monthly fee, then the number of months, then the product" is added to the task.
Fictional assistant output (with the step-by-step request):
OutputThe monthly fee for Block B is $145. If you stay 9 months, you pay $145 × 9 = $1,305. You can write again if you have other questions.With the steps written out, the calculation is visible and easier to check: 145 × 9 = 1,305, correct. But do not forget Lesson 19: writing the steps does not guarantee the calculation is right, it only makes an error easier to catch. You still calculate the result yourself.
A student wants question-and-answer cards for an exam from their biology notes (cell organelles). They write the criteria first: (1) exactly 5 cards, (2) each card has one question and one answer, (3) answers are the same as in the notes. Version 1 ("Make study cards from these notes") gives 8 cards, and two of them have no answer: 1/3. The missed criteria are about format; in version 2 the single change goes into the format: "Exactly 5 cards; each card in the form 'Question: … / Answer: …'."
Testing a prompt once and saying "it works". One good output does not show that the prompt will give a good output every time: because the model picks words by probability, the same prompt can miss a criterion on the next attempt. In this lesson, version 3 scored 4/4 on the first attempt and 3/4 on the second. The right way: run every version at least twice, score every output against the criteria, record both in the log, and do not stop checking outputs after the prompt is adopted.
Next lesson: A prompt improves the output, but it does not guarantee that it is correct. In the next lesson you will test an output in three ways: against the source, by calculation, and with a counterexample.
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.
Fictional assistant output (version 2):
OutputQuestion: Where is the cell's genetic information (DNA) found? / Answer: In the nucleus.
Question: Which organelle produces energy in an animal cell? / Answer: The chloroplast.
Question: Where is protein synthesis done? / Answer: In the ribosome.
Question: What controls what enters and leaves the cell? / Answer: The cell membrane.
Question: Where does photosynthesis happen in a plant cell? / Answer: In the chloroplast.The format is now right: 5 cards, a question and an answer on each. But when you compare the answers with the notes, the second card is wrong: in the notes, the mitochondrion produces energy in an animal cell. Score 2/3. The missed criterion is accuracy; in version 3 the single change goes into the context: "Rely only on the notes below" and the notes themselves. The cards are still used only after being compared with the notes.