Study notes · 4.6% of the exam

Prompt Engineering

Write and iterate on prompts that get reliable behavior: clear instructions, good examples, correct placement of instructions across system, user, and tool components, output constraints, and safe handling of user input.

Key points

  1. 1

    Be clear and direct. State the audience, purpose, output format, length, and what to exclude, as if briefing a capable new colleague with no context.

  2. 2

    Explain why a rule exists (for example, "this will be read aloud by a text-to-speech engine"). Claude generalizes from the reason to cases the rules never listed.

  3. 3

    Tell Claude what to do rather than what not to do (for example "write in flowing prose paragraphs" instead of "no markdown"). Match your prompt's own style to the output you want.

  4. 4

    Few-shot examples are one of the most reliable ways to steer format and tone. Use about 3 to 5 examples that are relevant, diverse, and wrapped in <example> tags.

  5. 5

    Use XML tags to separate instructions, context, examples, and variable input, with consistent descriptive names that the instructions refer to.

  6. 6

    Put the role and stable, global rules in the system prompt, and per-request content and the task in the user turn. Tool-specific guidance (what a tool does, when to use it, parameter formats) belongs in a detailed tool description.

  7. 7

    Keep one authoritative copy of each rule. Duplicated or contradictory instructions across components cause erratic behavior.

  8. 8

    For long documents (roughly 20k+ tokens), put the documents at the top in XML tags with metadata, and the instructions and question at the end. Queries at the end can improve quality by up to 30%.

  9. 9

    Use prompt chaining (separate calls) when you need to inspect, log, or branch on intermediate outputs. A common pattern is draft, then review against criteria, then refine.

  10. 10

    Newer models follow instructions closely. Emphatic wording such as "CRITICAL: you MUST" written for older models can cause overtriggering, so use plain guidance.

  11. 11

    Refine iteratively and empirically. Define success criteria, keep a test set that includes past failures, change one thing at a time, and re-run the set before shipping. When patches pile up and conflict, consolidate the prompt.

  12. 12

    Input sanitization means treating user-supplied content as data. Wrap it in delimiters, neutralize delimiter tags inside it, and state that tagged content is material to process, never instructions to follow.

  13. 13

    Recent models do not accept assistant prefill (400 error). Use structured outputs or direct instructions for format, such as "respond without preamble".

Test yourself on Prompt Engineering

Ten questions, with the answer and explanation after each one.