Chapter 1: Anatomy of a Prompt
π― Learning Objectivesβ
After completing this chapter, you will be able to:
- Identify the four key components of a prompt
- Understand how each component affects AI output
- Construct prompts with all necessary elements
- Recognize when components are missing or weak
π Introductionβ
Just as a well-constructed sentence has subjects, verbs, and objects, a well-designed prompt has distinct components that work together to produce the desired output. Understanding these components is fundamental to becoming an effective prompt engineer.
The Four Components of a Promptβ
Every effective prompt can be broken down into four key components:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β PROMPT ANATOMY β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββββββ β
β β 1. INSTRUCTION β β What task to perform β
β ββββββββββ¬βββββββββ β
β β β
β ββββββββββΌβββββββββ β
β β 2. CONTEXT β β Background information β
β ββββββββββ¬βββββββββ β
β β β
β ββββββββββΌβββββββββ β
β β 3. INPUT β β Data to process β
β ββββββββββ¬βββββββββ β
β β β
β ββββββββββΌβββββββββ β
β β 4. OUTPUT FORMATβ β Desired response structure β
β βββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Not every prompt needs all four components, but understanding when and how to use each is crucial.
Component 1: Instructionβ
The instruction tells the AI what task to perform. It's the action-oriented part of your prompt.
Characteristics of Good Instructionsβ
| Characteristic | Example |
|---|---|
| Clear | "Summarize" not "Do something with" |
| Specific | "List 5 benefits" not "Talk about benefits" |
| Action-oriented | Uses verbs: write, analyze, explain, compare |
| Unambiguous | One interpretation possible |
Examplesβ
Weak Instructions:
β "Dogs"
β "Tell me stuff about marketing"
β "Code"
Strong Instructions:
β "Explain the top 3 training techniques for puppies"
β "Write a 200-word email marketing copy for a fitness app"
β "Debug this Python function and explain the fixes"
Instruction Verb Libraryβ
| Category | Verbs |
|---|---|
| Generate | Write, create, compose, draft, produce |
| Analyze | Examine, evaluate, assess, review, critique |
| Transform | Convert, translate, rewrite, simplify, expand |
| Explain | Describe, clarify, define, illustrate, elaborate |
| Compare | Contrast, differentiate, distinguish, relate |
| Organize | List, categorize, rank, prioritize, outline |
Component 2: Contextβ
Context provides background information that helps the AI understand the situation and produce more relevant responses.
Types of Contextβ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β TYPES OF CONTEXT β
βββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββ€
β Role/Persona β "You are a senior financial analyst..." β
βββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββ€
β Audience β "...explaining to high school students" β
βββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββ€
β Purpose β "...for a quarterly investor report" β
βββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββ€
β Constraints β "...within 500 words, avoiding jargon" β
βββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββ€
β Background β "Given that sales dropped 15% last year" β
βββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββ
Context Exampleβ
Without Context:
Write about renewable energy.
Result: Generic, unfocused content
With Context:
You are an environmental policy expert writing for
a government briefing document.
Target audience: Legislators with limited technical background
Purpose: To inform policy decisions on renewable energy investment
Tone: Professional, objective, evidence-based
Constraints: Focus on solar and wind energy in North America
Write about renewable energy.
Result: Focused, appropriate content for the specific use case
How Much Context is Enough?β
Include context until you can clearly answer these questions:
- Who is communicating?
- Who is the audience?
- What is the purpose?
- What constraints apply?
Component 3: Inputβ
The input is the specific data, text, or information you want the AI to process.
Input Typesβ
| Type | Example Use |
|---|---|
| Text | Document to summarize, article to analyze |
| Code | Function to debug, script to optimize |
| Data | Numbers to interpret, lists to process |
| Questions | Queries to answer |
| Examples | Samples to learn from |
Input Formatting Best Practicesβ
Clear Delimiters:
Analyze the following customer review:
"""
I bought this product last week and it's amazing!
The quality exceeded my expectations. Would definitely
recommend to friends.
"""
Provide sentiment analysis and key themes.
Labeled Sections:
Compare these two code snippets for efficiency:
[CODE A]
def sum_list(numbers):
total = 0
for n in numbers:
total += n
return total
[CODE B]
def sum_list(numbers):
return sum(numbers)
Which is more efficient and why?
Common Input Delimitersβ
Triple quotes: """content"""
Triple backticks: ```content```
XML tags: <input>content</input>
Square brackets: [INPUT] content [/INPUT]
Dashes: ---content---
Component 4: Output Formatβ
The output format specifies how you want the AI to structure its response.
Format Specificationsβ
| Format Type | When to Use |
|---|---|
| Prose/Paragraph | Explanations, stories, articles |
| Bullet Points | Lists, features, quick scans |
| Numbered Lists | Steps, rankings, sequences |
| Tables | Comparisons, structured data |
| Code | Technical outputs |
| JSON/XML | Programmatic processing |
| Markdown | Formatted documentation |
Format Examplesβ
Requesting Bullet Points:
List the benefits of remote work.
Format: Bullet points (5-7 items)
Each point: One sentence with a brief explanation
Requesting a Table:
Compare Python and JavaScript for web development.
Format your response as a markdown table with columns:
| Aspect | Python | JavaScript |
Requesting JSON:
Extract information from this job posting and return as JSON:
{
"title": "",
"company": "",
"location": "",
"salary_range": "",
"required_skills": [],
"experience_years": ""
}
Putting It All Togetherβ
Here's a complete prompt using all four components:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β INSTRUCTION β
β Analyze the following customer feedback and provide β
β actionable insights for our product team. β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β CONTEXT β
β You are a customer experience analyst at a SaaS company. β
β This feedback is from users of our project management tool. β
β We're preparing for our Q1 product planning meeting. β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β INPUT β
β """ β
β Feedback 1: "Love the collaboration features but the β
β mobile app is really slow." β
β Feedback 2: "Can't figure out how to set recurring tasks." β
β Feedback 3: "Great tool! Wish there was dark mode." β
β Feedback 4: "Integration with Slack keeps breaking." β
β Feedback 5: "The calendar view is confusing." β
β """ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β OUTPUT FORMAT β
β Structure your response as: β
β 1. Executive Summary (2-3 sentences) β
β 2. Key Themes (bullet points) β
β 3. Priority Recommendations (numbered, top 3) β
β 4. Quick Wins vs Long-term Investments (table) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Component Checklistβ
Use this checklist when crafting prompts:
β INSTRUCTION
β Clear action verb
β Specific task defined
β No ambiguity
β CONTEXT (as needed)
β Role/persona defined
β Audience specified
β Purpose stated
β Constraints listed
β INPUT (if applicable)
β Clearly delimited
β Properly formatted
β Complete information
β OUTPUT FORMAT
β Structure specified
β Length guidelines
β Style requirements
Common Mistakesβ
1. Missing Instruction
β "Customer feedback about our app"
β "Analyze this customer feedback and identify the top concerns"
2. Vague Context
β "You're an expert. Write about technology."
β "You are a cybersecurity consultant writing for small business owners with limited technical knowledge."
3. Unmarked Input
β Summarize: The product was good but shipping was slow
β Summarize the following review:
"""
The product was good but shipping was slow
"""
4. Missing Output Format
β "Tell me about the French Revolution"
β "Explain the causes of the French Revolution in 3-5 bullet points, each with one sentence of context"
Practical Exerciseβ
Exercise: Component Identificationβ
Identify the components in this prompt:
You are a nutritionist creating content for a health app
targeted at busy professionals.
Analyze the following meal plan and suggest improvements:
Breakfast: Coffee and a muffin
Lunch: Fast food burger and fries
Dinner: Frozen pizza
Snacks: Chips and soda
Provide your response as:
1. Current issues (bullet points)
2. Suggested improvements (numbered list)
3. Sample one-day meal plan (formatted schedule)
View Answer
Instruction: "Analyze the following meal plan and suggest improvements"
Context:
- Role: Nutritionist
- Purpose: Content for a health app
- Audience: Busy professionals
Input: The meal plan (Breakfast through Snacks)
Output Format:
- Bullet points for issues
- Numbered list for improvements
- Formatted schedule for sample plan
Key Takeawaysβ
- Every prompt has four potential components: Instruction, Context, Input, Output Format
- Instructions should be clear, specific, and action-oriented
- Context provides the background needed for relevant responses
- Input should be clearly delimited and formatted
- Output Format specifications dramatically improve response usefulness
- Not every prompt needs all four components, but knowing when to use each is crucial
What's Next?β
In the next chapter, we'll explore types of prompts, including the powerful concepts of zero-shot and few-shot prompting.