🚧 Lesson 7 of 10 in Level 01
Level 01 • Lesson 7

Prompt Engineering Basics

How to write effective prompts. Techniques for better results without changing the model.

What is Prompt Engineering?

Prompt engineering is the practice of designing inputs (prompts) to get better outputs from language models. It's like learning to ask the right questions.

Key Insight: The same model can give very different answers depending on how you phrase your question. Prompt engineering is about finding the phrasing that works best.

Why It Matters

Basic Principles

✓ Be Specific and Clear

❌ Vague:
"Tell me about dogs."
✓ Specific:
"Write a 3-paragraph summary about the history of domestic dogs, focusing on their evolution from wolves and their role in human societies."

✓ Provide Context

❌ No context:
"Is this good?"
✓ With context:
"I'm writing a blog post for software engineers about Python best practices. Is the following code example clear and helpful? [code]"

✓ Specify Format

❌ Unstructured:
"List the pros and cons of remote work."
✓ Structured:
"List the pros and cons of remote work. Format your response as: Pros: - [pro 1] - [pro 2] Cons: - [con 1] - [con 2]"

Core Techniques

1. Zero-Shot Prompting

Ask the model to do something without examples. Works well for simple, common tasks.

Classify the sentiment of this review as positive, negative, or neutral: "The movie was okay, nothing special but not terrible either."

2. Few-Shot Prompting

Provide examples of the desired input-output behavior. Helps the model understand the pattern.

Convert these to uppercase: Input: hello Output: HELLO Input: world Output: WORLD Input: prompt engineering Output:

3. Chain-of-Thought (CoT)

Prompt the model to show its reasoning step by step. Dramatically improves complex reasoning.

Q: Roger has 5 tennis balls. He buys 2 more cans of tennis balls. Each can has 3 tennis balls. How many tennis balls does he have now? A: Let's think step by step. Roger started with 5 balls. 2 cans of 3 balls each is 6 balls. 5 + 6 = 11. The answer is 11. Q: A juggler has 16 balls. Half are golf balls and half are tennis balls. If he loses 3 golf balls, how many golf balls does he have left? A:

4. Role Prompting

Tell the model to act as a specific persona. Changes tone and expertise level.

You are an expert Python programmer with 10 years of experience. Review this code and suggest improvements: [code]

5. System vs User Messages

Use system messages for high-level instructions, user messages for specific queries.

System: You are a helpful coding assistant. Always explain your reasoning. User: How do I reverse a list in Python?

Advanced Techniques

Self-Consistency

Generate multiple answers and take the most common one. Reduces random errors.

Tree of Thoughts

Explore multiple reasoning paths and evaluate which is best. Like CoT but branching.

ReAct (Reasoning + Acting)

Alternate between reasoning and taking actions (like using tools). Useful for complex tasks.

Thought: I need to find the population of Paris. Action: Search[population of Paris] Observation: The population of Paris is approximately 2.1 million. Thought: Now I have the information. I can answer the question. Final Answer: The population of Paris is approximately 2.1 million.

Common Pitfalls

❌ Leading questions:
"Don't you think Python is better than JavaScript?"
✓ Neutral:
"Compare Python and JavaScript, discussing their strengths and use cases."
❌ Overloading:
"Explain quantum computing, solve this math problem, and write a poem about it."
✓ One task at a time:
Break into separate prompts or clearly separate sections.
❌ Assuming knowledge:
"Fix this." [code with no context]
✓ Providing context:
"This function should calculate factorial but returns wrong results for n=0."