Stage 02 — Prompt Engineering Fundamentals
The Practical Art of Communicating with AI · Conceptual + Practical · ⏱ 5–7 hours
Learning Objectives
By the end of this stage you will be able to:
- Write clear, effective prompts using zero-shot and few-shot techniques
- Apply chain-of-thought prompting to improve reasoning quality
- Use system prompts to set model behavior, persona, and constraints
- Construct prompts using established frameworks (CRISPE, CO-STAR, RISEN)
- Diagnose and fix common prompt failures
- Use prompt chaining for complex multi-step tasks
- Understand why prompt engineering works at a mechanistic level
Section 1: Why Prompt Engineering Matters
A prompt is your primary interface with an LLM. The same model, given two different prompts, can produce outputs that differ by orders of magnitude in quality. Prompt engineering is the discipline of learning to communicate precisely with AI systems.
This isn't about tricking the model. It's about reducing ambiguity between your intent and the model's interpretation. LLMs are trained on human text and have learned to fill in gaps — if you leave gaps, the model fills them in whatever way the training distribution suggests. Prompt engineering is the art of leaving fewer gaps.
The Prompt Engineering Spectrum
Vague → Clear → Structured → Optimized
"Write me an email"
→ "Write a follow-up email after a sales demo"
→ "Write a professional follow-up email to [name] at [company] after our 30-min demo of [product]. Tone: warm but brief. Goal: schedule next steps. Length: 150 words max."
→ [+ few-shot example + output format spec]
Section 2: Anatomy of a Prompt
Modern LLM APIs accept prompts in structured roles:
The System Prompt
The system prompt is your persistent instruction layer. It runs before any user message and shapes the model's behavior for the entire conversation. System prompts are used for:
- Persona definition: "You are a senior Python engineer. You write concise, well-documented code following PEP 8."
- Behavioral constraints: "Only answer questions related to the company's products. If asked about competitors, politely redirect."
- Output format rules: "Always respond in JSON. Never include explanatory text outside the JSON object."
- Context injection: "The current date is {{date}}. The user's account tier is {{tier}}."
System prompt quality matters enormously. Treat it like a job description — the more precise and detailed, the more reliable the output.
The User Turn
The user message is the immediate request. In single-turn tasks, this contains everything. In multi-turn conversations, this is the latest message.
The Assistant Turn
In few-shot prompting, you can pre-populate an "assistant" turn to prime the model's behavior. Useful for forcing output format compliance.
Section 3: Zero-Shot vs. Few-Shot Prompting
Zero-Shot
You describe the task in natural language without examples.
Classify the sentiment of the following tweet as Positive, Negative, or Neutral.
Tweet: "Just landed in Tokyo, the flight was brutal but the food looks incredible!"
Sentiment:
Zero-shot works well for tasks that are well-described and within the model's training distribution. It fails for unusual output formats or nuanced classification schemes the model hasn't seen.
One-Shot
One example provided.
Classify the sentiment of tweets as Positive, Negative, or Neutral.
Example:
Tweet: "The coffee here is terrible, waited 20 minutes and it was cold."
Sentiment: Negative
Tweet: "Just landed in Tokyo, the flight was brutal but the food looks incredible!"
Sentiment:
Few-Shot (2–10 examples)
Multiple examples calibrate the model to your specific definition of the task.
Classify each tweet as Positive, Negative, Mixed, or Neutral.
Tweet: "Best burger I've ever had, but parking was a nightmare."
Sentiment: Mixed
Tweet: "Their app crashed again. Third time this month."
Sentiment: Negative
Tweet: "The keynote had some interesting ideas but the demos didn't work."
Sentiment: Mixed
Tweet: "Just closed my biggest deal ever!! 🎉"
Sentiment: Positive
Tweet: "The conference has registration open now."
Sentiment: Neutral
Tweet: "The interface is gorgeous but it lags badly on older hardware."
Sentiment:
When to use few-shot:
- Custom classification labels
- Specific tone or style requirements
- Output formats the model doesn't naturally produce
- When zero-shot outputs are inconsistent
Section 4: Chain-of-Thought Prompting
Chain-of-thought (CoT) prompting asks the model to reason step-by-step before giving a final answer. This dramatically improves performance on math, logic, and multi-step reasoning tasks.
Zero-Shot CoT
Simply add "Let's think step by step" or "Think through this carefully before answering."
A train leaves Chicago at 9:00 AM traveling at 60 mph toward New York.
Another train leaves New York at 11:00 AM traveling at 80 mph toward Chicago.
The cities are 780 miles apart. At what time do they meet?
Let's think step by step.
Without CoT, models often jump to the wrong answer. With CoT, they work through the arithmetic and usually get it right.
Few-Shot CoT
Provide examples that include the reasoning chain:
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: Roger starts with 5 balls. 2 cans × 3 balls = 6 new balls. 5 + 6 = 11. Answer: 11.
Q: The cafeteria had 23 apples. If they used 20 for lunch and bought 6 more, how many apples do they have?
A:
When CoT Helps (and When It Doesn't)
Helps:
- Math word problems
- Logic puzzles
- Code debugging
- Multi-step instructions
- Decision making with trade-offs
Doesn't help much:
- Simple factual questions
- Short classification tasks
- Creative writing (the reasoning can interfere)
Important: For GPT-o1/o3 models, CoT is handled internally — don't add "think step by step." The model already reasons internally before responding.
Section 5: Prompt Frameworks
These frameworks help structure complex prompts consistently.
CO-STAR (Context, Objective, Style, Tone, Audience, Response)
CONTEXT: I'm a product manager at a B2B SaaS company. We're announcing a new AI-powered feature for our data analytics platform.
OBJECTIVE: Write a LinkedIn post announcing this feature to drive awareness and sign-ups for our beta.
STYLE: Thought leader — authoritative but accessible, not salesy
TONE: Excited but professional
AUDIENCE: Data analysts, BI engineers, and tech-forward executives at mid-market companies
RESPONSE FORMAT: 150–200 words. Include 3–4 relevant hashtags at the end. No bullet points.
RISEN (Role, Instructions, Steps, End Goal, Narrowing)
Useful for complex tasks requiring sequential steps.
ROLE: You are a senior technical writer specializing in API documentation.
INSTRUCTIONS: Create a README for a Python library.
STEPS:
1. Start with a one-paragraph description of what the library does
2. List installation requirements and commands
3. Show a minimal working example
4. Document the main classes and methods
5. Include a "Contributing" section
END GOAL: A developer should be able to read this README and use the library within 15 minutes.
NARROWING: Keep it under 500 words. Use only Markdown formatting. Assume the reader knows Python but has not used this library.
RTF (Role, Task, Format)
Minimal but effective for most tasks:
Role: You are a financial analyst at a hedge fund.
Task: Summarize the key risks from this earnings call transcript.
Format: Bullet points, max 5 items, each 1–2 sentences.
[transcript here]
Section 6: Output Format Control
Getting consistent, parseable output is critical for production use.
Requesting JSON
Extract the following information from this job posting and return it as JSON.
Required fields:
- company_name (string)
- job_title (string)
- location (string, "Remote" if fully remote)
- salary_range (string or null if not mentioned)
- required_years_experience (integer or null)
- tech_stack (array of strings)
Job posting:
[posting text here]
Return only the JSON object. No other text.
Common issue: Models sometimes include markdown code fences (``json``). Instruct them not to, or strip them in code. In production, use structured output APIs (OpenAI's JSON mode, Anthropic's tool use) instead of relying on prompt-only format control.
Requesting Markdown
Generate a comparison of the top 3 vector databases (Pinecone, Weaviate, Chroma) as a markdown table. Columns: Name, Open Source, Hosted Option, Best For, Pricing Model.
Requesting Structured Lists
List 5 concrete limitations of using LLMs for medical diagnosis.
Format: numbered list. Each item: [Limitation Title]: [2-sentence explanation].
Section 7: Prompt Anti-Patterns to Avoid
Over-Specification
Adding too many constraints causes the model to focus on following format rules at the expense of quality.
Bad:
Write a haiku about autumn that exactly follows the 5-7-5 syllable structure, mentions the color orange at least once, uses the word "falling" exactly once, starts with a noun, ends with an emotion, and has no articles.
Better: Let the model write the haiku first, then add constraints if needed.
Under-Specification
Write me something about machine learning.
No context, no format, no length, no audience. The model will make many assumptions.
Negation Overload
Models struggle with long lists of "don't do X" instructions. State what you want positively.
Bad:
Don't use jargon. Don't be too long. Don't include irrelevant examples. Don't use passive voice. Don't repeat yourself.
Better:
Write in plain language, 100–150 words, with exactly one concrete example. Use active voice throughout.
Ambiguous Pronouns
Compare Python and JavaScript. Tell me which is better for building web scrapers and why it's better.
"It" is ambiguous. Rephrase: "...and explain why that language is better."
Section 8: Prompt Chaining
Complex tasks often require breaking work into sequential prompts, where each output becomes input to the next. This is called prompt chaining.
Example: Research Report Pipeline
Prompt 1: Given this research paper abstract, extract: (a) main claim, (b) methodology, (c) key limitations. Return as JSON.
Prompt 2: Based on this extracted JSON, identify 3 follow-up research questions that address the limitations.
Prompt 3: For each research question, suggest 2–3 existing papers I should search for using their likely titles or keywords.
Each prompt does one thing well. This is more reliable than asking a single prompt to do all three.
When to Chain vs. Single Prompt
Use single prompt:
- The task is self-contained
- Output quality is good
- Task takes < 10 steps
Use chaining:
- Earlier steps inform later steps
- You need to validate/filter before continuing
- The task is too complex for reliable single-prompt output
- You need human review at intermediate steps
Section 9: System Prompt Best Practices
Start with Role Definition
You are an expert Python developer with 10 years of experience building production systems. You specialize in performance optimization, clean architecture, and test-driven development.
Specify Behavior for Edge Cases
If the user asks you to do something outside your expertise, say so clearly and redirect them to the appropriate resource.
If you're unsure about something, say "I'm not certain, but..." rather than stating it as fact.
If the user's code has security vulnerabilities, always point them out even if they didn't ask.
Set Output Conventions
When writing code:
- Always include type hints
- Include a brief docstring for every function
- If the code is longer than 50 lines, break it into functions
- Show example usage after the code block
Inject Context
Current date: {{current_date}}
User's subscription tier: {{tier}}
User's primary programming language: {{preferred_language}}
Checkpoint Assessment
- What is the difference between zero-shot and few-shot prompting? When would you choose each?
- Why does chain-of-thought prompting improve performance on reasoning tasks?
- Write a CO-STAR prompt for this task: "Summarize a quarterly financial report for a non-technical board of directors."
- What are two anti-patterns in this prompt and how would you fix them: "Write me a blog post. Don't make it boring. Don't use bullet points. Don't be too technical. Make it about AI."
- A model keeps returning inconsistent JSON even though you asked for it. Name two approaches to solve this.
- You're building a customer service chatbot. Write the system prompt for it.
Hands-On Exercises
Exercise 1: Prompt Improvement Challenge
Take this weak prompt and make it excellent:
Help me write code for a website.
Write 3 versions: slightly better, good, excellent. Compare outputs.
Exercise 2: Few-Shot Calibration
Create a few-shot prompt to classify customer support tickets into: Bug Report, Feature Request, Account Issue, Billing Question, Other.
Write 6 training examples covering each category. Test it with 3 ambiguous tickets.
Exercise 3: Chain-of-Thought Stress Test
Ask Claude and ChatGPT the same logic puzzle with and without CoT. Document which versions got it right.
Puzzle: "There are 5 houses in a row, each a different color. The green house is immediately to the left of the white house. The owner of the green house drinks coffee..."
(Use a Zebra puzzle variant.)
Exercise 4: System Prompt Design
Design a system prompt for a TechNodeX study assistant that:
- Stays on-topic (only tech education questions)
- Encourages active recall (asks questions back)
- Identifies knowledge gaps and recommends specific stages to review
- Always ends responses with one Socratic question
Key Vocabulary
| Term | Definition |
|---|---|
| Zero-shot | Prompting without examples |
| Few-shot | Prompting with 2–10 examples |
| Chain-of-thought | Prompting that elicits step-by-step reasoning |
| System prompt | Persistent instructions set before the conversation |
| Prompt chaining | Sequential prompts where output feeds into the next input |
| Temperature | Randomness parameter; 0 = deterministic, 1+ = creative |
| CO-STAR | Framework: Context, Objective, Style, Tone, Audience, Response |
| RTF | Framework: Role, Task, Format |
| Structured output | Forcing JSON/markdown/specific format via API or prompt |
What's Next
Stage 3 moves from theory to code. You'll use Python to call the Claude, OpenAI, and Gemini APIs — building real scripts that handle conversations, streaming, function calling, and basic error handling.
Lock In Founding Member Access
Get full access to every course on TechNodeX — AI, cybersecurity, Python, and everything we build next. $9/month, price locked forever.
Become a Founding Member →