C.W.K.
Stream
Lesson 02 of 10 · published

Claude — System Prompts, Long Context, XML Tags

~14 min · providers, claude

Level 0Apprentice
0 XP0/100 lessons0/14 achievements
0/120 XP to next level120 XP to go0% complete

What Claude does well

  • Long context (1M tokens on the latest Opus tier).
  • Extended thinking (explicit budget, visible-to-operator thinking blocks).
  • XML-tagged prompts — the model is heavily trained to respect tag boundaries.
  • Tool use with parallel calls and rich error semantics.
  • Citation feature for grounded answers with span-level traceability.

Quirks to know

  • System prompt is a top-level parameter, not a message — don't mix.
  • Last message must be a user message (or the model has nothing to respond to). Prefill is enabled by appending an assistant message that the model continues.
  • Token counting is server-side via the messages.count_tokens endpoint — there isn't a perfect client-side tokenizer.
  • JSON mode is via tools (tool_choice with a single output tool whose input_schema = your output schema).

Style preferences

Claude responds well to explicit structure: numbered lists, XML tags, named sections. Vague tone instructions ("be helpful") matter less than format anchors and field semantics.

Code

Claude — full-feature call·python
import anthropic

client = anthropic.Anthropic()
resp = client.messages.create(
    model="claude-opus-4-7",
    system=[
        {"type": "text", "text": LARGE_REF, "cache_control": {"type": "ephemeral"}},
        {"type": "text", "text": "You are a contract analyst. Cite sources from <docs>."}
    ],
    thinking={"type": "enabled", "budget_tokens": 6_000},
    tools=[{"name": "emit_findings", "input_schema": SCHEMA}],
    tool_choice={"type": "tool", "name": "emit_findings"},
    max_tokens=2048,
    messages=[{"role": "user", "content": question}]
)

External links

Exercise

Build one prompt that uses XML tags, prompt caching, and a structured tool output simultaneously. Verify cache hits in the response usage block.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.