jixiaxue 知识库
evidence · 2026-04-15

T0-3-real-world-03-prompt-engineering

/Users/shanfang/Documents/pe/jixiaxuegong/research/提示工程教程/evidence/T0-anthropic/T0-3-real-world-03-prompt-engineering.md

来源:https://github.com/anthropics/courses/blob/master/real_world_prompting/03_prompt_engineering.ipynb 爬取日期:2026-03-22

Lesson 3: Prompt engineering

In the first lesson, we quickly reviewed some key prompting tips. In the second lesson, we wrote a prompt that “blindly” applied all of those tips to a single prompt. Understanding these tips is critical, but it’s equally important to understand the prompt engineering workflow and decision making framework.


What is prompt engineering?

Prompt engineering is the art and science of crafting effective instructions for large language models like Claude to produce desired outputs. At its core, prompt engineering involves designing, refining, and optimizing the text inputs (prompts) given to models to elicit accurate, relevant, and useful responses. It’s about “communicating” with Claude in a way that maximizes the model’s understanding and performance on a given task. The importance of prompt engineering cannot be overstated:

How is it different from “basic prompting”?

Let’s define “basic prompting” as simply asking an AI model a question or giving it a straightforward instruction. Prompt engineering, on the other hand, is a more sophisticated and deliberate process.

In essence, prompt engineering elevates the interaction with a model from a casual conversation to a carefully orchestrated exchange designed to maximize the model’s potential in solving real-world problems repeatably. As we progress through this course, you’ll learn the techniques and mindset needed to master this crucial skill.


The Prompt Engineering Lifecycle

Prompt engineering follows a structured lifecycle that helps you iteratively improve your prompts and achieve better results:

1. Plan

Start by clearly defining your task and success criteria. Ask yourself:

2. Draft

Create your initial prompt. Incorporate the best practices we learned in Lesson 1:

3. Evaluate

Test your prompt against sample inputs and evaluate the outputs:

4. Refine

Based on your evaluation, make targeted improvements:

5. Deploy

Once satisfied, integrate your prompt into your application and monitor real-world performance.

This cycle repeats as you encounter new patterns or requirements.


Key Decision Points in Prompt Engineering

When engineering a prompt, you’ll need to make several critical decisions:

Decision 1: What role should Claude play?

Should Claude be:

The role shapes the tone, knowledge level, and approach Claude takes.

Decision 2: How much context does Claude need?

Balance between:

Decision 3: Should you use examples?

Decision 4: What format should the output be?

Specify:

Decision 5: How should Claude handle uncertainty?

Tell Claude to:

Decision 6: What constraints should you apply?

Consider:


Common Prompt Engineering Patterns

Pattern 1: The Expert Advisor

Define Claude as an expert and leverage that persona:

You are a senior software architect with 20 years of experience.
A developer is asking you for advice on...

Pattern 2: Structured Thinking

Ask Claude to break down its reasoning:

First, analyze the problem.
Then, consider the options.
Finally, provide your recommendation with reasoning.

Pattern 3: Few-Shot Learning

Provide examples of the desired behavior:

Here are examples of good summaries:
Example 1: [input] → [output]
Example 2: [input] → [output]

Now summarize this: [new input]

Pattern 4: Role + Format + Constraints

Combine multiple elements:

You are a technical writer. Convert this into a FAQ format.
Each answer should be 2-3 sentences maximum.
Use everyday language.

Content: [text]

Pattern 5: Self-Criticism

Ask Claude to evaluate its own work:

Generate a response. Then, critique it for accuracy, clarity, and completeness.
Provide the improved version.

Practical Exercise: Your First Engineered Prompt

Scenario

You need Claude to analyze customer feedback and categorize it as:

Each piece of feedback should also receive a sentiment score (1-5).

Your Task

  1. Plan: Define success criteria
  2. Draft: Write your initial prompt
  3. Evaluate: Test with provided examples
  4. Refine: Make improvements based on results
  5. Document: Write down your key decisions