A prompt is the instruction you give a Large Language Model. The same model can give a vague answer or an excellent one depending on how you ask. Prompt engineering is the skill of writing clear, testable instructions so the output is accurate, consistent and in the format you need.
The 5 parts of a good prompt
- Role: who the model should act as.
- Task: exactly what to do.
- Context: background the model cannot guess.
- Constraints: length, tone, what to avoid.
- Output format: bullet list, table, JSON, code.
Before and after
A weak prompt:
Write about testing.A strong prompt:
You are a senior QA engineer mentoring freshers.
Explain the difference between smoke testing and regression testing.
Audience: final-year B.Tech students with no job experience.
Use one real e-commerce example for each.
Keep it under 150 words and end with one interview question.The second prompt fixes the audience, scope, length and format, so the answer is useful the first time.
Technique 1: Few-shot examples
Show the model 2 or 3 examples of input and output. It copies the pattern.
Classify the support ticket as BILLING, TECHNICAL or OTHER.
Ticket: "I was charged twice this month" -> BILLING
Ticket: "The app crashes when I upload a photo" -> TECHNICAL
Ticket: "Do you have an office in Pune?" -> OTHER
Ticket: "Payment failed but money was deducted" ->Technique 2: Ask for step-by-step reasoning
For maths, logic or debugging, ask the model to work through the problem before giving the final answer. This usually improves accuracy.
A course costs Rs 40,000. There is a 15% discount, then 18% GST on the discounted price.
Work it out step by step, then give the final amount on the last line as: TOTAL = <amount>.Technique 3: Structured output
When code will read the answer, ask for JSON and describe the exact keys.
Extract details from the message below. Reply with JSON only, no extra text:
{"name": string, "phone": string, "course": string | null}
Message: "Hi, I am Ravi, 9876543210, interested in the Playwright course"Many APIs also support a JSON or schema mode that guarantees valid JSON; use it in production.
Technique 4: Give the model a way out
Models try to answer even when they should not. Add an explicit fallback.
Answer only from the policy text below. If the policy does not cover it, reply exactly: "Not covered in the policy."Prompting checklist
- Be specific about audience, length and format.
- Put long reference text between clear markers such as
"""or XML-style tags. - Prefer positive instructions ("use simple words") over only negative ones.
- Test the prompt on 10 or more real inputs, not just one.
- Version your prompts like code, and note what changed.
Interview questions
| Question | Short answer |
|---|---|
| Zero-shot vs few-shot? | Zero-shot gives only instructions; few-shot adds worked examples. |
| What is temperature? | A setting that controls randomness: low for facts and code, higher for creative text. |
| What is a system prompt? | Hidden top-level instructions that set the model's role and rules for the whole conversation. |
| How do you test prompts? | Keep an evaluation set of inputs with expected outputs and compare versions. |
Next steps
Prompting is the first layer of building AI applications. Continue with what RAG is, or learn it end to end in our Generative AI Engineering course.
