Master the art and science of communicating with AI. Write prompts that get results every time — for code, data, content, and automation.
Prompt engineering is the skill of writing precise instructions for AI language models to get the best possible output. As AI tools become part of every tech workflow, the ability to communicate with them effectively is now a professional skill as valuable as coding.
A Large Language Model (LLM) is trained on billions of text documents. When you send a prompt, it predicts the most statistically likely continuation based on patterns in its training. It does not "think" — it pattern-matches at massive scale.
You write a prompt → the model responds → you refine based on output → repeat. Prompt engineering minimises the number of iterations needed to get what you want.
Most prompts that produce poor results are missing one or more of these five elements. Include each deliberately and your output quality will improve dramatically.
AI models have been trained on billions of lines of code across every major programming language. When prompted correctly they can write, explain, debug, review, and refactor code with impressive accuracy. The key is directing them effectively.
Include: language, specific task, input/output types, edge cases to handle, constraints, and desired format.
Write a JavaScript function validateEmail(email) that: - Returns true if the string is valid email format - Returns false otherwise - Handles: empty string, no @ symbol, no domain - Include JSDoc comments - Do NOT use external libraries
Debug this Python code. Error: TypeError: unsupported operand type(s) for +: int and str Expected: sum of all numbers in list Actual: crashes on line 5 Environment: Python 3.11 on Ubuntu 22 [paste your code here]
Review this code for: 1. Security vulnerabilities (SQL injection, XSS, CSRF) 2. Performance bottlenecks 3. Error handling gaps 4. Code readability Return as a numbered list. Label each: Critical / Major / Minor
Explain this code to me as if I am a junior developer. Describe what each section does and why. Flag any potential problems or anti-patterns. [paste code]
Asking the model to reason step by step before answering significantly improves accuracy on reasoning, math, and logic tasks. Simply add: "Think step by step before answering."
Calculate the total cost including 7.5% VAT and 15% service charge for a bill of 45,000 Naira. Think step by step before giving the final answer.
Break complex tasks into a sequence of prompts where the output of one becomes the input of the next. More reliable than one giant prompt.
Ask for multiple approaches then select the best: "Give me 3 different approaches to solving this, then recommend the best one and explain why."
Ask AI to write your prompt: "I want an AI to [describe your goal]. Write me the best possible prompt to achieve this."
Tell the model what NOT to do: "Do not use jargon", "Do not exceed 200 words", "Do not use passive voice", "Do not suggest frameworks I have not mentioned."
When using AI APIs directly you have two prompt types:
const response = await fetch("https://api.anthropic.com/v1/messages", {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": YOUR_API_KEY,
"anthropic-version": "2023-06-01"
},
body: JSON.stringify({
model: "claude-opus-4-5",
max_tokens: 1024,
system: "You are a helpful assistant for SWAL Learn.",
messages: [{ role: "user", content: "Your question here" }]
})
});
With the right prompts you can extract structured data from unstructured text, classify content at scale, summarise large documents, and generate realistic test data — without complex parsing code.
Extract these fields from the invoice text below. Return ONLY a valid JSON object with no additional text: - vendor_name (string) - invoice_number (string) - total_amount (number, in Naira) - due_date (string, YYYY-MM-DD format) Invoice text: [paste here]
Classify each message as: BILLING / TECHNICAL / ACCOUNT / COMPLAINT / OTHER
Return a JSON array. Each item: {id, category, confidence: high/medium/low}
Messages:
1. [ID:001] "I was charged twice this month"
2. [ID:002] "App crashes when I upload a file over 5MB"
Summarise this document in exactly 3 bullet points. One sentence per bullet point maximum. Focus only on actionable insights, not background context. [document]
Generate 10 realistic Nigerian customer records for testing. Return as a JSON array. Each record: firstName, lastName, email, phone (080/081/070/090 prefix), state (Lagos/Abuja/Rivers/Kano/Delta), year joined (2023-2025) Make names authentically Nigerian. No duplicate emails.
AI models excel at content creation when given clear direction. The key is specificity — vague prompts produce generic content. Detailed prompts with audience, tone, format, and purpose produce content that actually serves your goals.
Before any content prompt, define:
Rewrite the following text in a warm and encouraging tone while keeping all factual content identical. [original text]
This explanation was written for developers. Rewrite it for a non-technical CEO audience. Replace all technical jargon with plain business language. Focus on business impact not technical implementation. [original text]
Our brand voice is: confident but not arrogant, simple but not simplistic, warm but professional. We never use jargon or corporate buzzwords. We speak to African entrepreneurs in their language. Rewrite this to match our voice: [text]
A prompt that works perfectly once may fail unpredictably on different inputs. Before deploying any AI-powered feature in production, you must test prompts systematically across a range of inputs.
Change one element at a time. If you change role, format, and examples simultaneously, you cannot know which change caused an improvement. Version control your prompts like code.
Run two prompt versions simultaneously with different user segments and measure outcomes: user satisfaction, task completion, error rate, time-to-completion.
Prompt injection is an attack where malicious user input overrides or bypasses the system prompt instructions, causing the AI to behave in unintended ways — revealing confidential information, ignoring safety rules, or taking harmful actions.
Moving from casual AI use to professional prompt engineering means treating prompts like code: version controlled, documented, tested, and maintained systematically.
Organise tested prompts by category in your codebase:
const buildEmailPrompt = (customerName, issue, tone) => `
You are a customer support specialist for PayFast.
Write a response to ${customerName}'s complaint about: ${issue}
Tone: ${tone}
Under 150 words. End with a specific resolution timeline.
`;
Store in a prompts/ folder. Descriptive names: customer-complaint-response-v3.txt. Commit with meaningful messages. Roll back when a new version underperforms.