Skip to content
mentoor

Topic 5 of 5 · 4 min read

Marking examples apart from the input

Goal: Format a few-shot prompt so the examples are clearly separated from the real input, in a chat app and as API message pairs.

Label your examples, keep their layout identical, and put the real input last, clearly marked as the one to answer. If the model cannot tell where the examples end and the task begins, it may answer an example, continue it, or mix the two.

Check yourself · 1 of 3

Why should the real input come last, after a marker such as "Now do this one:"?

Choose one answer

Why it matters

To you the structure is obvious. To a model the whole prompt is one stream of text. If you paste three examples and then a new item with no marker, the model may treat the new item as a fourth example, summarise the examples, or reply to the wrong one. Clear marks remove that guesswork.

How to mark them (chat app)

  1. Introduce the examples. One line such as "Here are two examples of the format I want."
  2. Label each part the same way. Use the same words every time, such as "Input:" and "Output:". Keep the same spacing and punctuation.
  3. Separate examples from each other. Use a blank line, a line of dashes, or a numbered title such as "Example 1".
  4. End with the real task. Write "Now do this one:" or "Input to process:", then the real input, then a bare "Output:" so the model knows where to start.
  5. Say what the examples are. For example: "The examples are for format only."

Before and after

Before: I need a short title. The report is about sales. Title: Q3 sales rise. The report is about hiring. Title: Hiring slows. The report is about customer churn.

It is hard to see what is an example and what is the question. The model may reply with a hiring title.

After: Write a title of up to four words for each report. Examples are for format only.

Example 1 Report: sales figures for the third quarter Title: Q3 sales rise

Example 2 Report: staff recruitment summary Title: Hiring slows

Now do this one: Report: customer churn analysis Title:

Optional: tags and message pairs for developers

When you build an app, use XML-style tags or real message turns. Anthropic's guide suggests wrapping examples in tags such as <example>. With a chat API, you can also send each example as a user message followed by an assistant message, then the real input as the final user message.

[
  {"role": "system", "content": "Write a title of up to four words. Examples are for format only."},
  {"role": "user", "content": "Report: sales figures for the third quarter"},
  {"role": "assistant", "content": "Q3 sales rise"},
  {"role": "user", "content": "Report: staff recruitment summary"},
  {"role": "assistant", "content": "Hiring slows"},
  {"role": "user", "content": "Report: customer churn analysis"}
]

What goes wrong

  • Inconsistent labels. "Input" in one example and "Q" in another weakens the pattern.
  • No marker for the real input. The model treats it as another example.
  • Real user text inside the examples block. If untrusted text sits among your examples, it can look like an instruction.

Examples

Tagged examples in a single prompt

Classify each message as BILLING or TECHNICAL.

<examples>
<example>
Message: Charged twice in March
Label: BILLING
</example>
<example>
Message: The export button does nothing
Label: TECHNICAL
</example>
</examples>

Message: I cannot log in after the update
Label:

The tags make it clear where the examples end, and the final bare label shows where to answer.

Fixing an answer that replied to an example

A user pastes three samples with no labels and a new item. The model answers the second sample. The fix is to add "Example 1, 2, 3" headings, and a line "Now do this one:" before the real input.

Key points

  • Tell the model what the examples are and what they are for.
  • Use identical labels and layout in every example.
  • Separate examples from each other and from the real input with a clear break.
  • Put the real input last and end with the label the model should complete.
  • In an API, send examples as user and assistant message pairs, or wrap them in tags.

Common mistakes

  • Pasting examples and the real input as one block with no marker between them.
  • Using different labels or layouts from one example to the next.
  • Forgetting to say the examples are for format, not content.
  • Placing untrusted user text inside the examples section.

Check yourself · 2 of 3

Your examples label the input "Input:" in one place and "Q:" in another. What is the best fix?

Choose one answer

Check yourself · 3 of 3

In a chat API, how can you present few-shot examples as message pairs?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic