Sub topic 16
Prompting, retrieval, or fine-tuning: choosing the fix
This chapter assumes you can read basic Python and know the earlier chapters' ideas: prompts, context windows, hallucination, embeddings, retrieval-augmented generation (RAG), and test-case evaluation. It covers how to decide which lever to pull when an LLM feature gives bad results.
Start with the failure, not the technique
Teams often pick a technique first ("we need RAG" or "we should fine-tune") and then look for a problem it solves. Reverse that. Collect failing examples from your evaluation set, label why each one failed, and let the causes point to the fix.
The three levers change different things:
- Prompting changes the instructions and examples the model sees. It costs nothing to deploy and takes effect immediately.
- Retrieval changes the facts the model sees. Your code finds relevant documents and places them in the prompt at request time.
- Fine-tuning changes the model's weights by training on example input and output pairs. It changes behavior, not knowledge you can easily update.
A useful rule: prompting fixes instructions, retrieval fixes knowledge, and fine-tuning fixes habits.
Diagnosing the cause
Read ten to fifty failing outputs and ask what the model lacked.
| Symptom | Likely cause | First fix |
|---|---|---|
| Reply ignores a rule, or the format drifts | Instruction is vague, buried, or missing | Prompting |
| Wrong label on edge cases | Categories are not defined, no examples | Prompting (add definitions and examples) |
| Invents a policy, price, or product detail | Model never saw your data | Retrieval |
| Answer was correct last quarter, wrong now | Knowledge is stale | Retrieval |
| Tone or format is right only after a long prompt | Behavior is hard to describe but easy to show | Fine-tuning |
| Prompt is huge, costly, and still brittle | Too many rules to carry in every request | Fine-tuning |
A single feature often has failures from more than one row. That is normal, and it is why you count causes before you choose.
Counting causes in code
Once you have labeled failures, a few lines of code turn them into a recommendation. This sketch assumes you have labeled each failure with a cause.
from collections import Counter
FIX_FOR = {
"wrong_format": "prompting",
"ignored_instruction": "prompting",
"missing_fact": "retrieval",
"stale_fact": "retrieval",
"wrong_style": "fine-tuning",
"too_many_rules": "fine-tuning",
}
def recommend(failures):
"""failures is a list of dicts like {"id": 1, "cause": "missing_fact"}."""
fixes = Counter()
for failure in failures:
fixes[FIX_FOR.get(failure["cause"], "investigate")] += 1
return fixes.most_common()
failures = [
{"id": 1, "cause": "missing_fact"},
{"id": 2, "cause": "missing_fact"},
{"id": 3, "cause": "wrong_format"},
{"id": 4, "cause": "stale_fact"},
{"id": 5, "cause": "unknown_cause"},
]
print(recommend(failures))This prints [('retrieval', 3), ('prompting', 1), ('investigate', 1)]. Retrieval is the biggest bucket, so start there. Anything labeled investigate needs a human to look again.
Why this order: prompting, then retrieval, then fine-tuning
The usual order follows cost and reversibility.
- Prompting first. You can change a prompt in minutes and test it against your evaluation set. Most "the model is bad at this" problems turn out to be "the model was never told clearly." Add a definition of each label, state the output format, and include two or three worked examples.
- Retrieval second. If the model must answer from private, changing, or large bodies of text, no prompt can supply facts the model does not have. Retrieval adds an index to build and maintain, but it keeps knowledge in documents you can edit and delete.
- Fine-tuning last. It needs a clean training set, a training run, a new model version to deploy, and repeat work whenever the base model changes. It is the hardest lever to undo.
The order is a default, not a law. If your failures are plainly missing facts, skip straight to retrieval.
What fine-tuning is good for
Fine-tuning earns its cost in a narrow set of cases:
- Consistent style or format that is hard to describe in words but easy to show with hundreds of examples, such as a house writing voice.
- Narrow, high-volume tasks where a smaller tuned model can match a larger prompted one at lower cost and latency.
- Shortening prompts. Behavior that required a long instruction block can move into the weights, which cuts tokens per request.
- Specialized output habits, such as a domain-specific notation the base model handles poorly.
Fine-tuning is a poor way to teach facts. A tuned model may repeat training facts unreliably, cannot cite where they came from, and keeps them after the source document changes. Facts belong in retrieval.
Combining the levers
The levers are not exclusive. A mature support assistant might use all three:
- A prompt that sets role, tone, and refusal rules.
- Retrieval that supplies the current refund policy per question.
- A fine-tuned small model that classifies tickets before routing.
Add one lever at a time and re-run the same evaluation set after each change. If you change two things at once, you cannot tell which one helped or which one caused a new failure.
Common errors
- Fine-tuning before measuring. With no evaluation set, you cannot tell whether the tuned model is better. You may also have trained on the very cases you later test with.
- Retrieval with no check on retrieval quality. If the right document is not in the top results, the model cannot use it. Evaluate retrieval separately from generation: for each test question, did the correct document appear in the top k?
- Stuffing the prompt. Adding every rule you can think of makes the prompt long and contradictory. Rules that conflict get followed unpredictably.
- Training data with the same mistakes. Fine-tuning on outputs written by a prompted model copies that model's errors into the new one. Review the examples by hand.
- Ignoring maintenance. Retrieval needs reindexing when documents change. Fine-tuned models need retraining when requirements change or the base model is retired.
A quick decision checklist
Before choosing, answer these questions with evidence from your failing examples:
- Can a human do the task using only the prompt text and the supplied documents? If not, the inputs are incomplete, and no lever will help.
- Is the needed knowledge private, large, or changing? Use retrieval.
- Did you try clear instructions and three or more examples? If not, do that before anything else.
- Do you have hundreds of high-quality examples and a stable task? Fine-tuning becomes a candidate.
- Will the result be measured against the same test set before and after? If not, build it first.
Exercise
A legal-research assistant answers questions about your firm's contracts. It often cites clauses that do not exist, and its answers are fine in tone and format. Which lever do you try first, and what do you check afterward?
Show answer
Try retrieval first, with a prompt telling the model to answer only from the supplied clauses and to say so when the clauses do not cover the question. The failures are missing facts, not style or instructions. Afterward, check retrieval quality separately (does the correct contract clause appear in the top results for each test question?), then re-run the full evaluation set to see whether the invented citations dropped.
Exercise
You need a model to rewrite product descriptions in a distinctive brand voice. A long prompt with ten rules gives mixed results, and you have 800 approved descriptions. Which lever is a reasonable candidate, and why?
Show answer
Fine-tuning. The voice is hard to describe in rules but easy to show, you have a large set of approved examples, and a tuned model could shorten the prompt. Before training, try a prompt with several example descriptions and compare it to the tuned model on a held-out test set.