Mastering Prompt Engineering : a beginner Guide


Introduction: Why Prompt Engineering Matters
Have you ever heard the phrase "Garbage In, Garbage Out" (GIGO)? If you put rubbish into something, you're gonna get rubbish out. It simply means that if you feed poor-quality input into a system, you’ll get poor-quality output. This principle is crucial in Artificial Intelligence (AI), especially when working with Large Language Models (LLMS) like Chatgpt, Gemini, or Claude. Even the smartest AI can only give you great results if you ask the right way.
Think of it this way: if you ask your smart AI an unclear or confusing question, it will likely give you an unclear or incorrect answer. However, if you carefully word your question (known as a "prompt"), you can get much better answers. That's where "Prompt Engineering" comes in—it's the art of communicating with AI smartly and clearly.
What is a prompt?
A prompt is just a simple bit of text you type in to tell the AI what you want it to do . Think of it like giving instructions to a very smart assistant—the clearer you explain things, the better job they can do for you.
Example of a Bad vs. Good Prompt
❌ Bad Prompt:
"Tonight I have a date with my girlfriend, what should I wear?”
(Too unclear—no details about the setting, style preferences, or formality level.)
✅ Good Prompt:
" Act as a personal stylist. Tonight I have a candlelight dinner date with my girlfriend at a nice but not super fancy Italian restaurant. It will be a little bit dark inside. I usually like to wear smart casual clothes. What kind of outfit would you suggest?"
(Specific: mentions location, lighting, preferred style, and avoids overly formal/casual extremes.)
What is Prompt Engineering?
Prompt engineering is the skill of creating clear questions or instructions, called prompts, to help AI give the best and most helpful answers.
Key Concept of Prompt Engineering
Alpaca (Simplified Instruction Training)
A team at Stanford developed a small AI named Alpaca by training it with many good prompt–response examples, enabling it to follow instructions effectively without needing to be as large as GPT. You use an Instruction + Input + Response structure.
For more details about Alpaca, click here.
Example
prompt = """
### Instruction:
Solve the word problem provided by the user.
### Input:
Sarah has 5 apples. She buys 3 more apples. How many apples does Sarah have now?
### Response:
Sarah started with 5 apples and bought 3 more.
5 + 3 = 8.
Sarah now has 8 apples.
"""
2. ISNT (Instruct Supervised and Noisy Tuning)
ISNT is a way Meta (like Facebook) trains AI. Instead of only showing it perfect examples, they also show it messy and confusing instructions. This makes the AI tougher and smarter because it learns to figure things out even when your instructions aren't perfect.
Example
prompt = """
<<SYS>>
You are a motivational coach who always speaks in rhymes.
<</SYS>>
### Instruction:
Give me tips to stay focused while studying.
### Response:
Keep your phone far and sit real tight,
Focus on goals and hold them tight!
Take small breaks, but not too long,
Study steady, you can't go wrong!
"""
ChatML (Chat Message Language by OpenAI)
OpenAI made a chat style called ChatML for models like GPT-4. Instead of just saying "do this," it organizes conversations by who's talking: the system (like the AI's core), the user (you), and the assistant (the AI's reply). Everything is tagged so the AI knows who said what and how to respond in the conversation.
prompt = [
{"role": "system", "content": "You are a motivational coach who always speaks in rhymes."},
{"role": "user", "content": "Give me tips to stay focused while studying."},
{"role": "assistant", "content": "Keep your phone far and sit real tight,\nFocus on goals and hold them tight!\nTake small breaks, but not too long,\nStudy steady, you can't go wrong!"}
]
Key Technique in Prompt Engineering
Zero-shot Prompting
Zero-shot means you just ask the AI to do something without giving any examples.
Example:
"Translate 'Hello' to Nepali."
→ Output: "Namaste"
Few-shot Prompting
You provide a few examples to help the AI understand the pattern.
Example:
prompt = """
Example 1: 'What is the capital of France?' → 'Paris'
Example 2: 'What is the capital of Germany?' → 'Berlin'
Now, 'What is the capital of Italy?'
"""
Output: 'Rome'
Chain of Thought (Cot) prompting
Instead of asking for a direct answer, you encourage the AI to explain its reasoning step-by-step. This improves accuracy for complex problems. It’s all about guiding the model to think step by step.
Example:
This leads to more logical, accurate answers
4. Self-Consistency Prompting
Sometimes, the AI might give different answers to the same question. Self-consistency involves generating multiple responses and choosing the most common or best one. Self-consistency is about creating various reasoning paths and selecting the most consistent answer.
Example
Instruction-Based Prompting
Give direct commands to the AI to follow a specific format.
Example:
Prompt:
*"Write a 100-word summary of the French Revolution in bullet points."*
Direct Answer Prompting
Sometimes you don't want storytelling or step-by-step reasoning.
You want the direct answer only.Prompt: "What's 15% of 200? Only give me the final number." → Answer: 30.
Persona-based Prompting
Persona prompting asks the AI to "act" like someone.
Prompt: "Pretend you're a personal fitness coach. Give me a beginner's exercise plan."
The AI takes on a "character" to guide its style and tone.
Role-playing Prompting
Similar to persona-based, but often more interactive.
Prompt: "You are a restaurant waiter. Help me choose a dish based on my mood: tired and craving comfort food."
The AI will "play along" with the role, making the interaction feel natural.
Contextual Prompting
Contextual prompting means you give the AI extra background so it can give more meaningful answers.
Prompt: "You are helping a college freshman who is studying biology and struggling with genetics. Explain Mendel’s experiments."
Here, you're setting the scene so the AI adjusts the explanation accordingly.
Multimodal prompting
It means using multiple types of inputs — like text + image together.
You upload a photo of a flower and ask: "Describe this flower and suggest a scientific classification."
Conclusion
Prompt engineering is like learning to communicate effectively with AI. The better your prompts, the better the results. Start with simple techniques like few-shot prompting and Chain of Thought, then experiment with personas, role-playing, and multimodal inputs.
Subscribe to my newsletter
Read articles from Mahesh Kunwar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Mahesh Kunwar
Mahesh Kunwar
I am Mahesh Kunwar, a dedicated web developer specializing in the MERN stack—MongoDB, Express.js, React.js, and Node.js. Passionate about creating user-friendly and efficient applications, I enjoy solving complex problems through clean and scalable code. My journey in web development has been shaped by hands-on projects that have enhanced my problem-solving skills and deepened my technical expertise. With a dynamic mindset and a strong enthusiasm for technology, I am always eager to learn new technologies and adapt to emerging trends in the fast-evolving tech landscape. A quick learner, I thrive in collaborative environments, constantly seeking opportunities to contribute, grow, and innovate. My goal is to leverage my skills to develop impactful software solutions that enhance user experiences and drive meaningful progress.