Engineering Prompts
Bad prompt:
Write about dogs.
Good prompt:
Write a 150-word paragraph for a children's educational website explaining
why dogs make good family pets. Use simple language (age 8-10 reading level),
include 2 concrete examples, and end with a friendly call-to-action to
visit a local shelter.
The difference: explicit task, audience, format, length, content constraints, and goal.
Progress:
- [ ] Step 1: Define the goal — what exact output do you need?
- [ ] Step 2: Specify role/context the model should adopt
- [ ] Step 3: Give explicit format/structure requirements
- [ ] Step 4: Add constraints (length, tone, must-include/exclude)
- [ ] Step 5: Provide examples (few-shot) if format is non-obvious
- [ ] Step 6: Test, inspect failure modes, refine
Step 1 — Define the goal. Ask: what will the output be used for? Who reads it? What counts as success? Vague goals produce vague outputs.
Step 2 — Set role/context. "You are a senior backend engineer reviewing a PR for security issues" focuses the model's behavior far more than no role at all.
Step 3 — Structure the output. Specify format explicitly: bullet list, JSON schema, table, numbered steps, word count, headers. If you need JSON, show the exact schema and say "output only valid JSON, no commentary."
Step 4 — Constrain. State what to avoid as clearly as what to include ("do not use jargon," "do not exceed 3 sentences per point," "do not invent facts — say 'unknown' if unsure").
Step 5 — Use examples for ambiguous tasks. One or two input→output examples (few-shot) resolve ambiguity faster than more instructions. Order examples from simple to complex.
Step 6 — Iterate like debugging. Run the prompt, identify the specific failure (too long, wrong tone, hallucinated fact, wrong format), fix that one thing, re-test. Change one variable at a time.
Example 1: Vague → Precise Input: "Summarize this article." Output:
Summarize the article below in exactly 3 bullet points, each under 20 words,
focused only on actionable takeaways for a startup founder. Ignore background
history and statistics.
[article text]
Example 2: Forcing structured output Input: "Give me info about this product review's sentiment." Output:
Analyze the sentiment of the review below. Respond with ONLY valid JSON matching
this schema, no extra text:
{
"sentiment": "positive" | "neutral" | "negative",
"confidence": 0.0-1.0,
"key_phrases": string[]
}
Review: "[review text]"
Example 3: Reducing hallucination Input: "What were the main causes of the 2023 event?" Output:
Answer based only on the context provided below. If the context does not contain
the answer, respond exactly: "Not enough information in the provided context."
Do not use outside knowledge.
Context: [...]
Question: What were the main causes of the event described?
Example 4: Few-shot for consistent format
Convert each product description into a one-line ad slogan.
Description: "Durable waterproof hiking boots with memory foam insole."
Slogan: "Step anywhere. Stay dry. Stay comfortable."
Description: "Wireless earbuds with 30-hour battery life."
Slogan: "Days of sound. Zero wires."
Description: "Organic cold-pressed olive oil from Tuscany."
Slogan:
- Front-load the instruction, put variable data last. Model attention favors instructions stated before the content to process.
- Be literal. Models follow instructions more like a strict API than a human colleague — ambiguity gets resolved unpredictably.
- Specify negative space. "Don't include a preamble," "don't add disclaimers," "don't explain your reasoning" — otherwise models default to verbose hedging.
- Use delimiters (triple quotes, XML tags, markdown headers) to separate instructions from data, especially with long inputs.
- Ask for step-by-step reasoning before the final answer on complex/logical tasks ("think step by step, then give the final answer on the last line labeled ANSWER:").
- Pin output length explicitly ("exactly 5 items," "under 100 words") — models drift long by default.
- Test edge cases: empty input, contradictory instructions, adversarial input — these reveal prompt fragility.
- Version and store prompts like code when used in production; small wording changes can shift output quality significantly.
- Stacking too many tasks in one prompt. "Summarize, translate, and critique this" in one shot degrades quality on all three — split into separate calls when possible.
- Assuming the model knows unstated context. If the audience, tone, or purpose isn't in the prompt, it isn't known.
- Over-relying on "please be accurate/creative/concise" as a vague adjective instead of giving a concrete, checkable constraint.
- Not providing a fallback for uncertainty, leading to confident hallucination instead of "I don't know."
- Changing multiple variables at once when iterating, making it impossible to tell which edit fixed or broke the output.
- Ignoring output format validation. If you need JSON/structured output, always parse-check it — don't assume compliance.