Prompt Engineering Basics
The Art and Science of Prompting
Prompt engineering is the practice of crafting instructions to LLMs to reliably produce high-quality, consistent outputs for a specific task.
When you build an AI automation system, the prompt is your code. A poorly written prompt produces unpredictable, low-quality outputs. A well-engineered prompt can unlock remarkable capability from the same underlying model.
This is not just academic -- in production AI systems, prompt quality is often the single biggest factor in whether the system works reliably.
The Anatomy of a Prompt
A production prompt typically has several components:
1. System Prompt
Sets the context, role, and constraints for the entire interaction. Always comes first.
You are a customer support agent for Paystack, a Nigerian payment infrastructure company.
Your role is to help customers resolve issues with payments, accounts, and integrations.
Always be professional, concise, and empathetic.
If a question is outside your knowledge, say so and offer to escalate.
Respond only in the language the customer uses.
2. Task Instructions
Clearly describe what you want the model to do.
Classify the following customer message into exactly one of these categories:
- BILLING: Questions about charges, invoices, or refunds
- TECHNICAL: Integration issues, API errors, code problems
- ACCOUNT: Login, settings, KYC, or account management
- GENERAL: Other questions or greetings
3. Output Format Instructions
Tell the model exactly how to structure its response.
Respond with a JSON object in this exact format:
{
"category": "<one of the categories above>",
"confidence": "<HIGH, MEDIUM, or LOW>",
"reasoning": "<one sentence explaining your classification>"
}
Do not include any text outside the JSON object.
4. The Input
The actual data you want the model to process.
Customer message: "My webhook is not receiving events after the integration. I checked the endpoint and it is accessible."
Core Prompting Principles
Be Specific
Vague prompts produce vague outputs. The more specific your instructions, the more predictable the results.
| Vague | Specific |
|---|---|
| "Summarise this" | "Summarise this in 3 bullet points, each under 20 words" |
| "Write a response" | "Write a professional, empathetic 2-paragraph response" |
| "Extract the information" | "Extract the company name, phone number, and email address. If any are missing, use null" |
Assign a Role
Telling the model who it is improves output quality significantly.
You are an expert Nigerian tax consultant with 15 years of experience advising SMEs.
Provide Examples (Few-Shot Prompting)
One of the most powerful techniques: show the model examples of good inputs and outputs before giving it the real task.
Classify customer sentiment. Examples:
Message: "This app is amazing, saved me so much time!"
Sentiment: POSITIVE
Message: "I have been waiting 3 days for a response. This is unacceptable."
Sentiment: NEGATIVE
Message: "When does the offer expire?"
Sentiment: NEUTRAL
Now classify:
Message: "The new update is clean but I wish the dark mode was available."
Chain of Thought
For complex reasoning tasks, instruct the model to think step by step before giving its final answer.
Analyse this contract clause and determine if it is unusual or high-risk.
Think through it step by step:
1. What does this clause say in plain language?
2. Is this standard practice for this type of contract?
3. What are the potential risks or implications?
4. What is your overall assessment?
Use Delimiters
When including external content (like a document to summarise), use delimiters to clearly separate it from your instructions.
Summarise the following article in 3 bullet points.
---ARTICLE START---
[article text here]
---ARTICLE END---
Common Prompt Engineering Mistakes
1. No output format specified: The model will choose its own format, which will vary and break downstream parsing.
2. Ambiguous instructions: "Be concise" means different things to different people and different prompts. Say "respond in 2 sentences" instead.
3. Too many instructions: If you ask for 15 things at once, the model will often miss some. For complex tasks, break them into smaller steps.
4. No examples for edge cases: What should the model do when the input is ambiguous? Provide examples of edge cases.
5. Ignoring the system prompt: The system prompt is the most reliable place to set persistent instructions. Do not rely on per-request instructions for core behaviour.
Testing and Iterating on Prompts
Prompt engineering is empirical. You cannot just reason about what will work -- you need to test.
A good prompt testing workflow:
- Define a set of diverse test cases (including edge cases)
- Run all test cases through the prompt
- Evaluate outputs against your quality criteria
- Identify patterns in failures
- Update the prompt to address failures
- Re-run all test cases to verify improvement and check for regressions
This is called prompt evaluation and is a critical part of building reliable AI automation systems. Some teams maintain spreadsheets of test cases. Others use dedicated evaluation frameworks.
Prompt Templates in Code
In a real AI automation system, prompts are usually templates with variables filled in at runtime:
function buildClassificationPrompt(customerMessage) {
return `You are a customer support classifier for Paystack.
Classify the following message into one of: BILLING, TECHNICAL, ACCOUNT, GENERAL.
Respond with JSON: {"category": "...", "confidence": "HIGH|MEDIUM|LOW"}
Customer message: ${customerMessage}`;
}
const prompt = buildClassificationPrompt("My webhook stopped working after the update");
// Then call the LLM API with this prompt
This approach makes prompts maintainable, testable, and easy to update across the entire system when improvements are made.
Try it yourself
Key Takeaways
- Prompt engineering is the practice of crafting instructions to LLMs to produce reliable, high-quality outputs for a specific task.
- A production prompt typically includes a system prompt (role and constraints), task instructions, output format, and the actual input.
- Few-shot prompting (providing examples) is one of the most powerful techniques for improving output consistency.
- Chain-of-thought prompting instructs the model to reason step by step, improving performance on complex tasks.
- Prompts should be tested systematically across diverse test cases including edge cases, and iterated on based on failure patterns.
Quick Quiz
1.What is few-shot prompting?
2.Why should you always specify an output format in production prompts?
3.What is chain-of-thought prompting?
4.What is the system prompt in an LLM API call?
Ready to go further?
CareerEx gives you structured 12-week training, live classes every Saturday and Sunday, real tutor feedback, and a certificate. Join the next cohort.
Join CareerEx