paulserban.eu

Writing Edition

Paul Serban

Writing, snippets & book notes

September 10, 2022

Model Adaptation Techniques in AI Engineering: Prompt Engineering vs. Fine-Tuning and Their Data Needs

A practical guide to choosing between prompt-based adaptation and fine-tuning, and how foundation models shifted data requirements across the AI engineering stack

Introduction

Every team building on a foundation model eventually faces the same question: how do I get this general-purpose model to perform well on my specific task? Unlike classical ML, where the answer was almost always "train a new model," foundation models offer a spectrum of adaptation techniques, each with dramatically different data requirements, engineering complexity, and payoff. Understanding this spectrum - and knowing when to reach for a lightweight technique versus a heavier one - is one of the most practically important skills in AI engineering.

At the highest level, adaptation techniques split into two categories based on a single structural question: does this technique require updating the model's weights? Prompt-based techniques, including prompt engineering and retrieval-augmented generation, adapt a model's behavior without touching its weights at all. Fine-tuning, by contrast, updates the weights directly through further training. This distinction isn't just academic - it determines how much data you need, how much infrastructure you must build, and how much engineering effort stands between you and a working application.

Why This Choice Matters: From Task-Specific to General-Purpose Models

Before foundation models, most production ML models were task-specific. A sentiment analysis model was trained to do exactly one thing: classify text as positive, negative, or neutral. It had no capacity to translate a sentence, summarize an article, or answer a question - those were entirely separate models, each requiring its own labeled dataset, its own training run, and its own deployment pipeline. If your product needed five different NLP capabilities, you likely needed five different models, each with its own data collection effort behind it.

Foundation models changed this by being general-purpose from the outset. Thanks to their scale and the way they're trained - typically through self-supervised pretraining on massive text corpora - a single large language model can perform sentiment analysis, translation, summarization, and dozens of other tasks reasonably well right out of the box, with no task-specific training at all. This capability is what makes the adaptation question so central to AI engineering: instead of asking "which model do I train for this task," teams now ask "which adaptation technique gets the most performance out of a model that's already broadly capable."

This shift doesn't eliminate the value of task-specific models entirely. A smaller, narrowly trained model can still be meaningfully faster, cheaper to run, and more predictable than a general-purpose foundation model wielded through prompting. The decision of whether to adapt an existing foundation model or build a task-specific model from scratch is, at its core, a classic buy-or-build trade-off - and the availability of powerful, accessible foundation models has simply shifted where that trade-off lands for most teams, making "buy and adapt" the sensible default for a much wider range of problems than it used to be.

The Two Categories of Adaptation: Weight-Updating vs. Prompt-Based

Prompt-Based Techniques: Adapting Without Touching the Model

Prompt-based techniques adapt a model's behavior by changing what you give it as input, not by changing the model itself. The most basic form is prompt engineering: crafting detailed instructions, often paired with examples of desirable outputs - a technique known as few-shot prompting - to steer the model toward the behavior you want. Because this technique requires no training step whatsoever, it's by far the easiest way to get started, and it requires the least data of any adaptation approach, sometimes needing nothing more than a handful of well-chosen examples embedded directly in the prompt.

A more sophisticated prompt-based technique is retrieval-augmented generation (RAG), where instead of (or in addition to) crafting examples, you connect the model to a database of relevant information it can draw on to generate better, more grounded outputs. RAG doesn't change the model's weights either - it changes what context the model sees at inference time, by retrieving relevant passages from a knowledge base and inserting them into the prompt. This makes RAG a prompt-based technique in the structural sense described above, even though it involves meaningfully more infrastructure (an embedding model, a vector store, a retrieval pipeline) than plain prompt engineering does.

Many genuinely successful production applications have been built using prompt engineering and RAG alone, without any fine-tuning at all. This is a notable departure from classical ML, where reaching production quality almost always required training on a labeled dataset specific to the task. The fact that prompt-based techniques can get an application to a usable, sometimes excellent, level of quality with minimal data investment is precisely what has lowered the barrier to entry for building AI applications.

Fine-Tuning: Adapting by Changing the Model Itself

Fine-tuning takes a fundamentally different approach: it adapts a model by updating its weights through further training on a dataset of examples specific to your task. Because this involves an actual training process rather than just crafting better inputs, fine-tuning is more complicated to implement - it requires training infrastructure, a labeled or curated dataset, and more ML expertise than prompt engineering does. It also requires meaningfully more data than prompt-based techniques, typically ranging from hundreds to a few thousand high-quality examples, though this is still dramatically less than the data required to train a model from scratch.

What fine-tuning offers in exchange for this added complexity is the ability to improve a model's quality, latency, and cost all at once, in ways prompt engineering often can't match. A fine-tuned model can internalize a desired output format, tone, or domain-specific behavior more reliably than a prompt can instruct it to, because the behavior is baked into the weights rather than re-explained on every single request. Fine-tuning can also reduce latency and cost: a model fine-tuned to perform a narrow task well sometimes allows you to use a smaller base model that would have underperformed on the same task with prompting alone, or to shorten prompts significantly because instructions that previously had to be spelled out in full are now partially encoded into the model's behavior.

How Responsibilities Shifted Across the Stack

The table below, drawn from how foundation models have reshaped AI engineering responsibilities, summarizes the shift succinctly for model development:

CategoryBuilding with Traditional MLBuilding with Foundation Models
Modeling and trainingML knowledge is required for training a model from scratchML knowledge is a nice-to-have, not a must-have
Dataset engineeringMore about feature engineering, especially with tabular dataLess about feature engineering and more about deduplication, tokenization, context retrieval, and quality control
Inference optimizationImportantEven more important

And for the application development layer:

CategoryBuilding with Traditional MLBuilding with Foundation Models
AI interfaceLess importantImportant
Prompt engineeringNot applicableImportant
EvaluationImportantMore important

This table captures something important about why prompt-based techniques have become so dominant: the skills needed to get value out of a foundation model are no longer concentrated exclusively in ML expertise. A product engineer with no background in training models can meaningfully improve an application's output quality simply by refining a prompt or improving retrieval - something that was never possible in the traditional ML pipeline, where the only lever for improving a model's behavior was retraining it, a process requiring specialized skills and substantial data.

At the same time, the table shows that nothing has actually gotten easier across the board - evaluation and inference optimization became more important, not less, even as modeling expertise became more optional. This is a useful corrective against the idea that foundation models simply remove engineering work; they relocate it, often toward areas (interface design, evaluation, prompt iteration) that classical ML pipelines barely had to think about.

Implementation: Choosing and Combining Adaptation Techniques

In practice, these techniques are rarely used in isolation - a well-built AI application often layers them. Consider a customer support application that starts with simple prompt engineering, then adds retrieval for product-specific knowledge, and only reaches for fine-tuning once both simpler techniques have been pushed as far as they can go.

import Anthropic from "@anthropic-ai/sdk";
import { retrieveRelevantDocs } from "./retrieval";

const client = new Anthropic();

// Stage 1: Pure prompt engineering - no retrieval, no fine-tuning
async function answerWithPromptOnly(question: string): Promise<string> {
  const response = await client.messages.create({
    model: "claude-sonnet-4-5",
    max_tokens: 400,
    system:
      "You are a customer support assistant for a SaaS billing product. " +
      "Answer clearly and concisely. If you're unsure, say so rather " +
      "than guessing.",
    messages: [{ role: "user", content: question }],
  });
  const block = response.content.find((b) => b.type === "text");
  return block && block.type === "text" ? block.text : "";
}

// Stage 2: Add retrieval-augmented generation for product-specific accuracy
async function answerWithRAG(question: string): Promise<string> {
  const relevantDocs = await retrieveRelevantDocs(question, 4);
  const context = relevantDocs.map((d, i) => `[${i + 1}] ${d.text}`).join("\n\n");

  const response = await client.messages.create({
    model: "claude-sonnet-4-5",
    max_tokens: 400,
    system:
      "Answer the user's question using ONLY the provided documentation. " +
      "Cite sources by bracketed number.",
    messages: [
      { role: "user", content: `Docs:\n${context}\n\nQuestion: ${question}` },
    ],
  });
  const block = response.content.find((b) => b.type === "text");
  return block && block.type === "text" ? block.text : "";
}

Both functions above are prompt-based: no model weights were touched, and no training job was run. The difference between them - adding a retrieval step - illustrates how much adaptation leverage is available before fine-tuning is ever necessary.

Only after a team has exhausted what prompting and retrieval can offer, and has specific production evidence of a recurring gap - say, the model consistently fails to follow a required JSON response format, or consistently misapplies company-specific policy language - does fine-tuning become justified. At that point, data preparation shifts toward curating a smaller, higher-quality dataset that demonstrates exactly the behavior the prompt-based approaches couldn't reliably produce:

import json

def build_finetune_dataset(reviewed_conversations: list[dict]) -> list[dict]:
    """
    Build a fine-tuning dataset from support conversations where human
    reviewers confirmed the assistant's response followed required
    format and policy correctly.
    """
    examples = []
    for convo in reviewed_conversations:
        if convo["reviewer_approved"]:
            examples.append({
                "messages": [
                    {"role": "system", "content": convo["system_prompt"]},
                    {"role": "user", "content": convo["user_question"]},
                    {"role": "assistant", "content": convo["approved_response"]},
                ]
            })
    return examples

def export_jsonl(examples: list[dict], path: str) -> None:
    with open(path, "w") as f:
        for ex in examples:
            f.write(json.dumps(ex) + "\n")

Notice that this dataset is small and highly curated - the goal isn't volume, it's precision on the exact behavior prompting couldn't reliably achieve.

Trade-offs and Pitfalls in Choosing an Adaptation Technique

The most common mistake teams make is reaching for fine-tuning too early, before they've genuinely exhausted what prompt engineering and RAG can offer. Fine-tuning introduces real ongoing costs: you now own a training pipeline, a versioned dataset, and a model artifact that needs to be re-tuned whenever the base model is updated or the task requirements shift. Many problems that look like they need fine-tuning - inconsistent tone, missing context, hallucinated facts - are often better and more cheaply solved by better prompts or better retrieval, which can be iterated on in minutes rather than requiring a full training run.

The opposite mistake also happens: teams stay with prompt engineering indefinitely even when production evidence clearly shows its ceiling has been reached. Prompt engineering has real limits - there's only so much behavior you can reliably instruct into a model through text, especially for tasks requiring a very specific, high-precision output format or a style that needs to feel deeply consistent across thousands of interactions. Teams that treat fine-tuning as permanently off-limits, regardless of production signal, sometimes end up writing increasingly long, brittle prompts to compensate for behavior that a modest fine-tuning dataset would have fixed more durably and cheaply.

A third pitfall concerns RAG specifically: treating retrieval as a solved problem once it's implemented, rather than an ongoing area needing evaluation. A RAG pipeline's quality depends heavily on retrieval precision - if the wrong documents get retrieved, even the best prompt and the best underlying model will produce a confidently wrong answer. Teams sometimes invest heavily in prompt engineering around a RAG pipeline's outputs while neglecting to measure and improve the quality of the retrieval step itself, which is often the actual bottleneck.

Best Practices for Matching Technique to Need

Start with prompt engineering by default, and resist the urge to skip straight to fine-tuning, even when you suspect the task is hard. Prompt engineering is cheap to iterate on and gives you fast, direct signal about where a general-purpose model's capabilities genuinely fall short, which is valuable information whether or not you eventually fine-tune. If your task depends on information the base model doesn't have - product-specific documentation, recent events, proprietary data - add retrieval before considering fine-tuning, since RAG solves a knowledge gap that fine-tuning is poorly suited to solve (fine-tuning teaches behavior and style far more reliably than it teaches new facts).

Move to fine-tuning only when you have specific, repeated evidence - ideally from production logs, not just intuition - that prompting and retrieval have hit a ceiling on a well-defined behavior. When you do fine-tune, invest in a small, carefully reviewed dataset rather than a large, loosely curated one; because fine-tuning datasets are much smaller than training-from-scratch datasets, each example carries disproportionate weight in shaping the model's behavior, so quality matters far more than quantity at this stage. Finally, treat the responsibility shifts described in the comparison table as a hiring and team-structure signal: since evaluation and interface design have become more important while raw ML modeling expertise has become less essential, teams succeed by investing accordingly, even if that means a different skill mix than a classical ML team would have had.

Mental Model: Renovating vs. Rebuilding a House

A useful analogy is to think of prompt engineering as rearranging furniture and giving better directions to someone already living in a house: you're not changing the house's structure, just how it's used and what instructions the occupant follows. RAG is like handing that occupant a reference library they can consult before answering questions - still no structural change, just better-informed answers. Fine-tuning, by contrast, is like renovating the house itself: more expensive, more disruptive, and not something you'd do for every small inconvenience, but sometimes genuinely necessary when the structure itself doesn't fit how you need to use the space. Nobody renovates a house because a chair is in the wrong corner - and in the same way, nobody should fine-tune a model to fix a problem a better prompt could solve.

Key Takeaways

Conclusion

The choice between prompt-based adaptation and fine-tuning isn't a binary decision made once at the start of a project - it's a spectrum that teams move along as evidence accumulates. Prompt engineering and RAG offer the fastest path to a working application with the least data investment, and for many tasks, that's genuinely enough. Fine-tuning remains valuable, but it's a heavier tool that should be reached for deliberately, once simpler techniques have shown their limits on a specific, well-understood problem.

What ties all of this together is the broader shift foundation models introduced: from task-specific models requiring dedicated training to general-purpose models that get tailored through a spectrum of adaptation techniques with very different data and engineering costs. Teams that understand this spectrum - and the responsibility shifts it brought across modeling, dataset engineering, and application development - are better positioned to invest their engineering effort where it actually moves the needle, rather than defaulting to the most complex technique available when a simpler one would do.

References

  1. Huyen, Chip. AI Engineering: Building Applications with Foundation Models. O'Reilly Media, 2024.
  2. Huyen, Chip. Designing Machine Learning Systems. O'Reilly Media, 2022.
  3. Lewis, Patrick et al. "Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks." NeurIPS, 2020.
  4. Hu, Edward J. et al. "LoRA: Low-Rank Adaptation of Large Language Models." arXiv:2106.09685, 2021.
  5. Brown, Tom B. et al. "Language Models are Few-Shot Learners." NeurIPS, 2020. (Few-shot prompting)
  6. Ouyang, Long et al. "Training Language Models to Follow Instructions with Human Feedback." NeurIPS, 2022.
  7. Anthropic. "Claude API Documentation." docs.anthropic.com.
  8. OpenAI. "Fine-tuning Guide." OpenAI Platform Documentation.