The Art of Prompting


Why Prompts Matter
If you’ve ever chatted with an AI model like ChatGPT, you’ve used a prompt. A prompt is simply the text you feed to the AI to get a response.
But here’s the twist — the way you write that prompt can completely change the answer you get.
Think of it like giving instructions to a person: if you’re vague, they might not guess what you mean. If you’re precise, you’ll get exactly what you wanted.
In the world of AI, this is even more important because models don’t “understand” the way humans do they predict the most likely response based on your input.
GIGO: Garbage In, Garbage Out
This is one of the oldest rules in computing: if your input is poor, your output will also be poor.
If you write:
Copy
explain computer
…you’ll get something vague and generic.
If you write:
Copy
Explain what a computer is to a 10-year-old using simple language and an example about video games.
…you’ll get something much better, because you gave clear instructions.
Lesson: The quality of your AI output is only as good as your input prompt.
Prompt Styling and ChatML
Prompt styling is the art of structuring prompts so they’re easy for the AI to interpret.
One formal way is ChatML, a format used to tell the AI which parts of a conversation belong to the system, the user, or the assistant.
Example:
Copy
// Example using OpenAI API
import OpenAI from "openai";
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const messages = [
{ role: "system", content: "You are a friendly AI tutor that explains in simple terms." },
{ role: "user", content: "What is machine learning?" }
];
const response = await openai.chat.completions.create({
model: "gpt-4o",
messages
});
console.log(response.choices[0].message.content);
Here:
System → Sets personality and style
User → The actual question
Assistant → The AI’s reply
By separating roles, you give the AI a cleaner context.
Types of Prompts role
(a) System Prompt
Purpose: Sets the rules, tone, style, or role for the AI throughout the conversation.
Where it fits: Usually the first message in the conversation.
Effect: Strong influence — it acts like the “ground truth” behaviour guide for the AI.
Example:
Copy
{
"role": "system",
"content": "You are a helpful and polite AI tutor that explains things step-by-step."
}
When to use:
Defining the AI’s persona
Setting response constraints (e.g., only reply in JSON)
Maintaining consistent style across the chat
(b) User Prompt
Purpose: The actual input or question from the person using the AI.
Effect: Directly tells the AI what to do or answer.
Example:
Copy
{
"role": "user",
"content": "Explain what blockchain is in simple terms."
}
When to use:
Every time the user is asking something new
Providing examples or specific instructions for the task
(c) Assistant Prompt (AI’s Response)
Purpose: The AI’s reply to the user.
Effect: Can be fed back into the conversation history to maintain context for future responses.
Example:
Copy
{
"role": "assistant",
"content": "Blockchain is like a digital ledger......." //response given to user by AI
}
When to use:
Only when sending back the AI’s answer in conversation state
For multi-turn chat sessions where context matters
(d) Developer Prompt (specialized, not always visible in public APIs)
Purpose: Gives hidden instructions to the AI from the developer, often to control formatting, safety, or content filtering without user seeing it.
Effect: Higher priority than user messages but can be overridden by system prompts in some cases.
Example:
Copy
{
"role": "developer",
"content": "Always respond in a professional tone and avoid political discussions."
}
When to use:
- In app integrations where developers want consistent behaviour without exposing rules to the user.
Visual Role Hierarchy
System Prompt → Defines core behaviour/persona
Developer Prompt → Adds hidden control for developer’s needs
User Prompt → Directs the AI on what to do
Assistant → Outputs AI’s response based on above
Types of Prompting
Now let’s go through the most common prompting techniques all beginner-friendly.
(a) Zero-Shot Prompting
Definition: Asking the AI to do a task without giving any examples.
Example:
Copy
const messages = [
{ role: "system", content: "You are a grammar checker." },
{ role: "user", content: "Correct this sentence: She go to market yesterday." }
];
Why use it?
- Fast and simple for straightforward tasks.
Drawback:
- The AI might not understand special formatting or style you want without examples.
(b) Few-Shot Prompting
Definition: Giving the AI a few examples before asking it to solve a new case.
Example:
Copy
const messages = [
{ role: "system", content: "You are a grammar corrector." },
{ role: "user", content: `
Correct the grammar in these sentences:
1. She go to market yesterday. → She went to the market yesterday.
2. They is happy today. → They are happy today.
Now correct this: He eat lunch at 2 PM every day.
` }
];
Why use it?
- Helps the AI mimic your style or format.
(c) Chain-of-Thought Prompting
Definition: Asking the AI to “think step-by-step” before answering.
Example:
Copy
const messages = [
{ role: "system", content: "You are a math tutor who explains step-by-step." },
{ role: "user", content: "What is 12 * 15 + 40 ? Show your reasoning." }
];
Output might be:
Step 1: Break 12 15 + 40 into (12 15) + (40)
Step 2: 180 + 40
Final answer: 320
Why use it?
- Great for reasoning tasks and avoiding “jumping to the answer.”
(d) Self-Consistency Prompting
Definition: Asking the AI to solve the problem multiple times internally and pick the most consistent answer.
While you can’t directly “see” this process in a single API call, you can simulate it in code:
Copy
async function selfConsistencyPrompt(prompt, runs = 5) {
const answers = [];
for (let i = 0; i < runs; i++) {
const res = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: prompt }]
});
answers.push(res.choices[0].message.content.trim());
}
// Find the most common answer
return answers.sort((a, b) =>
answers.filter(v => v === a).length - answers.filter(v => v === b).length
).pop();
}
console.log(await selfConsistencyPrompt("What is 25 * 25?"));
Why use it?
- Improves accuracy for tricky reasoning tasks.
(e) Persona-Based Prompting
Definition: Assigning the AI a personality or role.
Example:
Copy
const messages = [
{ role: "system", content: "You are a pirate who explains programming concepts in pirate slang." },
{ role: "user", content: "Explain what a variable is." }
];
Why use it?
- Great for storytelling, marketing, or making technical learning fun.
Putting It All Together: A Prompting Workflow
Here’s a step-by-step way to approach any prompting task:
Define the role → Use a system prompt to set tone and purpose.
State the goal clearly → Avoid ambiguity.
Give context/examples if needed → Few-shot for style matching.
Guide reasoning → Use chain-of-thought for complex tasks.
Refine and test → If the answer isn’t right, improve the prompt.
Beginner Tips for Better Prompts
Be Specific → “Explain AI” is vague, “Explain AI in 3 bullet points for a beginner” is better.
Add Constraints → Word count, style, tone.
Ask for the format → “Reply in JSON” or “Write as a blog post.”
Iterate → Treat prompt writing like coding — test and improve.
Subscribe to my newsletter
Read articles from Arun Chauhan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
