Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Objectives: LO-3.1, LO-3.2, LO-3.3
Prerequisites: Module 2
Time: about 6 hours: 2 for this reading, 2.5 for Lab 3, and 1.5 for the practice

Module 2 built a request as data. This module writes the text inside it. A model acts only on what the request says, so you will rewrite vague prompts until they state everything the task needs, and score them with the course’s prompt rubric. You will decide which text belongs in the system prompt and which in the user’s turn. Last, you will specify an output’s format precisely enough for code to check every response. Current Claude models don’t accept a temperature setting (Module 1), so the prompt is your main way to narrow the range of acceptable answers.

What the model can’t see

A request is everything the model gets (Module 2). The shop’s queue rules, the person who will read the answer, and what they will do with it live in your head and in the shop’s documents. None of them reach the model unless the prompt includes them.

Anthropic’s prompting best practices page puts it this way: think of Claude as “a brilliant but new employee who lacks context on your norms and workflows.” Its test is to show the prompt to a colleague who knows little about the task. If they would be confused, Claude will be too. The page also says to ask explicitly for anything beyond what the task strictly requires, rather than expect the model to infer it.

LO-3.1 names five things a clear prompt states:

The prompt rubric scores five matching criteria from 0 to 2, for a total out of 10, with a few quoted words as evidence for each score. A high score records a clear specification. Only an evaluation, which Module 7 builds, measures how often a model meets it.

Worked example: from “Write this up” to a work order

A clerk pastes ticket T05 under three words:

Write this up.

One spoke snapped on the rear wheel

It scores 2 out of 10. Task gets 1, because “Write this up” names an action but not what to write. Context gets 1: the ticket is there, but the shop’s policy isn’t. The other three criteria get 0. A reader could fairly write a reply to the customer, a summary for the owner, or a work order. This revision takes its policy from the handbook’s section H07, “Work orders”:

Draft a work order for the mechanic who will repair this bicycle. The mechanic reads it at the
bench before starting, so describe the work, not the customer's words.

Shop policy: a work order names the requested service and the parts it needs. A paid service
the customer didn't request needs their approval first, so list it as a suggestion, never as
part of the order.

Write exactly three lines:
Service: <the requested service, in at most eight words>
Parts: <the parts it needs, separated by commas, or "none known">
Suggestions: <paid services to offer the customer, or "none">

If the ticket doesn't say what is wrong, write "Service: inspection", and "none known" and
"none" on the other two lines.

Ticket: One spoke snapped on the rear wheel
CriterionScoreEvidence
Task2“Draft a work order for the mechanic who will repair this bicycle”
Audience and purpose2“reads it at the bench before starting”
Context2The ticket and the policy, each labeled
Constraints2The approval rule, and a fallback for an unclear ticket
Output and success2Three named lines with fixed values that code can check

Each addition rules out a reading. The audience rules out a reply to the customer. The policy keeps an unrequested paid service, such as truing (straightening) the wheel, out of the order. The fallback covers a ticket such as “My bike makes a noise.” In Lab 3, Exercise L3.1 has you rewrite three other vague prompts, and Exercise P3.1 in the practice rewrites a fourth.

Give the reason behind a rule

A rule with its reason is easier to apply than a bare rule. The best-practices page shows a prompt that, instead of only forbidding ellipses, explains that a text-to-speech engine will read the response and can’t pronounce them. The page says Claude can generalize from such an explanation. It also recommends saying what to do instead of what not to do.

Worked example: a rule about repair times

A prompt for replies to customers says “Never promise a repair time.” The handbook’s section H02 holds the reason: the shop books repairs in 30-minute slots, and a walk-in repair gets the next open slot. Here is the rule with its reason, and with something to do instead:

The shop books repairs in 30-minute slots, and only the clerk who books a slot knows when the
repair will start. So never promise a repair time. Say that a clerk will confirm it.

Now a customer asks “Will it be ready by Friday?” A reader could decide that the bare rule covers times, not days. The reason covers both, because no slot is booked yet, and the last sentence gives the reply something to say.

Settle the cases the instructions leave open

“Fix this ticket” leaves the task open: a reader could repair the bicycle, revise the customer’s text, or route the ticket. Before writing a prompt, name the decision and who will use it. A dispatcher needs one queue label; a customer needs a clear next step. Then look for inputs the instructions don’t decide, such as a ticket with two topics, and give each a rule or a fallback.

Worked example: a ticket with two topics

The shop has three queues: repair for mechanical service, billing for payments and receipts, and account for profile access. This ticket mentions a wheel and a receipt:

My wheel is fine now. Can you send my receipt?
RuleResult
Use the first topic mentionedLabel: repair
Use the customer’s current requestLabel: billing
Ask the customer which they meanA question, not a label

The queue must act on what the customer wants now, so the shop writes the second rule into the prompt: “When two topics appear, use the explicit current request.” The queue definitions matter too: without them, the word “repair” in ticket T14, “I need the brake repair receipt as a PDF,” could pull a receipt request into the repair queue.

The receipt determines the label. A format checker can test the line’s shape, but only a labeled test case or a person can say whether billing is right. Use the rubric to record each change and the problem it addresses. Exercise P3.4 asks for a rule of your own.

Give each instruction a home

A request has two places for text (Module 2): the top-level system field and the turns in messages. Decide where each piece goes by how often it changes. The system prompt holds what stays the same for every request: the role, the policy, the definitions, and the output format. The user’s turn holds what changes: the ticket, and any choice made for this request.

Anthropic’s documentation supports the split. The best-practices page says a role set in the system prompt focuses Claude’s behavior and tone, even in one sentence. The Messages API guide says to describe an output format in the system prompt, and to use the top-level system field for instructions that should apply from the first turn.

A role such as “You route repair shop tickets” sets scope and vocabulary but decides none of the hard cases, so add rules for the decisions it leaves open. When the user may choose something, list the allowed choices in the system prompt and put the current choice in the user’s turn. If customers may ask for a reply in English or Spanish, the system prompt lists both, and the user’s turn says which one this customer wants.

The split helps the program around the model too. The shop reviews one copy of its policy, not a copy in every ticket. A customer writes the ticket, and it can contain text that looks like a rule; Module 4 marks it as data, and Module 11 shows why marking alone isn’t a defense. An unchanging system prompt also gives every request the same opening text, and Anthropic’s prompt caching guide says a cache hit needs that opening to be identical (Module 10).

Worked example: splitting the work-order prompt

Everything in the revised work-order prompt except the ticket moves into system:

request = {
    "model": "claude-opus-5-5",
    "max_tokens": 2000,
    "system": work_order_instructions,  # the role, the policy, the format, and the fallback
    "messages": [{"role": "user", "content": "One spoke snapped on the rear wheel"}],
}
TextHow often it changesWhere it goes
The role: drafting work orders for mechanicsRarelysystem
The approval policyWhen the shop changes itsystem
The three-line format and its fallbackWhen the format changessystem
The ticketEvery requestThe user’s turn

max_tokens is far more than three lines need, because Claude Opus 5.5 thinks before it answers and its thinking tokens count toward max_tokens (Module 2). The Messages API guide says to set it high enough for the whole response. In Lab 3, Exercise L3.2 splits the routing prompt, and practice Exercise P3.2 asks where a policy change goes.

Specify the format so code can check it

A format specification gives the allowed values, spelled exactly with their capital letters; the number of lines, and whether other text may appear; what to write when the input doesn’t decide the answer; and the length, in a unit code can count. “Be concise” is subjective unless you give a criterion, but “at most two sentences” can be counted.

Writing the format into the prompt doesn’t guarantee it. The Messages API guide says that, unlike a prefill (which current models reject), a system prompt instruction doesn’t guarantee how a response starts, so check the text in code. Where a format must always hold, the best-practices page suggests structured outputs, or a tool whose input allows only the valid labels (Module 8). Ask for the length in the prompt, because max_tokens is only a ceiling. Check the stop reason before you score: an answer cut off at max_tokens can still start with a plausible line.

Decide how strict the checker is. Anthropic’s evaluation guide shows an exact-match grader that strips surrounding whitespace and ignores case. That suits a grader that measures meaning. A checker that protects the code reading the response can’t be lenient: if that code takes the queue from after Label: , then label: billing breaks it.

Worked example: a checker for the rack contract

The handbook’s section H05 sends completed repairs to the green rack, and bicycles awaiting inspection to the orange rack. A prompt that assigns a rack from a status note sets a contract: the whole response is exactly Rack: green or Rack: orange.

ResponseValid?Why
Rack: greenYesMatches exactly
rack: greenNoLowercase r
Rack: green.NoAn extra period
Rack: green, then a newlineNoAn extra character after the value

The last row catches a common bug. In Python’s re module, $ matches at the end of the string or just before a newline at its end, so re.match(r"Rack: (green|orange)$", text) accepts "Rack: green\n". re.fullmatch succeeds only when the whole string matches, so it rejects the newline; calling str.strip() first would forgive it. In Lab 3, Exercise L3.3 checks the routing contract, and Exercise L3.4 runs that check over 30 illustrative responses.

Check format and meaning separately

Format and meaning fail independently. Label: repair has the right shape for a receipt ticket and sends it to the wrong queue. Billing, because the customer wants a receipt. makes the right decision in the wrong shape. A test that counts only matching labels hides formatting problems, and a test that counts only formatting misses wrong decisions.

The two checks need different evidence. A format check needs only the response, so code does it; the evaluation guide calls code-based grading the fastest and most reliable method, though it lacks nuance for complex judgments. A meaning check compares the parsed value with a reference label that a person assigned, as the guide’s exact-match example compares the output with a golden_answer.

Worked example: eight responses, two tallies

A person wrote these eight responses to the rack prompt for this example; no model produced them. Each note’s reference rack comes from section H05. For an invalid response, “meaning” asks whether a person reading it would find the right rack.

#Status noteReferenceResponseFormatMeaning
1Brakes adjusted, test ride donegreenRack: greenvalidright
2Dropped off today, not inspectedorangeRack: orangevalidright
3New chain fitted and checkedgreenRack: orangevalidwrong
4Waiting for a mechanicorangerack: orangeinvalidright
5Repair finishedgreenRack: green.invalidright
6Arrived with a flatorangeRack: orangevalidright
7Wheel trued, ready for pickupgreenRack: green and a second lineinvalidright
8Inspection booked for tomorroworangeRack: greenvalidwrong
Meaning rightMeaning wrong
Format valid3 (1, 2, 6)2 (3, 8)
Format invalid3 (4, 5, 7)0

Five of the eight, 62.5%, pass the format check, and six, 75%, name the right rack. Only three, 37.5%, do both, and only those are safe for code that trusts the format. The rates describe these eight responses only; Module 7 reports a rate with its uncertainty. Practice Exercise P3.3 asks you to build one failure of each kind.

Common misconceptions

Summary

Self-check

Answer each question before you open its answer.

  1. (LO-3.1) Why include queue definitions when the labels look obvious?

    Answer

    They fix the boundaries between queues. Without them, a receipt for a repair, such as T14, could be routed by the word “repair.” The definitions send receipts to billing whatever else the ticket mentions.

  2. (LO-3.1) A prompt scores 2 on every rubric criterion. Does that show it works?

    Answer

    No. The rubric records how clearly the prompt specifies the task. Only an evaluation over test cases (Module 7) shows how often a model meets the specification.

  3. (LO-3.2) Where do you put an account-specific message?

    Answer

    In the per-request user content, because it applies to this request only. The system field holds the stable routing rules, which are the same for every request.

  4. (LO-3.3) Does matching the output format prove the routing was right?

    Answer

    No. Compare the parsed label with a reference label separately. The format check sees only the shape: Label: repair is valid for a receipt ticket and still wrong.

  5. (LO-3.3) A response reads Label: billing, and its stop_reason is "max_tokens". Should an audit count it as a valid answer?

    Answer

    No, report it as incomplete. The model was cut off, so the text isn’t the whole answer. Check the stop reason first, and parse only responses that ended normally (Module 2).

Further reading