ByUmair

Thinking

Back to thinking
AI Architecture8 min readPublished

RAG vs Fine-Tuning vs Prompt Engineering: A Decision Framework

Prompting, retrieval, and fine-tuning solve different problems, so the right choice begins with what must change.

By

Choose prompt engineering when the model needs clearer instructions, RAG when the request needs current or private evidence, and fine-tuning when a stable task needs learned behavior that examples in the prompt cannot deliver reliably or economically. They are not maturity levels and they are not mutually exclusive. Start with an evaluation set, diagnose the failure, and change the smallest layer that can fix it.

Ask what must change
Instructions

Prompt, examples, output contract, and deterministic validation.

Knowledge

Retrieve authorized, current, attributable evidence at request time.

Behavior

Train on representative examples after a prompted baseline plateaus.

Diagnose the failure before choosing the technique

Build representative cases and a strong base-model baseline first. Score task correctness, evidence support, format, safety, latency, and cost separately. Include missing evidence, ambiguous requests, adversarial content, and cases where abstention is correct. A single quality score can conceal the difference between a style mismatch and an unauthorized tool action.

Inspect errors. If the answer is wrong because the task or format is unclear, improve the prompt. If the needed fact never reached the model, improve context or retrieval. If the model has the right evidence and instructions but repeatedly applies the wrong transformation or decision boundary, investigate fine-tuning. If the application passes the wrong tenant's document or accepts malformed output, none of the three techniques solves the actual defect.

OpenAI's current model-optimization guidance uses the same core loop: establish evals, prompt with relevant context, consider fine-tuning for suitable cases, and run representative tests after every change. Provider features and availability change, so treat the technique as an architectural category and verify current support before committing to a platform.

Use prompt engineering for a clearer, bounded job

Prompt engineering changes what the model sees for the current request. Define the task, permitted evidence, output structure, refusal conditions, and what to do when information is missing. Separate trusted instructions from user and retrieved content. Add a few diverse examples when the model understands the capability but needs the local pattern.

Prompting is the first choice for extraction, classification, rewriting, routing, and drafting when the necessary information fits in context. It is easy to version with the application, inspect during an incident, compare in an eval, and roll back. Validate structured output in code and enforce permissions outside the prompt; instructions are not a type system or an authorization boundary.

Do not use a prompt as a document store. Pasting a handbook into every request increases token cost and latency, can crowd out relevant context, and provides no ingestion, freshness, or permission model. A larger context window changes the capacity constraint, not the need to select trustworthy evidence. Prompting also cannot create a missing fact.

Use RAG when knowledge must be current, private, or attributable

Retrieval-augmented generation selects external material at request time and supplies it as context. The original 2020 RAG paper described combining a model's learned parameters with a retrieved non-parametric memory. In a product, the useful property is operational: documents can be updated, permissioned, deleted, and cited without retraining model weights.

A production RAG system is an evidence pipeline, not a vector database. OpenAI's retrieval guide covers semantic search and configurable ranking; a complete product must also identify authoritative sources, ingest and version them, preserve document and access metadata, split content without losing meaning, retrieve candidates, optionally rerank, assemble bounded context, and map citations back to the original source. Semantic retrieval helps with conceptual similarity; lexical or structured filters remain important for identifiers, dates, plan names, and exact error codes.

Evaluate each stage. Measure whether the corpus contains the answer, whether permission filters exclude unauthorized content before retrieval, whether relevant evidence appears in the candidate set, and whether the final response is entailed by that evidence. A citation proves that a source was attached, not that the response faithfully represents it.

Retrieved content is untrusted. OWASP's guidance on vector and embedding weaknesses covers unauthorized access, data poisoning, and hidden content that can manipulate downstream generation. Keep instructions separate, authorize before retrieval, track provenance, sanitize downstream rendering, and never let a retrieved instruction expand tool permissions.

Use fine-tuning for a demonstrated, repeated behavior gap

Fine-tuning changes model behavior by training on examples or feedback. It can improve a specialized classification boundary, recurring transformation, output style, or tool-selection pattern. It may also let a smaller model perform a narrow task or reduce repeated few-shot examples. Those are hypotheses to measure against the base model, not guaranteed benefits.

Use it only when the task is stable, high-volume enough to justify a model lifecycle, and supported by representative examples on which reviewers agree. OpenAI's supervised fine-tuning documentation describes training on prompt-and-desired-output examples and evaluating against held-out data. The same experimental requirement applies across providers and open models: keep training cases separate from the evaluation used to claim improvement.

Fine-tuning is usually the wrong store for current facts, one customer's documents, prices, or policies. Those need record-level updates, access control, deletion, and often citation. Training data also becomes a governed product: establish provenance and consent, remove secrets and poisoned examples, version the dataset and base model, document the configuration, and regression-test every replacement.

Availability is a real architectural constraint. Providers support different techniques and models, and their product roadmaps change. OpenAI's current optimization page, for example, says its hosted fine-tuning platform is being wound down for new use while existing models follow deprecation timelines. Verify portability, export options, model support, regional requirements, and the fallback if a fine-tuned endpoint is retired.

Combine techniques without blurring ownership

A mature system may use all three: a versioned prompt instructs a fine-tuned model using passages retrieved from an authorized corpus. Keep each responsibility observable. The prompt owner controls task instructions and output contracts. The retrieval owner controls corpus quality, permissions, freshness, and ranking. The model owner controls training data, model versions, and regression results.

Consider a SaaS support assistant. The prompt defines tone, escalation, and response fields. RAG supplies the customer's plan, current documentation, and incident status. Fine-tuning becomes relevant only if reviewed examples reveal a stable behavior gap—perhaps a subtle routing taxonomy—that the prompted models cannot meet at the required cost. Fine-tuning would not remove the need for current retrieval or application authorization.

Keep consequential action separate from generated language. Tool schemas, allowlists, tenant permissions, argument validation, idempotency, rate limits, and approval gates belong in application code. Retrieved text and model output can propose an action; a trusted policy layer decides whether it is allowed and verifies the result.

Let operating constraints break close decisions

ConcernPromptingRAGFine-tuning
Primary assetVersioned instructionsVersioned corpus and retrievalVersioned training data and model
Fresh factsOnly if suppliedStrong fitPoor fit
Main latencyInput and generationSearch, reranking, generationInference, possibly shorter input
DeletionRemove request contextRemove source and derived index dataMay require a future training version
New failure surfacePrompt drift and context limitsIngestion, permissions, retrieval, freshnessDataset quality, training, hosting, deprecation

Benchmark end-to-end cost and tail latency per successful task. Prompting adds input tokens but little infrastructure. RAG adds ingestion, storage, retrieval, and freshness operations. Fine-tuning adds data preparation, training, hosting, model governance, and regressions, while sometimes reducing inference cost. Include human review and failure handling in every comparison.

Data constraints may decide first. RAG is usually easier when individual records need tenant permissions, regional placement, citation, or deletion. Fine-tuning requires a lawful and contractually permitted training dataset, and removing one example from an already trained model may not be practical. Prompt-only context can suit short-lived sensitive inputs if provider processing and retention controls meet the requirement.

Apply the decision in five steps

  1. Define success and failure. Build representative and held-out cases before optimizing.
  2. Establish a prompted baseline. Supply the facts that fit, define the output, and validate it.
  3. Classify remaining errors. Separate missing knowledge, weak retrieval, behavior, permissions, and application defects.
  4. Add one intervention. Introduce RAG for evidence or fine-tuning for a proven behavior gap, then rerun the same eval.
  5. Operate the chosen layer. Version it, monitor quality, latency, cost, security, and drift, and keep a rollback path.

The conservative default is prompt first, retrieval for knowledge, and fine-tuning for evidence-backed behavior gaps. It keeps early work reversible and failures attributable. For the evaluation process behind that choice, read how to evaluate an AI feature before writing code. The AI workflow and services overview connect the framework to product delivery.

Sources and further reading