Prompt Engineering
What makes a good prompt?
Be specific: state the task, give context, set the role and format, and show what “good” looks like. A clear prompt shrinks the model's space of interpretations toward the answer you want.
“You are a senior editor. Rewrite this for clarity.” beats “fix this.”
Include the data it needs; don't make it guess or recall.
“Return JSON with keys x, y” — constrain the shape of the answer.
- “What's a system prompt?” — A high-priority instruction that sets persistent role/rules for the whole conversation.
Zero-shot vs few-shot prompting?
Zero-shot just asks. Few-shot includes a handful of worked examples so the model infers the pattern — this is in-context learning: it adapts with no weight updates.
- Show 2–5 input→output examples in the prompt.
- Boosts accuracy and locks in the output format.
- No examples — shortest prompt.
- Fine for simple, unambiguous tasks.
- “Why does few-shot work without training?” — In-context learning: the model recognizes the pattern from the examples at inference time.
What is chain-of-thought prompting?
Ask the model to “think step by step” before answering. Generating the reasoning out loud markedly improves accuracy on math, logic, and multi-step tasks — the intermediate tokens give it room to compute.
Self-consistency samples several chains and takes the majority answer. ReAct interleaves reasoning with tool calls. For final-answer-only outputs, you can hide the reasoning.
- “Downside of CoT?” — More tokens → higher cost and latency; reasoning can also be plausible but wrong.
What are common pitfalls?
Vague instructions, conflicting directions, overstuffed context (“lost in the middle”), and assuming the model knows private or current facts it was never given.
- “What is prompt injection?” — Malicious input that overrides your instructions; mitigate by separating system/user content and validating outputs.
- “How do you handle facts the model lacks?” — Provide them in context or use RAG — don't rely on recall.
- “How do you make outputs deterministic?” — Lower the temperature (and fix the seed where supported).