Skip to content
The AI Agent Factory

25.3 Clear instructions and output constraints

Approved by
Panaversity ·
12 min read

In everyday life. You order a shirt from a tailor. "Make me a nice shirt" gets you a shirt, in the tailor's idea of nice. A careful order has the sleeve length in centimeters and the collar as one of the three styles on the tailor's card. It also says what to do when something is missing: "If this cloth is finished, phone me. Do not choose another." The second order is longer by three lines. They are the lines you would have said in the shop, standing there, if the tailor had asked.

What you will learn. You practice this in Lab 25. In Task 1, one instruction is made clear. In Task 3, the prompt says what to write for a missing value.

  • What does a clear instruction say?
  • What is an output constraint?
  • When should the model report, and when should it skip?
  • What do I keep, and what do I remove?

Why it matters. A person who reads an answer knows the form they wanted. The code knows only what the prompt said.

At work. Friday's extraction prompt named the field terms and never said which values it may hold. So the model wrote what the invoice said, "Net 30 days". On Monday at 7:10 the check from 14.5 knew the five terms and nothing else, and refused it. After Ana reads the report at 8:40 the builder finds the cause. It is a missing output constraint: the prompt never listed the five terms.

What does a clear instruction say?

Everything you would tell a capable new colleague who has never seen your work. Anthropic's test is to show the prompt to a colleague with little context: "If they'd be confused, Claude will be too".1 Four habits from the same page do most of the work:

  • Say what to do, not only what to avoid. Write "write the term from this list", not "do not invent terms".1
  • Give the reason. A rule with its reason lets the model handle a case you did not list, because it "can generalize from the explanation".1
  • Number the steps when their order matters.
  • Separate the parts. Put each kind of content in its own XML tag, such as <instructions> and <example>. An XML tag is a label in angle brackets. Use the same names every time.1

What is an output constraint?

An output constraint is a line that fixes the form of the answer. It gives the field names, the type of each and the allowed values. It says whether any text may come before or after, and what to write when the data is absent.2 It is the person's first job, knowing the form, written down. Friday's prompt had the field names and their types, and nothing else. This is what the missing lines look like:

Return one JSON object and nothing else, with exactly these fields:
number, vendorId, invoiceDate, terms, subtotalCents, taxCents,
amountCents, poNumber.

terms is one of: Due on receipt, Net 15, Net 30, Net 45, Net 60.
Write the term from this list that the invoice means.
Amounts are whole cents: $4,825.00 is 482500.
If the invoice shows no purchase order, write null for poNumber.
Never fill a field with a guess, because code will act on these values.

The line about a missing value matters as much as the list. Without it, a model asked for a purchase order writes one. A person would have left the box empty and asked. What does the model write when the terms are none of the five? That is 25.7's subject, where the schema gives that answer a value of its own.

When should the model report, and when should it skip?

Report when a written criterion is met, and skip everything else. Some prompts ask the model to notice things, and "flag anything unusual" is the unclear version. Unusual to whom? The model must guess your threshold, and a line such as "be careful" gives it nothing to check. Write the criterion instead, for both sides:

Report an invoice when its amount is more than its purchase order's amount.
Skip a difference in layout, wording or the order of the lines.

The first line says what counts. The second says what does not, so the report is not filled with findings that Ana must read and reject. Each false finding teaches her to trust the report less.

What do I keep, and what do I remove?

Keep the lines that do work: controls, limits, tests and the output constraints. Remove the rest. A prompt grows by one line after every bad answer. Anthropic's prep course for this exam tells the story of a classifier whose prompt grew over five revisions. Its answers got longer and slower, and no more accurate.2 So read a prompt as you read code, and remove what does no work.

RemoveKeep
Generic lines: "think carefully", "double-check your work"Required controls: steps that policy or a system demands
Steps the model can work out by itselfAuthority limits: what the step may never decide
Words in capital letters, and "CRITICAL" in front of a ruleSpecific acceptance tests, success criteria and stop rules
Rules and notes that built up for an older modelThe output constraints above

Capitals: the documentation says Claude Opus 4.5 and 4.6 are "more responsive to the system prompt". So a rule no longer needs loud words to be followed. Its own example replaces "CRITICAL: You MUST use this tool when..." with "Use this tool when...".1 Old rules: Anthropic's guide to its newest model says that some instructions designed for earlier models "raised cost, caused side effects, or no longer had an effect".3 "Think carefully": how long the model thinks is a setting, called effort, and it is not a sentence in the prompt. Chapter 29 covers it.

One old technique is gone. A prefill is the first characters of the answer, written by you, such as {, so that the model continues from there. Starting with Claude 4.6 models, a request that ends this way returns a 400 error.1 Ask for the form in the system prompt instead. Then, as the documentation warns, "a system prompt instruction doesn't guarantee how the response starts, so check the response's text in your code".4

The price. That warning holds for the whole prompt. A constraint in a prompt is a request, and the model can still miss it. It lowers how often the check in code refuses an answer. It never replaces the check. A prompt alone is fine where a person still reads each answer. Where code reads it, 25.7 moves the form into a schema that the API holds.

The operating rule: write down the form, the allowed values and what to do when a value is missing. Remove every line that does no work.

Do this now. Ask your coding agent to review one prompt against this section. Copy this line:

Read the prompt in this file. List every field of the answer for which it does not state the type, the allowed values, or what to write when the value is missing. Then list every line that is generic advice and not a rule, a limit or a test. Change nothing.

Check yourself

Question 1 / 7

0 answered

On Monday at 7:10, what refused the answer that held "Net 30 days"?

  1. Prompting best practices, Anthropic.↑↑2↑3↑4↑5↑6
  2. Claude Certified Developer, Foundations prep path, Module 2, Prompting Craft, Anthropic Partner Academy.↑↑2
  3. Prompting Claude Fable 5.2, Anthropic.↑
  4. Using the Messages API, Anthropic.↑
Owner
Panaversity