Prompting, RAG or fine-tuning: when do you use each?
Learning path, stage 1 of 5: How LLMs work · question 10 of 10Start with prompting. Add RAG when the model needs knowledge it doesn't have: private, fresh or large data. Fine-tune only when you need a behaviour, style or format the model can't reliably follow from instructions and examples, or when you must make a smaller, cheaper model do one narrow task well.
Decision guide
| Need | Best tool |
|---|---|
| Better instructions, format, tone | Prompting (+ few-shot examples) |
| Company docs, up-to-date facts, citations | RAG |
| Knowledge that changes often | RAG (re-index, don't retrain) |
| Consistent narrow skill at high volume, low cost | Fine-tune a smaller model |
| Strict output schema | Structured outputs or strict tool use |
| Take actions, live data | Tools or agents |
Trade-offs to mention
- Prompting: fastest to iterate, no infrastructure. Limited by context size and cost per call.
- RAG: fresh, traceable knowledge with citations. Adds retrieval quality as a new place for things to fail (chunking, ranking).
- Fine-tuning: needs curated data, an eval set and retraining when the base model changes. Bad at adding facts. Good at shaping behaviour.
- They combine: a fine-tuned model can still use RAG and tools.
The interview answer
"I'd build an eval set first, try prompting, add retrieval if failures come from missing knowledge, and only fine-tune if failures are about behaviour and the volume justifies it."
Sources
Code example
1// A tiny eval harness: the thing that should drive the choice.2interface Case { input: string; expected: string }34type Variant = (input: string) => Promise<string>;56export async function compare(cases: Case[], variants: Record<string, Variant>) {7 const scores: Record<string, number> = {};8 for (const [name, run] of Object.entries(variants)) {9 let pass = 0;10 for (const c of cases) {11 const out = await run(c.input);12 if (out.toLowerCase().includes(c.expected.toLowerCase())) pass++;13 }14 scores[name] = pass / cases.length;15 }16 return scores; // e.g. { prompt: 0.62, "prompt+rag": 0.91, "fine-tuned": 0.88 }17}1819// Pick the cheapest variant that clears your quality bar.
To run it: follow the one-time setup guide, add npm i @anthropic-ai/sdk, save the code as a .ts file and run npx tsx file.ts. Anything marked declare is a part you supply.
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the AI Agents & LLMs set.