Prompt engineering vs RAG vs fine-tuning: how to choose the right approach for your LLM app
A practical decision guide for AI engineers: what prompt engineering, retrieval-augmented generation (RAG) and fine-tuning each fix, what they cost, how to evaluate them, and the order to try them in. With a decision diagram, a decision table, a small evaluation harness and two worked examples.
Almost every team building an LLM app hits the same fork in the road. The answers are a bit wrong, a bit vague or a bit off-brand, and someone asks: should we fix the prompt, add RAG, or fine-tune?
They are not competing options. They fix different problems, and picking the wrong one can cost weeks. This guide explains what each one actually changes, gives you a decision diagram and table, shows a tiny evaluation harness you can copy, and walks through the order we follow when building LLM apps.
Key takeaways
- Prompt engineering changes the instructions. Cheapest, fastest, always first.
- RAG changes the knowledge the model sees at answer time. Use it for private, fresh or citable facts.
- Fine-tuning changes the behaviour baked into the model. Use it for format, style and narrow repeated tasks.
- None of them works without an evaluation set. Measure before and after every change.
- Many production apps end up as prompt + RAG, with fine-tuning added only where the numbers justify it.
First, name the failure
Before choosing a technique, write down how the app is failing. Pull 30 to 50 real or realistic questions, run them, and label every bad answer with one of these:
| Failure | Example | Usually fixed by |
|---|---|---|
| Didn't follow instructions | Ignored "answer in 3 bullets" | Prompt engineering |
| Didn't know the fact | Wrong refund policy, old price | RAG |
| Made something up | Invented a clause that isn't in the contract | RAG + grounding rules + evaluation |
| Wrong format or tone, consistently | JSON breaks, tone too casual | Prompting first, then fine-tuning |
| Too slow or too costly at scale | Big model for a simple classification | Smaller model, possibly fine-tuned |
This labelled set becomes your golden dataset, the yardstick for every change that follows. Our LLM evaluation and guardrails checklist shows how to build one properly, including negative cases the model should refuse.
Option 1: prompt engineering
What it changes: the instructions, examples and structure you send with each request.
Good for: clear task definitions, output formats, tone, step-by-step reasoning instructions, a few worked examples (few-shot), and refusing out-of-scope questions.
Costs: almost nothing to try. Longer prompts add tokens to every call, so very long system prompts do show up on the bill at scale. Provider features such as prompt caching can reduce that cost for a fixed prefix; check your provider's documentation for how it is priced.
Limits: a prompt can't give the model facts it never saw, and it can't hold thousands of documents.
Prompt habits that pay off
- Put the role, the task, the rules and the output format in separate, clearly labelled sections.
- Give two or three examples of a good answer, including one edge case.
- Use the model's structured-output or JSON mode when you need machine-readable results.
- Tell the model what to do when it doesn't know ("say you don't know and suggest who to ask").
- Version your prompts like code and re-run the golden dataset after every edit.
A tiny evaluation harness
You don't need a platform to start measuring. A JSONL file of cases and a short script are enough to compare two prompt versions on the same questions:
import json
def load_cases(path="golden.jsonl"):
# each line: {"id": "...", "question": "...", "must_include": ["..."], "should_refuse": false}
with open(path, encoding="utf-8") as f:
return [json.loads(line) for line in f if line.strip()]
def grade(case, answer: str) -> bool:
text = answer.lower()
if case.get("should_refuse"):
return "don't know" in text or "not in the provided" in text
return all(term.lower() in text for term in case["must_include"])
def run(ask, prompt_version: str):
cases = load_cases()
passed = sum(grade(c, ask(c["question"], prompt_version)) for c in cases)
print(f"{prompt_version}: {passed}/{len(cases)} passed")
# run(ask_llm, "prompt_v1"); run(ask_llm, "prompt_v2")
Keyword checks are crude, but they catch regressions on day one. Later you can swap grade() for reference-answer comparison, a calibrated LLM-as-a-judge, or a library such as Ragas for RAG-specific metrics. The important habit is the same: one fixed set of cases, scored every time something changes.
Option 2: retrieval-augmented generation (RAG)
What it changes: the context. At question time you search your own documents and pass the most relevant passages to the model, with instructions to answer from them. The idea was formalised in the original RAG paper by Lewis et al. and is now the default pattern for enterprise question answering.
Good for: private company knowledge, anything that changes (policies, prices, catalogues), answers that need citations, and data where different users are allowed to see different documents.
Costs: you now run a pipeline: document parsing, chunking, embeddings, a vector or hybrid search index, and re-indexing when content changes. Retrieval quality becomes its own thing to measure.
Limits: RAG can only be as good as its retrieval. If the right passage isn't found, the model either says "I don't know" (good) or guesses (bad, unless your prompt forbids it).
What usually moves the numbers in RAG
- Chunking that follows the document's structure (headings, sections, tables) rather than fixed character counts.
- Hybrid search (keyword plus vector) and a re-ranker for the top results.
- Metadata filters for permissions, so a user only retrieves what they are allowed to see.
- Grounding rules in the prompt: answer only from the provided context, cite the source, say so when it isn't there.
- Separate metrics for retrieval (was the right chunk in the top results?) and generation (was the answer faithful to it?).
Managed options exist on every major cloud, for example the Vertex AI RAG Engine on Google Cloud, but the design decisions above still sit with you. We go deeper on architecture, evaluation and cost in agentic RAG in production.
Option 3: fine-tuning
What it changes: the model's weights. You train it further on examples of inputs and the outputs you want.
Good for:
- A consistent output format or style that prompts can't hold reliably.
- Narrow, repeated tasks (classification, extraction, routing) where a smaller tuned model may match a larger general one at lower cost and latency.
- Shorter prompts at scale, because behaviour you trained in no longer needs long instructions on every call.
Costs: you need a clean, representative training set (often hundreds to thousands of examples), training runs, a held-out evaluation set, and a plan to re-tune when the base model or your requirements change. Managed services such as tuning on Vertex AI or the options in OpenAI's model optimization guide handle the infrastructure. For open models, parameter-efficient methods such as LoRA train small adapters instead of all the weights, which makes tuning smaller models feasible on a single GPU.
Limits: fine-tuning is a poor way to add facts. The model may still blend or misremember them, you can't cite where an answer came from, and every update means another training run. That's exactly the job RAG is built for.
Before you fine-tune, check these five things
- Prompt and retrieval changes have stopped improving the golden-set score.
- The remaining failures are about behaviour (format, tone, routing), not missing facts.
- You have enough good examples, reviewed by someone who knows the domain.
- You have a held-out test set the training never sees.
- Someone owns re-tuning when the base model is upgraded or the requirements change.
If any answer is "no", the money is usually better spent on the prompt, the retriever or the dataset.
The decision table
| Your situation | Start with |
|---|---|
| Prototype, unclear requirements | Prompt engineering |
| Needs company documents, policies or live data | RAG |
| Answers must cite sources or respect user permissions | RAG |
| Format or tone keeps drifting despite good prompts | Fine-tuning (after prompting) |
| High-volume narrow task, cost or latency matters | Fine-tune a smaller model |
| Needs both private knowledge and a strict format | RAG + fine-tuning |
The order to follow
- Build the golden dataset from real questions and label the failures.
- Fix the prompt until instruction-following failures stop improving.
- Add retrieval for knowledge failures and measure retrieval and answer quality separately.
- Fine-tune only what's left: a format, a style, or a high-volume task where cost matters, and only if you have enough good examples.
- Keep evaluating in CI so a prompt edit, a new document batch or a model upgrade can't silently undo earlier wins.
Skipping straight to step 4 is one of the most common and most expensive mistakes in LLM projects. Teams spend weeks preparing training data for a problem that a clearer prompt or a better retriever might have fixed in a day.
Two illustrative examples
HR policy assistant (illustrative). Imagine employees asking about leave and reimbursement rules. If the wrong answers are almost all missing or outdated knowledge, RAG over the current policy documents, with citations and an "I don't know" rule, fixes the root cause. When the policy changes, you re-index one document. Fine-tuning would freeze last year's policies into the model.
Support ticket triage (illustrative). Say thousands of tickets a day need a category, a priority and a JSON summary. A large model with a long prompt works but is slow and costly at that volume. A smaller model fine-tuned on labelled past tickets can hold the format reliably at a lower per-call cost, with the golden dataset guarding accuracy. Tickets that mention account details still go through retrieval, so the tuned model never has to "remember" customer data.
Security doesn't change with the approach
Whichever lever you pick, the same risks apply: prompt injection hidden in retrieved documents, sensitive data leaking into answers or training sets, and over-trusting model output. The OWASP Top 10 for LLM Applications is a good checklist to run against your design. Add its attack cases to your golden dataset so they're tested on every release.
Learn to build and evaluate LLM apps with IndMinds
The Applied AI Engineer AI Course is a live, hands-on 12-week track (Mon / Wed / Fri, 10:00–11:30 AM IST, starting Mon 30 Nov 2026) where you build prompt-driven apps, production RAG pipelines and tool-using agents, and learn when fine-tuning is worth it, with evaluation built in from day one and code reviews from the instructor. Want to see the teaching style first? Book the free Applied AI Engineer demo. New to Python? Start with the Python for AI roadmap.
Sources (official pages, checked Nov 23, 2026)
- Lewis et al., Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks (2020)
- Hu et al., LoRA: Low-Rank Adaptation of Large Language Models (2021)
- Google Cloud: Introduction to tuning on Vertex AI
- Google Cloud: Vertex AI RAG Engine overview
- OpenAI: Model optimization guide
- Ragas documentation
- OWASP Top 10 for LLM Applications
Frequently asked questions
Should I use RAG or fine-tuning?
Use RAG when the model needs knowledge it does not have, especially knowledge that changes, must be cited or must respect user permissions. Use fine-tuning when the model already knows enough but needs to behave differently: a fixed output format, a house style, or a narrow task done more reliably and cheaply. Many production apps use both.
Does fine-tuning teach a model new facts?
Not reliably. Fine-tuning is good at changing behaviour and format. For facts that change, need citations or must respect who is allowed to see them, retrieval is the safer and cheaper choice, because you update a document instead of re-training a model.
What should I try first: prompt engineering, RAG or fine-tuning?
Prompt engineering, measured against a small evaluation set of 30 to 50 real questions. It is the cheapest lever to change and shows you exactly where the model fails. Add retrieval for knowledge failures, and consider fine-tuning only once prompts and retrieval have stopped improving the scores.
What is LoRA fine-tuning?
LoRA (Low-Rank Adaptation) is a parameter-efficient fine-tuning method that freezes the original model weights and trains small adapter matrices instead. It needs far less GPU memory and storage than full fine-tuning, which makes tuning smaller open models practical on a single GPU.
Can I combine RAG and fine-tuning?
Yes. A common pattern is RAG for the facts and a lightly fine-tuned model for the output format or tone, for example a support assistant that must cite current policy documents and always reply in a fixed JSON structure. Evaluate each layer separately so you know which one caused a regression.
Does IndMinds teach RAG, evaluation and fine-tuning?
Yes. The Applied AI Engineer AI Course covers prompting, production RAG, evaluation and when fine-tuning is worth it, with hands-on labs and code reviews. It runs live on Mon / Wed / Fri, 10:00–11:30 AM IST, starting Mon 30 Nov 2026.
Written by IndMinds AI Team, who builds and runs the AI video pipeline behind our flagship AI YouTube channel and teaches the IndMinds AI Courses. Policies and exam details change; we link the official pages so you can check the current version.
Related posts


Newsletter
One useful AI email a week. No spam.
New posts, real numbers from our channel, and the next workshop and batch dates. Unsubscribe with one reply.
Prefer WhatsApp?
Ask a question or get batch dates on WhatsApp. We reply within one working day.
