Prompt Engineering Basics
Prompt engineering comes down to four habits: be specific about what you want, show examples of good output (few-shot), ask for a defined structure, and iterate based on failures. Most bad LLM output traces back to a vague prompt, not a bad model.
Why Does Being Specific Matter So Much?
The model can't read your mind — every constraint you leave out (audience, length, format, what to exclude) is a decision it makes for you, usually wrong. State the task, the context, the audience, and the output format explicitly, and say what to do in edge cases ("if the review mentions no product, output 'unknown'").
What Is Few-Shot Prompting?
Few-shot prompting means including 2-5 worked examples of input and desired output in the prompt; the model imitates the pattern far more reliably than it follows a written description of it. Pick examples that cover your tricky cases, not just the easy ones.
Classify the sentiment of each review as positive, negative, or mixed.
Review: "Battery lasts forever, camera is mediocre."
Sentiment: mixed
Review: "Broke after two days."
Sentiment: negative
Review: "Does exactly what it promises."
Sentiment: positive
Review: "Great screen but the speakers are terrible."
Sentiment:
Why Ask for Structured Output?
Requesting a specific structure — JSON with named keys, a markdown table, numbered steps — makes output parseable by code and forces the model to cover every field instead of rambling. If a field can be missing, define what goes there (null, "unknown") so you don't get invented values.
How Should You Iterate on a Prompt?
Treat prompts like code: keep a handful of test inputs, run them after every edit, and fix failures by adding a rule or an example that targets the specific mistake. Change one thing at a time so you know what helped.
What Does a Before-and-After Prompt Look Like?
Here is the same task written vaguely, then rewritten using all four rules.
# Before (vague)
Summarize this customer feedback.
# After (specific, structured, edge cases handled)
Summarize the customer feedback below for a product manager.
Return JSON with exactly these keys:
"top_complaints": up to 3 issues, most frequent first
"top_praise": up to 3 strengths
"urgent": true if any message mentions a safety issue or legal threat
If the feedback contains no complaints, use an empty list.
Feedback:
<paste feedback here>
Common Pitfalls
- Overstuffed prompts: ten pages of contradictory rules dilute the important ones. Keep instructions short and prioritized.
- Biased few-shot examples: if all your examples are positive reviews, the model over-predicts positive. Balance them.
- Judging on one input: a prompt that works once can fail on the next input. Always test on several varied cases.
- Prompting around a knowledge gap: no phrasing makes the model know your internal docs — that's a retrieval problem, not a prompting problem (see RAG).
Pro Tip: When the model keeps making the same mistake, don't write another rule against it — paste the failing input into your prompt as a few-shot example with the correct output. One good example beats three paragraphs of instructions.
← Back to AI & ML Tips