Prompt Pitfalls
Most prompt problems fall into a handful of recurring patterns. Recognising them saves hours of trial and error. This lesson lists the common pitfalls, with small tools that catch some of them automatically.
1. Ambiguity
"Summarise this briefly" — one sentence? One paragraph? For whom? The model will choose, and its choice may change between runs. Fix: concrete limits and an audience.
2. Conflicting instructions
Long prompts that grew over time often contain rules that contradict each other ("be detailed" … "answer in one sentence"). The model has to guess which wins. A quick automated check can catch obvious conflicts:
CONFLICTS = [
({"detailed", "thorough", "in depth"}, {"one sentence", "brief", "very short"}),
({"formal"}, {"casual", "slang"}),
({"json only", "only json"}, {"explain your answer", "add a comment"}),
]
def find_conflicts(prompt):
low = prompt.lower()
found = []
for side_a, side_b in CONFLICTS:
a = sorted(p for p in side_a if p in low)
b = sorted(p for p in side_b if p in low)
if a and b:
found.append(f"{a[0]!r} vs {b[0]!r}")
return found
prompt = """You are a formal assistant. Give detailed, thorough answers.
Users like casual language. Keep every answer to one sentence.
Reply with JSON only."""
for c in find_conflicts(prompt):
print("conflict:", c)conflict: 'detailed' vs 'one sentence'
conflict: 'formal' vs 'casual'
Fix: decide the priority yourself and state it ("Prefer brevity: at most 3 sentences, even for complex questions").
3. Missing context
The model only knows what is in its training data and in the prompt. "Is this within our refund policy?" fails if the policy isn't in the prompt — the model may answer confidently from typical policies instead. Fix: include the facts, or retrieve them (RAG).
4. Asking the model to do what code does better
Counting characters, exact arithmetic on large numbers, sorting long lists, checking dates — LLMs often get these slightly wrong, and slightly wrong is worse than obviously wrong. Do these in code and give the model the result, or give the model a tool (see Tool Use).
text = "The quick brown fox jumps over the lazy dog"
facts = {
"characters": len(text),
"words": len(text.split()),
"letter 'o' count": text.count("o"),
"sorted words": sorted(text.lower().split()),
}
for k, v in facts.items():
print(f"{k}: {v}")characters: 43
words: 9
letter 'o' count: 4
sorted words: ['brown', 'dog', 'fox', 'jumps', 'lazy', 'over', 'quick', 'the', 'the']
These are exact in two lines of Python. An LLM asked the same questions would sometimes be off by one — partly because, as you saw in Tokens, it doesn't see individual letters.
5. Leading questions
"Why is solution A better than B?" presupposes the answer; models tend to agree with the framing they are given (sometimes called sycophancy). Fix: ask neutrally — "Compare A and B for this use case. Which fits better, and why?"
6. Format drift in long outputs
A list of 50 items starts in the requested format and drifts. Fix: smaller batches, explicit examples of the format, and validation in code (see Structured Output).
7. Prompt sensitivity and over-fitting
Small wording changes can change results. If you tune a prompt on three examples until they look perfect, it may be worse on everything else. Fix: test each change on a fixed set of varied inputs and look at the overall score, not one favourite example.
# Pretend evaluation results: did each prompt version answer each test input correctly?
results = {
"v1": [1, 0, 1, 1, 0, 1, 0, 1, 1, 0],
"v2 (tuned on inputs 1-3)": [1, 1, 1, 0, 0, 1, 0, 1, 0, 0],
"v3 (clearer rules)": [1, 1, 1, 1, 0, 1, 1, 1, 1, 0],
}
for name, r in results.items():
print(f"{name:<25} first 3: {sum(r[:3])}/3 all 10: {sum(r)}/10")v1 first 3: 2/3 all 10: 6/10
v2 (tuned on inputs 1-3) first 3: 3/3 all 10: 5/10
v3 (clearer rules) first 3: 3/3 all 10: 8/10
v2 looks perfect on the three inputs it was tuned on but is actually worse overall than v1. Only the full test set reveals it.
8. Putting secrets or untrusted text in the wrong place
Secrets in a system prompt can leak; untrusted text (web pages, emails, user uploads) inserted without delimiters can contain instructions that hijack the model (prompt injection). Fix: no secrets in prompts, clear delimiters, and limited permissions for anything the model can trigger.
Checklist
| Check | Question to ask |
|---|---|
| Task | Would a new colleague know exactly what to produce? |
| Context | Are all needed facts in the prompt? |
| Format | Is the output shape specified (and validated)? |
| Priorities | If two rules clash, does the prompt say which wins? |
| Fallback | What should the model do if it can't answer? |
| Tests | Has the prompt been tried on varied, realistic inputs? |
| Safety | Are untrusted inputs delimited, and are secrets kept out? |
Test yourself
A prompt says both 'be thorough' and 'answer in one sentence'. What is the best fix?
- Add more emphasis to both rules
- Decide which matters more and state the priority explicitly
- Raise the temperature
- Remove the system prompt
A prompt version scores perfectly on the 3 inputs you tuned it on. What should you do before shipping it?
- Ship it immediately
- Test it on a larger, varied set of inputs and compare the overall score
- Add more exclamation marks
- Delete the old version
Which task is better done in code than by an LLM?
- Rewriting a paragraph politely
- Counting the exact number of characters in a string
- Brainstorming product names
- Summarising an email