Skip to main content
المدونة

Zalt Blog

Deep Dives into Code & Architecture

AT SCALE

Fine-Tuning vs RAG vs Prompting: What to Reach for First

By محمود الزلط
Insights
12m read
<

Most teams asking about fine-tuning their LLM actually need better prompting. Here is the ordered decision framework I use with every production AI system I build.

/>
Fine-Tuning vs RAG vs Prompting: What to Reach for First - Featured blog post image
Mahmoud Zalt

1:1 Mentor

Are you a software engineer moving into AI?

Let's have a call. I'll help you modernize your skills and learn the tools, systems, and architecture behind real AI products. One session or ongoing.

Hire AI Employees

Hire AI Employees that work 24/7. No code.

Alice, AI Personal Assistant
AI Assistant

Alice

AI Personal Assistant

Chat Now

Prompting First, RAG Second, Fine-Tuning Last

If you are wondering whether to fine-tune a model, use RAG, or just write better prompts: start with better prompting. The overwhelming majority of production teams I have worked with got to 80-90% of their quality target through structured prompting alone, with no model training involved. Reserve RAG for when your knowledge is too large or too dynamic to fit in context. Reserve fine-tuning for a narrow set of cases where neither of the cheaper options can close the remaining gap.

I am Mahmoud Zalt, an independent senior AI systems architect with 16+ years building production software. I founded Sista AI, where the choice between fine-tuning and retrieval has come up repeatedly across a year of keeping autonomous agents reliable in production. I build AI agents and LLM-backed systems end-to-end, and my AI agent development work runs this exact decision process on every engagement. What follows is the framework I use, not theory.

Why the Order Matters: Cost and Reversibility

These three techniques are not interchangeable options sitting at the same level. They differ sharply in cost, lead time, and how easily you can undo a mistake.

TechniqueUpfront costTime to first resultReversible?Requires labeled data?
Better promptingNear zeroMinutesFully, instantlyNo
RAGLow to mediumHours to daysMostly yesNo (eval set helps)
Fine-tuningHighDays to weeksNo, you retrainYes, hundreds to thousands

The order is not about preference. It is about not paying a $10,000 fine-tuning bill to fix something a better system prompt would have solved in an afternoon. Every engagement where a team skipped this ladder had the same pattern: they jumped to fine-tuning because it felt more 'serious,' then discovered the base model was never their bottleneck.

Stage 1: Exhaust Prompting Before Anything Else

Prompting is underestimated because it looks simple. It is not. Most teams write a one-sentence instruction and declare prompting insufficient. That is not prompting, that is a placeholder.

What actually exhausting prompting looks like

  • Role + task + format + constraints in the system prompt. Be explicit about output schema (JSON, markdown headers, bullet rules). Models comply dramatically better when the output shape is spelled out.
  • Few-shot examples in the prompt. Three to five concrete input/output pairs, chosen to represent your edge cases, often outperform a fine-tuned model on a small dataset.
  • Chain-of-thought for reasoning tasks. Instruct the model to think step by step before producing a final answer. For classification and structured extraction, this alone moves accuracy by 10-20 points on hard cases.
  • Negative instructions. Tell the model what not to do, not just what to do. 'Do not invent citations. If you do not know, say so.' This reduces hallucination meaningfully without any training.
  • Temperature and sampling params. Creative tasks want temperature 0.7-1.0. Deterministic extraction tasks want temperature 0.0 or close to it. Wrong sampling settings make a good prompt look bad.

When to stop at prompting

If your eval set accuracy is above 85% and failures are edge cases you can handle with output validation or a retry, you are done. Ship it. The remaining gap may not be worth the cost of the next stage.

What teams get wrong here

They do not build an eval set before iterating. Without a fixed set of 50-200 representative input/output pairs scored against a rubric, prompt changes are guesswork. You will ship a prompt that looks better on the three examples you tested and is worse on 40 others. Build the eval set first, run every prompt version against it, keep the version with the best aggregate score.

Stage 2: Add RAG When the Knowledge Problem Is Real

RAG (Retrieval-Augmented Generation) solves one specific problem: the model does not have the right facts in its weights, and you cannot fit all the facts in the context window. It is not a quality booster in general. It is a knowledge delivery mechanism.

The three legitimate RAG use cases

  1. Knowledge that changes faster than you can retrain. Product documentation, pricing, legal policies, support articles. Anything updated weekly or more frequently. You update the index, the model sees fresh facts tomorrow.
  2. Knowledge too large for context. A 500,000-word internal wiki, a codebase, a corpus of research papers. You cannot paste it all in. Retrieval selects the relevant slice.
  3. Attribution requirements. Finance, legal, healthcare. The user needs a 'this came from doc X, page 3' citation. RAG gives you the source chunk natively.

A minimal production RAG stack

The simplest version that actually works in production: chunk documents into 300-600 token pieces with a 10-15% overlap. Embed with a dedicated embedding model (OpenAI text-embedding-3-small or a self-hosted alternative for cost control). Store in a vector DB with metadata filters (Qdrant, Weaviate, or pgvector if you are already on Postgres). At query time, retrieve 5-10 candidates, re-rank with a cross-encoder, inject the top 3-5 into context. Add a 'no relevant content found' fallback so the model does not hallucinate an answer when retrieval misses.

Where RAG fails and what to do about it

RAG fails when retrieval fails. The generation model is only as good as what you hand it. The most common failure modes: chunks are too large and dilute signal, embedding model does not match your domain vocabulary, no metadata filtering so irrelevant documents compete with relevant ones, and no eval loop on retrieval quality. Measure retrieval recall separately from end-to-end answer quality. If retrieval recall at top-5 is below 80% on your eval set, fix retrieval before blaming generation.

RAG is not a replacement for prompting

RAG and prompting compose. You still need a well-structured prompt that tells the model how to use the retrieved context, when to say it does not know, and what format to produce. Bad prompting with good retrieval still produces bad output. Get prompting right first, then layer in RAG.

Stage 3: Fine-Tune Only in These Narrow Cases

Fine-tuning is powerful and genuinely the right call in some situations. Those situations are narrower than most teams think. Here is the precise list of cases where I recommend it.

When fine-tuning is actually the right tool

  • Style and tone that few-shot examples cannot nail. If your brand voice is unusual enough that even 10 in-context examples do not capture it, and you have 500+ labeled examples, fine-tuning locks in the style cheaply at inference time.
  • Latency and cost-driven compression. You have a complex multi-shot prompt that costs $0.08 per call and you are running 1 million calls per day. Fine-tuning a smaller model on outputs from a larger model (distillation) can replace a GPT-4o call with a fine-tuned GPT-4o-mini call at 10x lower cost, once quality is validated.
  • Structured output reliability at scale. For very high-volume pipelines where you need exact JSON schema compliance on every call, fine-tuning on format examples eliminates retry logic and parsing failures. This matters when 0.1% parse failure rate means thousands of broken records per day.
  • Domain adaptation with proprietary notation. Medical coding (ICD-10), legal citation formats, internal DSLs, specialized scientific notation. These do not appear in pretraining data. RAG can supply context but the model still struggles with the syntax. Fine-tuning on domain examples fixes this.
  • Capability that prompting literally cannot add. If you need the model to follow a reasoning protocol it has never seen, not just a style variation but a genuinely novel task structure, fine-tuning is the only option besides using a different base model.

What fine-tuning does not fix

Fine-tuning does not fix factual gaps. If the model does not know your product's current pricing, fine-tuning on old examples embeds old pricing. You will ship stale facts that are harder to update than a RAG index. Fine-tuning also does not fix a retrieval problem. And it does not fix a prompt that never told the model what to do clearly. I have seen teams invest weeks in fine-tuning runs because prompting was never properly attempted. The fine-tuned model was marginally better, but the baseline was so low that a well-crafted zero-shot prompt on the original model would have outperformed it.

The data requirement is non-negotiable

Supervised fine-tuning requires labeled examples: input/output pairs where the output is exactly what you want the model to produce, reviewed by a human. For instruction following, 200-500 high-quality examples are a minimum for a measurable lift. For reliable behavior change, plan for 1,000-5,000. Low-quality labeled data is worse than no fine-tuning. It will teach the model your labelers' mistakes at scale.

Worked Example: A Support Bot That Escalated Incorrectly

A team came to me with a support bot that was escalating too many tickets to human agents. Their first instinct was to fine-tune on historical tickets labeled 'should escalate' vs. 'should not escalate.' Before going there, I ran the prompt audit.

The original system prompt was 47 words with no examples and no escalation criteria. I rewrote it to explicitly list the 8 conditions that warrant escalation (billing disputes over $500, explicit legal threats, repeated contacts on the same issue, etc.), added 6 few-shot examples showing the boundary cases, and set temperature to 0.1. I ran both versions on a 200-ticket eval set labeled by their support lead.

Original prompt: 61% correct escalation decisions. Rewritten prompt: 87% correct. Fine-tuning was never needed. The team saved 3 weeks of data labeling and a training run. The remaining 13% gap was partly from genuinely ambiguous tickets that even humans labeled inconsistently, not a model failure. That ambiguity is not a fine-tuning target, it is a policy decision about escalation thresholds.

If they had needed to go further: the next step would have been RAG on their internal escalation policy documents, not fine-tuning. Fine-tuning would have been the right call only if the escalation rules were so idiosyncratic and large-volume that per-call cost became a constraint.

Evals Are Not Optional: The Infrastructure Under All Three

None of these three approaches is responsible engineering without an eval framework underneath. Evals are how you know whether a change improved anything, and they are the same infrastructure regardless of which layer you are working on.

A minimal eval setup

Collect 100-500 representative inputs from your real use case. For each, define the expected output or a scoring rubric (exact match, semantic similarity, human preference, or rule-based checks). Run every candidate prompt version, retrieval config, or model checkpoint against this set. Track aggregate score, failure mode distribution, and regression on previously passing cases. Automate this in CI so no change ships without an eval run.

For LLM-as-judge evals: use a different, stronger model to score outputs when human labeling is expensive. Define the scoring prompt carefully and validate that the judge agrees with humans on 30-40 calibration examples before trusting it at scale.

Observability in production

Log every prompt and completion in production with latency, token count, model version, and a stable request ID. Route 1-5% of production traffic to shadow evaluations. Monitor output length distribution, refusal rate, and format compliance. When something degrades, you need the trace to know which layer broke: retrieval, prompting, or model behavior.

The Decision Tree I Actually Use

When a client asks which approach they need, I work through this sequence:

  1. Is the system prompt structured with role, task, format, constraints, and examples? If no: write it properly and measure. Stop here if eval target is met.
  2. Is the problem a knowledge gap: facts not in weights, too much to fit in context, or content that changes frequently? If yes: add RAG. Measure retrieval recall separately before measuring generation quality.
  3. After both prompting and RAG: is the remaining quality gap coming from style, output format compliance, or a domain-specific notation the model has never seen? If yes, and if volume justifies the cost: consider fine-tuning.
  4. Do you have 500+ high-quality labeled examples you can afford to create and maintain? If no: do not fine-tune yet. Return to prompting and RAG iteration.
  5. Is the use case high-volume enough that per-call cost reduction through a smaller fine-tuned model pays for training? If yes, this is the strongest economic case for fine-tuning.

Most teams exit at step 1 or step 2. Very few legitimate use cases require step 3, and almost none require it before steps 1 and 2 are genuinely exhausted.

Frequently Asked Questions

when should I use RAG vs fine-tuning for a knowledge-heavy chatbot

Use RAG. Knowledge-heavy means the facts change or the corpus is large. Fine-tuning embeds facts statically into weights; you would need to retrain every time facts change, which is expensive and slow. RAG lets you update the index and have the model cite fresh facts the next day. Fine-tune only if, after RAG, the model still cannot handle the domain's specialized syntax or vocabulary in the response style you need.

does fine-tuning reduce hallucination

No, not reliably. Fine-tuning on correct examples can reduce a specific class of error on your training distribution, but it does not give the model new facts it did not have. A model trained to confidently answer questions in your domain will confidently produce wrong answers for questions outside its training examples. Hallucination reduction requires grounding (RAG or tool calls to authoritative sources) plus output validation, not just training signal.

how many examples do I need to fine-tune an LLM

For a measurable quality lift on instruction following: 200-500 high-quality, human-reviewed examples at minimum. For reliable behavior change on complex tasks: plan for 1,000-5,000. For style transfer or format compliance on a narrow task: sometimes 100 very clean examples are enough. The quality of examples matters more than raw count. Noisy labels at 5,000 examples will underperform clean labels at 500.

is prompt engineering enough for a production AI product

For most products: yes, with RAG added if knowledge management is needed. Prompt engineering plus a retrieval layer covers the requirements of the majority of B2B AI products I have built or reviewed. Fine-tuning is an optimization for specific constraints (cost, style, domain notation), not a prerequisite for production quality. The products that look most polished are usually the ones with the most carefully designed prompts and evaluation pipelines, not the ones with the most model training.

what is the cost difference between RAG and fine-tuning in practice

RAG ongoing costs are: embedding API calls (cheap, fractions of a cent per query), vector DB hosting ($50-$500/month for most use cases), and slightly larger prompts that increase per-call token cost. Fine-tuning upfront costs are: data labeling ($1,000-$20,000+ depending on complexity and volume), training compute ($100-$5,000+ per run on hosted APIs, more on self-hosted GPU), and ongoing cost of maintaining labeled data as your product evolves. The RAG path is almost always cheaper to start and maintain unless you have clear per-call cost reduction economics for fine-tuning.

can I combine prompting, RAG, and fine-tuning

Yes, and in mature production systems you often will. A fine-tuned model that has internalized your output format, served with RAG for fresh knowledge, and governed by a carefully structured system prompt is a legitimate architecture. The point of the ladder is the order of adoption, not mutual exclusivity. Add each layer only when the previous one has been fully exercised and measured. Layering all three on day one is overengineering that creates debugging complexity without proportional quality gain.

Build the Right Layer, Not the Most Impressive-Sounding One

The teams that ship reliable AI systems fastest are the ones that resist the pull toward complexity. They write a proper prompt, measure it, add retrieval if the knowledge problem is real, and reach for fine-tuning only when there is a clear economic or capability case that the first two layers cannot close. That discipline is harder than it sounds when everyone on the team wants to say they are training models.

If you are working through this decision for a real product and want a second opinion grounded in production experience, my AI agent development work includes architecture reviews where this is exactly what we work through together. Or reach out directly at /contact to talk through your specific system.

Work with me on your AI architecture decision

Thanks for reading! I hope this was useful. If you have questions or thoughts, feel free to reach out.

Content Creation Process: This article was generated via a semi-automated workflow using AI tools. I prepared the strategic framework, including specific prompts and data sources. From there, the automation system conducted the research, analysis, and writing. The content passed through automated verification steps before being finalized and published without manual intervention.

Mahmoud Zalt

About the Author

I’m Zalt, a technologist with 16+ years of experience, passionate about designing and building AI systems that move us closer to a world where machines handle everything and humans reclaim wonder.

Let's connect if you're working on interesting AI projects, looking for technical advice or want to discuss anything.

Support this content

Share this article