🎨 Prompt Engineering Fundamentals

Unit 3: The Art & Science of Talking to AI

Master the skill that makes GenAI truly powerful

πŸ“š Today's Journey

From Zero to Prompt Hero

Introduction to Prompt Engineering

What it is and why it matters

Anatomy of Effective Prompts

The building blocks of great prompts

Zero-shot & Few-shot Learning

Teaching AI with examples (or without!)

Advanced Techniques

Chain-of-thought, roles, templates

Hands-on Workshop

Build your own prompt library

πŸ’‘ Goal: By the end, you'll be able to craft prompts that get exactly the outputs you need!

3.1 Introduction to Prompt Engineering

🎯 What is Prompt Engineering?

Definition

Prompt Engineering = The art and science of crafting inputs (prompts) to get desired outputs from AI models

❌ Bad Prompt

"Tell me about AI"

Vague, unfocused, unpredictable results

β†’
βœ… Good Prompt

"Explain artificial intelligence in 3 bullet points for a high school student, focusing on real-world applications"

Clear, specific, actionable

Why It Matters

🎯 Precision

Get exactly what you need, not random outputs

⚑ Efficiency

Save time with first-try success

πŸ’° Cost Savings

Fewer tokens = lower API costs

3.1 Introduction to Prompt Engineering

🧠 The Prompt Engineering Mindset

Think Like a Model Trainer

❌ Common Mistakes

  • Assuming the model "knows" what you want
  • Being too vague or too verbose
  • Not providing context
  • Expecting mind-reading
  • Not iterating and testing

βœ… Best Practices

  • Be explicit and specific
  • Provide clear instructions
  • Give context and examples
  • Specify format and tone
  • Test and refine iteratively

The Golden Rule of Prompting

"If a human wouldn't understand your instruction, neither will the AI"

πŸ’‘ Pro Tip: Prompt engineering is empiricalβ€”what works for GPT-4 might not work for Claude. Always test!

3.2 Anatomy of Effective Prompts

🧩 The 6 Components of Great Prompts

The Prompt Formula

Role + Context + Task + Format + Tone + Examples

Not all components needed every timeβ€”choose what fits your use case!

🎭 Role

"You are an expert..."

Sets the persona

πŸ“ Context

"Given that..."

Background info

🎯 Task

"Please analyze..."

What to do

πŸ“‹ Format

"Output as JSON..."

How to structure

πŸ—£οΈ Tone

"Be professional..."

Style of response

πŸ“š Examples

"Like this:..."

Show don't tell

3.2 Anatomy of Effective Prompts

πŸ” Deconstructing a Great Prompt

Complete Prompt Example

Role You are an experienced Python developer.

Context I'm building a web scraper for e-commerce sites.

Task Write a Python function that extracts product titles and prices from HTML.

Format Use BeautifulSoup4, include error handling, and add docstrings.

Tone Explain your code with inline comments for a beginner.

Example Example HTML: <div class="product"><h2>Laptop</h2><span>$999</span></div>

Result: A well-structured, commented, error-handled function that matches your exact needs!

VS
Poor Prompt

"Write code to scrape websites"

Result: Generic, possibly wrong, no context-specific code

3.2 Anatomy of Effective Prompts

🎯 Clarity & Specificity

The Specificity Spectrum

Too Vague

"Summarize this"

Problem:

  • How long?
  • What format?
  • What to focus on?

Just Right

"Summarize this article in 3 bullet points, focusing on key findings and implications for healthcare"

Clear:

  • Length: 3 points
  • Format: Bullets
  • Focus: Findings + healthcare

⚠️ Watch Out for Over-specification

Too many constraints can be restrictive. Find the balance!

"Write exactly 247 words using only words starting with A-M, in iambic pentameter, about quantum computing..."

This is probably too much! πŸ˜…

3.3 Zero-shot Learning

πŸš€ Zero-shot Learning: No Examples Needed

What is Zero-shot?

Asking the model to perform a task without providing any examplesβ€”relying purely on its pre-trained knowledge

Zero-shot Example

Prompt

Classify the sentiment of this review as positive, negative, or neutral:

"The product arrived on time but the quality was disappointing."

Output

Sentiment: Negative

βœ… When to Use

  • Simple, common tasks
  • Model has strong pre-training
  • Quick prototyping
  • General knowledge questions

❌ When to Avoid

  • Domain-specific tasks
  • Complex formatting needs
  • Specialized terminology
  • Inconsistent quality
3.3 Zero-shot Learning

πŸ’‘ Zero-shot Best Practices

Making Zero-shot Work Better

Be Crystal Clear About the Task

❌ Vague: "Fix this code"

βœ… Clear: "Debug this Python function that's throwing a TypeError"

Specify Output Format

❌: "List the countries"

βœ…: "List the countries in alphabetical order, one per line"

Define Constraints

❌: "Explain quantum physics"

βœ…: "Explain quantum physics in 2 paragraphs for a high school

βœ…: "Explain quantum physics in 2 paragraphs for a high school student"

Use Action Verbs

Classify, Summarize, Extract, Generate, Translate, Rewrite, Analyze, Compare

πŸ’‘ Power Move: Combine clear instructions with role-setting: "As a Python expert, debug this function..."

3.4 Few-shot Learning

πŸ“š Few-shot Learning: Learn from Examples

What is Few-shot?

Providing 2-5 examples of the task to teach the model the pattern you want

Few-shot Example

Prompt with Examples

Extract company name and sentiment from reviews:

Review: "Apple's new iPhone is amazing!"
Company: Apple | Sentiment: Positive

Review: "Tesla's customer service was terrible"
Company: Tesla | Sentiment: Negative

Review: "Google's search results are okay"
Company: Google | Sentiment: Neutral

Review: "Microsoft Teams keeps crashing, very frustrating"
Company:

Output

Company: Microsoft | Sentiment: Negative

3.4 Few-shot Learning

⚑ The Power of Few-shot

Why Examples Are Magic

🎯 Shows Exact Format

Model learns the structure you want without explicit formatting instructions

🎨 Demonstrates Style

Tone, formality, and approach are learned from examples

πŸ”§ Handles Edge Cases

Include tricky examples to show how to handle them

πŸ“Š Improves Consistency

Outputs become more predictable and reliable

How Many Examples?

Examples Name When to Use
0 Zero-shot Simple tasks, quick tests
1 One-shot Show format or style
2-5 Few-shot Complex patterns, edge cases
10+ Many-shot Very specialized tasks
1000+ Fine-tuning Production systems, specific domains
3.4 Few-shot Learning

πŸŽ“ Few-shot Best Practices

Use Diverse Examples

Cover different scenarios and edge cases

βœ… Good: Positive, negative, neutral, mixed, sarcastic reviews

❌ Bad: Only positive reviews

Be Consistent

Use the same format across all examples

Input: [text]
Output: [result]

Input: [text]
Output: [result]

Order Matters

Put the most important/relevant examples last (recency bias)

Quality Over Quantity

3 perfect examples > 10 mediocre ones

3.5 Chain-of-Thought Prompting

🧠 Chain-of-Thought: Show Your Work

What is Chain-of-Thought (CoT)?

Prompting the model to explain its reasoning step-by-step before giving the final answer

❌ Without CoT

Q: If a store has 23 apples and sells 17, then receives 45 more, how many apples does it have?

A: 51

No reasoning shown, might be wrong

β†’
βœ… With CoT

Q: If a store has 23 apples and sells 17, then receives 45 more, how many apples does it have? Think step by step.

A: Let me solve this step by step:
1. Start: 23 apples
2. After selling 17: 23 - 17 = 6 apples
3. After receiving 45: 6 + 45 = 51 apples
Final answer: 51

3.5 Chain-of-Thought Prompting

🎯 Why Chain-of-Thought Works

πŸ” Better Accuracy

Especially for math, logic, and reasoning tasks

+40%
Accuracy improvement on math problems

πŸ› Easier Debugging

See where reasoning went wrong

πŸŽ“ Handles Complexity

Breaks down multi-step problems

CoT Techniques

Zero-shot CoT

Just add "Let's think step by step"

"Solve this problem. Let's think step by step."

βœ… Simple, works surprisingly well

Few-shot CoT

Provide examples with reasoning

Q: 5 + 3 = ?
A: Let me add: 5 + 3 = 8

Q: 10 - 4 = ?

βœ… Most powerful, best results

3.5 Chain-of-Thought Prompting

πŸ’Ό CoT in Real Applications

Example 1: Code Debugging

Prompt

Debug this code. Think through what each line does step by step:

def calculate(x):
  result = x / 0
  return result * 2

Output

Let me analyze step by step:
1. Line 1: Function takes parameter x
2. Line 2: Attempts x / 0 - ERROR: Division by zero!
3. Line 3: Would multiply by 2 (but never reached)

Problem: Division by zero on line 2
Fix: Add check for zero or use try-except

Example 2: Data Analysis

Prompt

Sales dropped 30% in Q3. Think through possible causes step by step.

3.6 Role Prompting & System Instructions

🎭 Role Prompting: Wear Different Hats

What is Role Prompting?

Telling the model to assume a specific persona or expertise to shape its responses

The Power of Roles

Without Role

"Explain blockchain"

Generic, medium complexity explanation

VS
With Role

"You are a blockchain professor. Explain blockchain to first-year students."

Educational, structured, beginner-friendly with analogies

πŸŽ“ Expert Roles

"You are a senior data scientist..."
"As a cybersecurity expert..."
"You are a patent lawyer..."

πŸ‘₯ Audience Roles

"Explain like I'm 5..."
"Write for C-level executives..."
"Teach a beginner..."

🎨 Creative Roles

"You are a creative copywriter..."
"As a storyteller..."
"You are a comedian..."

3.6 Role Prompting & System Instructions

βš™οΈ System Instructions: Setting Persistent Behavior

System vs User Prompts

System: Sets overall behavior (role, constraints, style)
User: Specific task or question

Typical API Structure

System Message

"You are a helpful Python tutor. Always:
- Explain concepts simply
- Provide working code examples
- Use comments to explain each line
- Suggest best practices"

User Message

"How do I read a CSV file?"

AI follows system rules

Great question! Let me show you the simplest way...
[Provides simple explanation + commented code + best practices]

πŸ’‘ Pro Tip: System instructions are perfect for chatbotsβ€”set once, affects all conversations!

3.6 Role Prompting & System Instructions

🎯 Effective Role Patterns

Pattern 1: Expert + Constraints

You are a [EXPERTISE] with [X] years of experience.
Always [BEHAVIOR].
Never [CONSTRAINT].

"You are a security researcher with 10 years experience. Always mention potential risks. Never recommend insecure practices."

Pattern 2: Persona + Style

You are a [PERSONA] who [CHARACTERISTIC].
Respond in a [TONE] manner.

"You are a friendly teacher who loves making complex topics simple. Respond in an encouraging, patient manner."

Pattern 3: Multi-Role

You are both a [ROLE1] and [ROLE2].
Consider [PERSPECTIVE1] and [PERSPECTIVE2].

"You are both a developer and product manager. Consider technical feasibility and user experience."

Pattern 4: Negative Instructions

You are a [ROLE].
DO NOT: [UNWANTED BEHAVIOR]

"You are a medical advisor. DO NOT: Provide diagnoses, recommend specific treatments, or replace professional medical advice."

3.7 Prompt Templates & Frameworks

πŸ“‹ Prompt Templates: Reusable Patterns

Why Templates?

Build once, use everywhere. Templates ensure consistency and save time

Template 1: Content Summarization

Summarize the following [TYPE] in [NUMBER] [FORMAT]:

[CONTENT]

Focus on: [FOCUS_AREAS]
Target audience: [AUDIENCE]

Example Use:

"Summarize the following research paper in 3 bullet points. Focus on: methodology and results. Target audience: non-experts"

3.7 Prompt Templates & Frameworks

πŸ› οΈ Essential Prompt Templates

Template 2: Code Generation

Write a [LANGUAGE] function that [TASK].

Requirements:
- [REQ1]
- [REQ2]
- [REQ3]

Include:
- Error handling
- Docstrings
- Type hints
- Example usage

Template 3: Data Extraction

Extract [FIELDS] from the text below.

Format as JSON:
{
  "field1": "value",
  "field2": "value"
}

Text: [INPUT_TEXT]

Template 4: Creative Writing

Write a [TYPE] about [TOPIC].

Style: [STYLE]
Tone: [TONE]
Length: [LENGTH]
Target audience: [AUDIENCE]

Include: [ELEMENTS]

Template 5: Analysis

Analyze [SUBJECT] for [PURPOSE].

Consider:
1. [ASPECT1]
2. [ASPECT2]
3. [ASPECT3]

Provide: Findings, Insights, Recommendations
3.7 Prompt Templates & Frameworks

🎯 Popular Prompting Frameworks

1. CRISPE Framework

  • Capacity and Role
  • Rinsight (Context)
  • Instructions
  • Statement (Task)
  • Personality (Tone)
  • Experiment (Iterate)

2. RISEN Framework

  • Role: Who is the AI?
  • Instructions: What to do?
  • Steps: How to do it?
  • End goal: What's the output?
  • Narrowing: Constraints

πŸ’‘ Remember: Frameworks are guides, not rules. Adapt to your needs!

3.8 Interactive Prompt Workshop

πŸ”¬ Hands-on Workshop Time!

What We'll Do

Build prompts together, test them live, and create your personal prompt library

Workshop Structure

Round 1: Zero-shot Challenge (10 min)

Write prompts for common tasks without examples

Round 2: Few-shot Practice (10 min)

Add examples to improve your prompts

Round 3: CoT Application (10 min)

Apply chain-of-thought to complex problems

Round 4: Template Building (15 min)

Create reusable templates for your use cases

🎯 Tool: We'll use ChatGPT/Claude/Gemini - bring your laptops!

3.8 Interactive Prompt Workshop

πŸ’ͺ Workshop Challenges

Challenge 1: Email Writer

Task: Write a prompt that generates professional emails

Requirements:

  • Adjustable tone (formal/casual)
  • Different purposes (request/update/apology)
  • Custom signature

Challenge 2: Code Reviewer

Task: Create a prompt for code review

Requirements:

  • Check for bugs
  • Suggest improvements
  • Explain reasoning

Challenge 3: Data Analyzer

Task: Create a prompt for analyzing datasets

Requirements:

  • Use chain-of-thought for reasoning
  • Output key insights and visualization suggestions
  • Handle edge cases like missing data

Challenge 4: Content Generator

Task: Build a prompt for generating social media content

Requirements:

  • Incorporate role prompting (e.g., as a marketer)
  • Specify tone and length
  • Include calls to action

πŸ’‘ Instructions: Work in pairs, test your prompts with an LLM, and share what worked/didn't!

Unit Conclusion

πŸ† Congratulations! You're Now a Prompt Engineer

Key Takeaways

🎯 Precision Matters

Clear, specific prompts yield dramatically better results

🧩 Use the 6 Components

Role + Context + Task + Format + Tone + Examples

πŸš€ Zero-shot vs Few-shot

Use zero-shot for simple tasks, few-shot for patterns and consistency

🧠 Chain-of-Thought

Force step-by-step reasoning for complex problems

🎭 Role Prompting

Make the AI adopt expert personas for better outputs

πŸ“‹ Templates & Frameworks

Build reusable prompts for efficiency and consistency

Your Next Steps

Practice Daily

Apply these techniques in every AI interaction

Build Your Prompt Library

Save your best prompts for reuse across projects

Experiment & Iterate

Test across models (GPT, Claude, Gemini) and refine

Share Knowledge

Teach others β€” teaching solidifies your mastery

Thank You!

You now have the superpower to make GenAI work for you β€” not the other way around.

Questions? Let's discuss! πŸ‘

1 / 24