Sub topic 12
A decision framework
This chapter assumes you can call a chat-style LLM API, read Python, and know what embeddings and a context window are. Earlier chapters covered the three levers and how to diagnose a problem. Here you combine those pieces into one repeatable process.
The order matters
The three approaches differ in cost and reversibility. Prompting changes in seconds and costs almost nothing. RAG needs an index and a retrieval step. Fine-tuning needs curated training data, a training run, and a model you must keep up to date. So you try the cheapest lever first and move on only when your evaluation set shows it is not enough.
Four questions
Ask these in order.
- Do you have an evaluation set and a baseline? Without one, you cannot tell whether any change helped. Build it first.
- Does a well-written prompt with a few examples pass? If yes, stop. Extra machinery only adds maintenance.
- Do the failures come from missing knowledge? Examples are private documents, facts that change often, or answers that need a source. Add RAG.
- Do the failures come from wrong behavior? Examples are an inconsistent format, a tone that drifts, or a task pattern the model keeps getting wrong even when it has the facts. Consider fine-tuning.
Both of the last two can be true at once. In that case you combine approaches.
The rule as code
The same logic fits in a small function. It is a simplification, but writing it down makes your assumptions visible.
def suggest_approach(needs_private_or_fresh_facts, needs_consistent_style_or_format, prompt_baseline_passes):
if prompt_baseline_passes:
return ["prompting"]
approaches = ["prompting"]
if needs_private_or_fresh_facts:
approaches.append("rag")
if needs_consistent_style_or_format:
approaches.append("fine-tuning")
return approaches
print(suggest_approach(True, False, False)) # ['prompting', 'rag']
print(suggest_approach(True, True, False)) # ['prompting', 'rag', 'fine-tuning']
print(suggest_approach(False, False, True)) # ['prompting']Prompting always stays in the list. Even a fine-tuned or retrieval-based system still needs instructions.
Applying it to cases
| Situation | Likely choice | Reason |
|---|---|---|
| Classify tickets into three labels | Prompting with few-shot examples | Behavior is simple and the examples fit in the prompt |
| Answer questions about internal policy documents | RAG | The model lacks the facts, and they change |
| Write release notes in a strict house style across thousands of requests | Fine-tuning | Long style instructions are costly and unreliable |
| Support bot that cites current product docs in a fixed tone | RAG plus fine-tuning | Both a knowledge gap and a behavior gap |
Common mistakes
- Fine-tuning to add facts. Training does not reliably store facts, and the facts go stale. Use RAG for knowledge.
- Using RAG to fix style. Retrieved passages do not change how the model writes.
- Skipping the baseline. You then cannot show that the added complexity paid off.
- Judging by a few hand-picked examples. Use a set that includes hard and ordinary cases.
Exercise
Your assistant answers questions about a product whose documentation is updated weekly. Answers are fluent and in the right tone, but often cite outdated features. The prompt baseline fails. Which lever do you add next, and why not fine-tuning?
Show answer
Add RAG. The failures are a knowledge gap, because the facts change weekly and the tone is already correct. Fine-tuning would bake facts into the weights, which go stale and would need retraining after every update. RAG reads the current documents at query time.
Exercise
After adding RAG, answers contain the right facts but the format varies between runs, and your evaluation shows 30% of outputs break the required JSON schema. What do you try first, and what do you try if that fails?
Show answer
First try stricter instructions and few-shot examples of the exact schema, then re-run the evaluation. If the failure rate stays too high, collect input and output pairs that show the correct format and fine-tune, keeping RAG for the facts.