Skip to content

Lesson 12 ยท Prompting Fundamentals

Prompting Claude

Apply Anthropic's official prompting guidance to Claude: clear requests with reasons, tagged examples, long documents first, a system role and effort settings.

Anthropic publishes a prompting guide for Claude, plus separate pages for individual models. Much of it matches good practice anywhere. Some points, such as how it recommends laying out long documents and which API settings are rejected, are worth learning separately.

This lesson explains the main ideas in original words and examples, as of December 2026. This tutorial is independent of Anthropic.

Be direct and explain why

Treat Claude like a capable new colleague who knows nothing about your project. A useful test from the guide: show your prompt to a person with little context. If it would confuse them, it will probably confuse Claude too.

If you want more than the minimum, say so. Use numbered steps when order or completeness matters. Then add the reason behind unusual rules, because a reason lets the model handle cases you did not list.

Weaker Stronger
Never use tables. A screen reader reads the reply aloud, and tables are hard to follow that way, so use short sentences and lists.
Make a packing list. Make a packing list for a 3-day winter work trip with one small bag. Group items and mark what can be worn twice.

The guide also advises describing the format you want instead of only what to avoid.

Examples and XML tags

Examples are a strong way to steer format and tone. The guide recommends examples that are relevant, varied and clearly marked, and suggests three to five. Wrap each in an <example> tag, and the set in <examples>.

Tags also separate other kinds of content. Pick descriptive names and use them consistently:

TEXT
<instructions>
Classify each message as billing, delivery or other. Reply with one word.
</instructions>

<examples>
<example>
Message: I was charged twice. -> billing
</example>
<example>
Message: The parcel says delivered but it is not here. -> delivery
</example>
<example>
Message: Do you have a store in my city? -> other
</example>
</examples>

<message>
{{MESSAGE}}
</message>

Tags help Claude read the structure. They do not make untrusted text safe.

Long documents go first

For large inputs (the guide mentions roughly 20,000 tokens or more), Anthropic advises placing the documents near the top and your question after them. Wrap each document and its source in tags. For long document tasks you can also ask Claude to first extract relevant quotes and then work from them.

Python Assemble a long-document prompt

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The function escapes angle brackets so that text in a document cannot close your tags by accident. This keeps the structure tidy; it is not a defense against prompt injection. The sample documents are tiny, so this only shows the layout.

Give Claude a role

The guide notes that even a one-sentence role in the system prompt can focus behavior and tone. In Claude's API, the system prompt is the top-level system field.

Python
# Read-only: needs the anthropic package and an API key
import anthropic

client = anthropic.Anthropic()
message = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=4000,
    system="You are a patient tutor for adults learning basic bookkeeping.",
    output_config={"effort": "medium"},
    messages=[{"role": "user", "content": "What is the difference between profit and cash?"}],
)
print(message.stop_reason)
for block in message.content:
    if block.type == "text":
        print(block.text)

Settings that differ from older advice

Old tutorials may suggest settings that current Claude APIs do not accept. These points reflect Anthropic's API reference as of late 2026. Check it for your model and API version.

  • Thinking depth is controlled mainly with output_config={"effort": ...}, from low to max. Supported levels depend on the model. Opus 5.5 and Haiku 5.5 default to medium.
  • Sampling parameters such as temperature, top_p and top_k are rejected under API version 2026-10-21.
  • Prefill, meaning writing the start of the assistant's reply yourself, is rejected on current models. Use structured outputs when you need a fixed shape.
  • Length: changing effort does not reliably change reply length on every model. Say how long you want the answer to be.

max_tokens is a hard limit that includes thinking, so leave room, and check whether stop_reason is max_tokens.

Read the notes for your model

Claude models differ. Anthropic's model-specific prompting pages cover points such as how often a model reports progress during long work, how much initiative it takes, and how to choose effort. Strong wording that once helped an older model may now cause too much of that behavior. After a model change, rerun your tests and trim.

The general guide describes the latest models as more concise and natural than earlier ones, with exceptions noted per model. If you want a summary after tool work, ask for it.

A role such as "You are a lawyer" changes style and focus. It does not give the model a license, current facts or reliability. Verify anything that matters.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why explain the reason behind a formatting rule?

    A reason gives the model a goal to generalize from.
  2. 2. For a very long document, where does Anthropic's guide suggest placing your question?

    The guide advises long material near the top and the query after it.
  3. 3. How should you control how deeply a current Claude model thinks?

    Effort is the recommended control; sampling parameters and prefill are rejected.
  4. 4. You move to a newer Claude model. What should you do with your prompt?

    Model behavior differs, so old fixes can become unnecessary or harmful.

Summary

  • Be specific, explain why, and say what you want the reply to look like.
  • Use a few varied examples in tags, and consistent tags for other content.
  • Put long documents before the question and consider asking for quotes first.
  • Use system for the role and output_config.effort for depth; follow model-specific notes.

Next: Zero-Shot and Few-Shot Prompting

Your progress is saved in this browser. No account needed.