← Previous | 🏠 Home | Next →
🌟 Overview
Welcome to Module 02. If Module 01 was about understanding the “engine” of AI, Module 02 is about learning how to drive it.
Prompt Engineering is the practice of designing inputs (prompts) to yield optimal outputs from Large Language Models (LLMs). Many users claim “AI is stupid” or “it didn’t give me what I wanted” simply because they treat LLMs like Google Search. LLMs do not search; they generate. To get high-quality generation, you must provide high-quality constraints, context, and formatting instructions.
In this massive deep dive, we will cover the anatomy of a perfect prompt, explore multiple prompting frameworks, provide 15 detailed before/after examples, and dig into advanced techniques like Meta-Prompting and Chain-of-Thought reasoning.
🏗️ 1. The Anatomy of a Perfect Prompt: The CREATE Framework
A world-class prompt is not a single sentence. It is a carefully structured micro-document. While you don’t need all these elements for a quick question, complex workflows require the CREATE framework:
- C – Context: Who are you, and what is the background situation? (e.g., “I am a junior frontend developer working on a React app…”)
- R – Role: Who is the AI supposed to be? (e.g., “Act as a strict Senior Software Architect…”)
- E – Explicit Task: What exactly do you want? Use active verbs. (e.g., “Review the attached code and find memory leaks…”)
- A – Audience: Who is the output for? (e.g., “Explain the solution so a beginner can understand it…”)
- T – Tone & Format: How should it sound, and how should it look? (e.g., “Keep the tone professional. Output the results as a Markdown table…”)
- E – Examples (Optional): Show, don’t just tell. (e.g., “Here is an example of what a good output looks like…”)
Systematic evaluation of prompt criteria and model outputs via LLM-as-a-Judge workflow
🛠️ 2. Core Prompting Techniques Deep Dive
2.1. Zero-Shot Prompting
Asking the model to perform a task without providing any prior examples. You rely entirely on the model’s pre-trained knowledge.
Prompt: “Translate the following English phrase to French: ‘Where is the library?'”
- Best for: Simple factual queries, basic translation, general knowledge.
2.2. Few-Shot Prompting
Providing the model with a few examples (usually 3 to 5) to establish a distinct pattern, tone, or formatting rule that the model should mimic.
Prompt:
Classify the sentiment and identify the core emotion of the text.
Text: I absolutely love this new phone! -> Sentiment: Positive, Emotion: Joy
Text: The customer service was terribly slow. -> Sentiment: Negative, Emotion: Frustration
Text: The delivery arrived on Tuesday. -> Sentiment: Neutral, Emotion: None
Text: I was so scared when the app deleted my data! -> Sentiment: Negative, Emotion: Fear
Text: I am somewhat annoyed but the product works. -> Sentiment:
2.3. Chain-of-Thought (CoT) Prompting
LLMs do not “think” internally by default; they output words immediately. CoT forces the model to write out its reasoning step-by-step before giving the final answer. This prevents the model from jumping to a hallucinated conclusion.
Prompt: “A farmer has 15 sheep. All but 8 die. How many are left? Think step-by-step and explain your reasoning clearly before providing the final number.“
- Why it works: By forcing the model to generate tokens explaining the logic, it gives its attention mechanism the correct “mathematical runway” to land on the correct answer.
Token probability distributions during Chain-of-Thought reasoning steps
2.4. Role-Based Prompting (Persona Adoption)
Assigning an expert persona shifts the model’s internal statistical weighting toward high-quality, domain-specific terminology.
Prompt: “Act as a world-class SEO copywriter. You specialize in ranking B2B SaaS articles on Google…”
- Why it works: The model has read millions of forum posts. If you don’t assign a role, it averages out the writing style. If you assign an “expert” role, it narrows its token prediction to professional-grade literature.
2.5. Negative Prompting
Explicitly telling the model what NOT to do. LLMs are eager to please and will often add unnecessary introductions (“Sure, I can help with that!”) or cliches.
Prompt: “Write a welcome email for our new users. Negative constraints: Do NOT use corporate jargon (like ‘synergy’ or ‘leverage’). Do NOT use emojis. Do NOT start the email with ‘Dear’. Do NOT exceed 150 words.“
Visual demonstration of negative prompting eliminating unwanted features and artifacts
🔄 3. The 15 Before/After Prompt Transformations
Here are 15 real-world examples demonstrating how moving from a “Search” mentality to an “Engineering” mentality drastically improves outputs.
📝 Category 1: Writing & Content Creation
| Goal | Bad Prompt ❌ | Good Prompt ✅ |
|---|---|---|
| Email to Boss | “Write an email asking for vacation.” | “Act as a professional employee. Write a short, polite email to my manager requesting Paid Time Off from Oct 10-15. Mention that all my Q3 projects are up to date and John will cover for me.” |
| Blog Ideas | “Give me blog ideas for my fitness site.” | “I run a blog for pregnant women interested in safe weightlifting. Generate 10 highly specific, SEO-friendly blog post titles. Exclude generic topics like ‘benefits of exercise’.” |
| Summarization | “Summarize this article.” | “Summarize the key arguments of this attached article in exactly 5 bullet points. Tailor the summary for a high school student to understand. Bold the most important sentence in each bullet.” |
| Rewriting | “Make this sound better: [Text]” | “Act as an expert copy editor. Review this text for pacing and grammar. Rewrite it to be punchy and persuasive (like an Apple product launch). Keep it under 200 words.” |
| Social Media | “Write a tweet about our new coffee.” | “Write a Twitter thread (3 tweets) announcing our new Pistachio Latte. Target audience: busy college students. Tone: energetic but not cringy. Do NOT use hashtags.” |
💻 Category 2: Coding & Development
| Goal | Bad Prompt ❌ | Good Prompt ✅ |
|---|---|---|
| Debugging | “Fix my code: [Code]” | “I am writing a React component. This code: [Code] throws a ‘Null Reference’ error on line 42 when the user clicks ‘Submit’. Identify the bug, explain why it happened, and provide the corrected code block.” |
| Writing Scripts | “Write a web scraper for Amazon.” | “Write a Python script using Playwright to extract product titles and prices from a given URL. Handle pagination up to 3 pages. Output the data as a clean JSON file. Add inline comments explaining the logic.” |
| Code Review | “Is this code good?” | “Act as a Senior Principal Engineer. Perform a strict code review on this Python snippet. Focus heavily on security vulnerabilities, Big-O performance, and PEP-8 compliance.” |
| Database | “Give me a SQL query to find users.” | “Write a PostgreSQL query to find all users who signed up in the last 30 days but haven’t made a purchase. The tables are users (id, created_at) and orders (id, user_id, amount). Use a LEFT JOIN.” |
| Regex | “Write a regex for email.” | “Write a Regular Expression (flavor: JavaScript) that matches corporate email addresses ending ONLY in ‘.com’ or ‘.org’. It should ignore Gmail or Yahoo addresses. Explain how the regex works step-by-step.” |
📊 Category 3: Business & Analysis
| Goal | Bad Prompt ❌ | Good Prompt ✅ |
|---|---|---|
| Data Extraction | “Find the names in this text.” | “Extract all human names and company names from the following text. Output the results strictly as a Markdown table with two columns: ‘Name’ and ‘Entity Type’. Do not include any conversational filler.” |
| Brainstorming | “How do I market my app?” | “I am launching a new budget-tracking app for freelancers. Ask me 5 questions about my budget, timeline, and unique features. Wait for my answers. Then, generate a 30-day go-to-market strategy.” |
| Interview Prep | “Help me practice for an interview.” | “Act as a strict hiring manager for a Senior UX Designer role at Google. Ask me one technical interview question at a time. Wait for my response. Critique my answer, then ask the next question.” |
| Translation | “Translate this to Spanish.” | “Translate the following marketing copy into Mexican Spanish. Ensure the tone is highly colloquial and conversational. Do not use formal Castilian Spanish (Spain). Maintain the humor of the original.” |
| Learning | “Explain quantum physics.” | “Explain the core concept of quantum entanglement using an analogy involving a pair of magical dice. The explanation must be suitable for a smart 12-year-old. Keep it under 3 paragraphs.” |
X-Y plot matrix demonstrating prompt emphasis and parameter variation on generative outputs
🇮🇷 4. Persian-Language Prompting Quirks & Strategies
Prompting in Farsi (Persian) introduces unique technical and linguistic challenges.
Cross-lingual semantic embedding space bridging concepts across languages and modalities
4.1. The Token Inefficiency Problem
As discussed in Module 1, Farsi text consumes significantly more tokens than English.
- The Problem: If you ask the AI to write a very long Persian article, it might stop generating mid-sentence because it hit its output token limit.
- The Fix: Simply type “ادامه بده” (Continue) or “Continue exactly where you left off.” The model will resume generating the text.
4.2. Ketabi (Formal) vs. Ameeyaneh (Colloquial)
LLMs are heavily trained on formal Persian literature, news websites (like BBC Persian), and Wikipedia. If you don’t specify a tone, the AI will sound like a formal news anchor (Ketabi).
- Strategy: You must explicitly demand a conversational tone if you are writing social media content or friendly emails.
- Prompt Example: “این متن را با لحن کاملاً محاورهای، صمیمی و دوستانه (مثل صحبتهای روزمره مردم در تهران) بازنویسی کن. از کلمات قلمبهسلمبه استفاده نکن.”
4.3. The “Cross-Lingual” Strategy for Complex Tasks
LLMs “think” best in English because their highest-quality logic circuits were formed on English data. For highly complex logical tasks (like math or coding architecture), prompting in Farsi can sometimes degrade the model’s intelligence.
- Strategy: Write your system instructions in English, but request the final output in Persian.
- Prompt Example: “Act as an expert data analyst. Read the following data. Perform a complex trend analysis. Output your final analysis entirely in fluent, professional Persian.“
🚀 5. Advanced Techniques
5.1. Prompt Chaining
Instead of asking for a massive task in one prompt (which confuses the model), break it into a sequence of linked prompts.
- Prompt 1: “Extract all the raw statistical facts from this 10-page document. Give me a bulleted list.”
- Prompt 2: “Great. Now, take those bullet points and organize them chronologically.”
- Prompt 3: “Perfect. Now, write a 500-word news article based ONLY on that chronological timeline.”
Intermediate thought representation and reasoning trajectories in multistep prompting architectures
5.2. Meta-Prompting (Prompting the AI to write the Prompt)
Are you struggling to write a good prompt? Make the AI do it for you.
Prompt: “I want to create a highly detailed Midjourney image prompt for a futuristic cyberpunk city. I don’t know the best photography terms to use. Please ask me 5 questions about the vibe, colors, and subjects I want. Once I answer, generate the ultimate, highly-optimized prompt for me to use.”
5.3. Self-Consistency (For Math/Logic)
Ask the model to generate multiple different reasoning paths, and then have it choose the most common answer.
Prompt: “Solve this math problem. Generate 3 completely different step-by-step ways to solve it. Then, compare the final answers. If they match, output the final answer. If they differ, re-evaluate your math.”
Multistage reasoning pipeline and self-verification in advanced reasoning models
🛠️ 6. Comprehensive Hands-on Exercises
Exercise 1: The Iterative Refinement Sandbox
Take a generic prompt and apply the CREATE framework step-by-step.
- Step 1: Ask: “Write a cover letter for a marketing job.” (Read the output. It will be boring and generic).
- Step 2 (Add Role & Context): “Act as an aggressive, confident copywriter. Write a cover letter for a Senior Growth Marketer position at a fast-paced AI startup.”
- Step 3 (Add Constraints): “Revise the previous letter. Make it exactly 3 paragraphs. Do NOT use the words ‘passionate’, ‘synergy’, or ‘team player’. Add a bold bulleted list of 3 fictional achievements in the middle.”
Exercise 2: Jailbreaking the “Format” Constraint
Ask the AI to output data in a format it usually struggles with.
- Prompt: “List the top 5 largest countries by population. Output the data strictly as a JSON array of objects. Each object should have the keys: ‘country_name’, ‘population’, and ‘capital’. Do not output any conversational text before or after the JSON block.”
TaskMatrix.AI architecture: connecting foundation models with external tools and APIs
⚠️ 7. Deep Dive: Common Pitfalls
- The “Garbage In, Garbage Out” (GIGO) Principle: If your prompt is lazy, the AI’s response will be lazy.
- Overloading the Context: Do not paste a 50-page PDF and ask “Summarize this” without telling the AI what to focus on. It will lose attention. Instead, ask “Summarize the financial risks mentioned in this document.”
- Implicit Assumptions: Assuming the model knows your company’s brand voice. It doesn’t. You must provide a 3-sentence summary of your brand voice in every prompt (or use a System Prompt/Custom Instruction).
- Ignoring Hallucination Triggers: Asking “Tell me about John Doe’s secret 2023 project” without providing the text. If it doesn’t know, it will invent it. Always add: “If the answer is not in the text provided, reply with ‘I do not know’.”
Mechanics of direct and indirect prompt injection compromising model instructions
Multimodal prompt injection attacks hidden within visual and multimodal inputs
🔗 8. Curated Resources
- Learn Prompting (Free Open Source Course) – The encyclopedia of prompting techniques.
- Anthropic’s Prompt Engineering Interactive Tutorial – Excellent for learning Claude’s specific quirks.
- OpenAI Prompt Engineering Best Practices – The official guide from the creators of ChatGPT.
← Previous | 🏠 Home | Next →