Anthropic interactive prompt engineering tutorial learning and collation

Star Count: 25.3K+ , Claude Model Optimization from Beginner to Advanced prompt-eng-interactive-tutorial is an open-source educational project launched by Anthropic that provides comprehensive step-by-step guidance to help users master the techniques of designing efficient prompts for Claude AI models.
It covers infrastructure to advanced chain prompt and tool integration, with 9 interactive lessons and Playground lab environments that allow learners to practice writing and debug prompts.
With its emphasis on the 80/20 principle and practical scenarios such as chatbots, law, finance, and coding, this tutorial has become a popular learning resource in the field of prompt engineering.

Course objectives

  • Master the basic elements of a good prompt structure.
  • Identify common failure patterns and master 80/20 tips for these situations.
  • Learn about the strengths and limitations of Claude models (and similar large language models).
  • Build strong prompts from scratch for typical use cases (e.g., chatbots, legal services, financial services, programming).

Course structure & overview of chapters

The course consists of 9 chapters + appendices, divided into three levels: “Beginner”, “Intermediate” and “Advanced”.

Beginner chapter

Chapter 1: Basic Prompt Structure

  • Explain what prompts consist of: context, user intent, restrictions/formatting requirements, etc.
  • Emphasize the importance of clear structure.
  • Exercise: Adjust a simple prompt to see how the model output changes.

Chapter 2: Being Clear and Direct

  • Teach you how to make the model “understand what you think”: avoid ambiguity and avoid implicit assumptions.
  • Exercise: Write multiple versions of the prompt for the same task and compare the results.

Chapter 3: Assigning Roles

  • Use “character setting” (e.g., “You are a legal expert” or “You are a history professor”) to set the tone or intellectual background.
  • Exercise: Assign roles for different scenarios and watch the model output change.

Intermediate Chapter

Chapter 4: Separating Data from Instructions

  • Separate the “data” (input) from the “instructions” (what you want the model to do) to avoid confusion.
  • Common problems in prompt design, such as embedding data directly into instructions, can lead to confusion.
  • Exercise: Split and reconstruct the data and instructions in the prompt.

Chapter 5: Formatting Output & Speaking for Claude

  • How to control output formats (e.g., JSON, Markdown, XML tags, etc.).
  • How to “speak for Claude” – i.e., use the model’s preferred formatting, markup, etc.
  • Exercise: Design prompts require output in a specific format (e.g., “Please return as a JSON array”).

Chapter 6: Precognition (Thinking Step by Step)

  • The model is guided to “think”/list the steps before outputting the results.
  • Use tags (such as <scratchpad>,<analysis> ) to help the model with segmented inference.
  • Exercise: Let the model list the advantages and disadvantages before making a judgment.

Chapter 7: Using Examples

  • Give the model “Sample Input→ Sample Output” as a few-shot prompt.
  • Examples can guide the model to the behavior you want more quickly.
  • Exercise: Provide 2-3 examples and let the model mimic.

Advanced Chapter

Chapter 8: Avoiding Hallucinations

  • Models may “make up” facts/misuse information. This chapter teaches you strategies to reduce this.
  • Example: Ask the model to extract evidence from the document and then respond based on the evidence.
  • Exercise: Given a long document, let the model extract references before outputting conclusions.

Chapter 9: Building Complex Prompts (Industry Use Cases)

  • Provide exercises for multiple industry scenarios: chatbots, legal services, financial services, programming, etc.
  • Exercise: Choose an industry (e.g., programming task) to design a prompt built from scratch.

Appendix: Beyond Standard Prompting

  • Chaining Prompts
  • Tool Use
  • Search & Retrieval

Study suggestions

  • After reading the “theoretical part” of each chapter, you must do exercises: modify the prompts and see the difference in results.
  • Record the results before and after the change in the exercise: this way you can visualize the impact of the “cue change” on the output quality.
  • Prioritize the industry use cases in Chapter 9 for the application areas you care about (e.g., you learn Python/AI-assisted programming).
  • Combining “output format constraints + role setting + step-by-step thinking” usually works better.
  • Note model limitations: Suggest that the project can be optimized, but it does not guarantee that the model “knows everything” or “is completely error-free”. The content of Chapter 8 is crucial.

Practical notes

Use a notebook (if you’re restoring an item)

  1. Installation dependencies:pip install anthropic jupyterlab
  2. Start:jupyter lab
  3. Open the notebooks/01_basic_prompt_structure.ipynb
  4.  prompt Modify the content and run the comparative output.
    (You need to configure ANTHROPIC_API_KEYit in the environment variables)

🎬 Step 1. Prepare the original text

Enter the following in the Claude or ChatGPT window (or in Notebook):

请总结下面的文本内容:

今天的天气非常糟糕,暴雨导致道路积水。很多上班族被迫在地铁站排队两个小时。
与此同时,超市的面包货架被一扫而空。城市仿佛回到了疫情时期。

Get the output (the AI may only write one sentence, for example):

Bad weather has caused transportation inconvenience and affected people’s lives.

🎯 Problem: Too vague, no structure, no emotional information.

🎬 Step 2. Improved Prompts

Second Input Improved Prompt:

请总结下面的文本内容,并使用以下格式:
- 用3个要点列出主要事件
- 每个要点后标注情绪倾向(如“负面”“中性”“正面”)

文本如下:
今天的天气非常糟糕,暴雨导致道路积水。很多上班族被迫在地铁站排队两个小时。
与此同时,超市的面包货架被一扫而空。城市仿佛回到了疫情时期。

The AI output could be:

  • Heavy rains cause waterlogging on roads and paralyzed traffic (negative)
  • Difficult commuting for office workers, long queues (negative)
  • Citizens rush to buy daily necessities, and social order is affected (negative)

🎯 Effect: Structured + Mood Labels + More Available.

Great, JupyterLab is already running. Here are two ways to “test right away”:

Clone the official tutorial and run it (closest to the project)

  1. Click “Terminal” on this page
    After entering the terminal, execute them in turn:
git clone https://github.com/anthropics/prompt-eng-interactive-tutorial.git
cd prompt-eng-interactive-tutorial
pip install -r requirements.txt
  1. Set up the Claude API Key
  • Temporary (current session):
    In the first cell of the Jupyter Notebook , write first:import os os.environ["ANTHROPIC_API_KEY"] = "你的sk-ant-开头的密钥"
  • or Windows Global (recommended): Takes effect after Terminal Input:setx ANTHROPIC_API_KEY "你的密钥" Close and reopen the Terminal or browser tab.
  1. Open the file bar on the left → prompt-eng-interactive-tutorial/notebooks/
    Double-click 01_basic_prompt_structure.ipynb(or any chapter) → the top menu Run > Run All Cells
    If you play “Trust this notebook”, click Trust.

If you see that each cell outputs normally (Claude’s text appears), it is OK.

Create a new minimum workable example (faster validation)

  1. In the Launcher, click Python 3 (ipykernel) to create a new notebook.
  2. Run the following cells in turn:

Cell 1: Installation & Key (just use the costume once for the first time)

!pip -q install --upgrade anthropic

import os
os.environ["ANTHROPIC_API_KEY"] = "你的sk-ant-密钥" # 没有就先去 anthropic.com 获取

Cell 2: Create a client + write a contrast test function

from anthropic import Anthropic

client = Anthropic() # 会自动读 ANTHROPIC_API_KEY

def ask(prompt: str):
 resp = client.messages.create(
 model="claude-3-5-sonnet-latest", # 你也可以换 opus/haiku
 max_tokens=400,
 messages=[{"role": "user", "content": prompt}]
 )
 return resp.content[0].text

baseline = """请总结下面的文本:
今天的天气非常糟糕,暴雨导致道路积水。很多上班族在地铁站排队两个小时。
与此同时,超市的面包货架被一扫而空。城市仿佛回到了疫情时期。
"""

improved = """请总结下面的文本,并严格按此格式输出:
- 用3个要点列出主要事件
- 每个要点后用括号标注情绪倾向(负面/中性/正面)

文本如下:
今天的天气非常糟糕,暴雨导致道路积水。很多上班族在地铁站排队两个小时。
与此同时,超市的面包货架被一扫而空。城市仿佛回到了疫情时期。
"""

print("—— 基线提示 ——")
print(ask(baseline))
print("n—— 优化提示 ——")
print(ask(improved))

Github:https://github.com/anthropics/prompt-eng-interactive-tutorial
Tubing:

Scroll to Top