Skip to chapter content
navan✳THE BUILD LABAI ENGINEERING / GUIDE
0/21 read
CHAPTER 15 / 21 · ADAPTATION AND EFFICIENCY

When to fine-tune a model.

Separate prompt, retrieval, and fine-tuning problems, then understand what an adaptation dataset teaches.

BY NAVAN SAMILONG READTHEORY FIRST
01 / FROM THE BEGINNING

Start with the meaning.

Fine-tuning changes a model's behavior by training it further on task-specific examples. It can help with a consistent output style, specialized format, or repeated task pattern. It is not the first answer to every failure. If the model lacks a current policy fact, retrieval is usually the more direct way to supply it. If a prompt is ambiguous, clarify the task before changing model weights.

Training examples teach patterns from inputs to desired outputs. Poor examples teach poor behavior. If the dataset contains unsupported answers, inconsistent labels, or private data without permission, fine-tuning can amplify those problems. Dataset quality and evaluation matter more than the mere act of training.

02 / THE SYSTEM

How the idea works.

A practical decision sequence is: define the failure, test a baseline prompt, improve evidence access, consider a simpler workflow, then assess whether a persistent behavior gap remains. Fine-tuning may be worthwhile if many examples show the same gap and the improvement justifies data preparation, training cost, and maintenance. Keep a holdout evaluation set that was not used for training.

Supervised fine-tuning uses examples of desired responses. Preference-based methods compare outputs and train toward preferred behavior. These approaches can shape style and task behavior, but they do not create a guarantee of factuality or permission compliance. The application still needs validation and monitoring.

A fine-tuned model is a new dependency. It has a version, training data lineage, evaluation results, and operational cost. When base models change, the adapted model may need to be rebuilt or re-evaluated. Consider whether a smaller adapted model can meet the task with lower latency than a larger general model.

Imagine a model repeatedly emits the wrong JSON field names despite a clear schema and many examples. A fine-tuned model may learn the desired format more consistently. Now imagine it gives the wrong vacation balance because the balance changed yesterday. Fine-tuning on old balances would be the wrong fix; the application needs current records or retrieval. Diagnose whether the failure is about behavior, knowledge, evidence, or authority before choosing an adaptation technique.

A training set should contain examples of the cases the model will face, including difficult boundaries and refusals. If it only contains ideal inputs, the adapted model may still fail on incomplete requests. Compare the adapted model against the existing system on a holdout that was never used for training or prompt tuning. Include latency, price, and critical failures in that comparison. A training run is an experiment whose value must be demonstrated.

01CorpusFacts to cite02TrainingBehavior to learn03HoldoutBehavior to test04FeedbackBehavior in use
Separate source facts, training examples, evaluation cases, and live feedback.
03 / PYTHON, EXPLAINED

Follow the code.

finetuning-decisions.py
def diagnose_failure(case):
    if case["missing_current_fact"]:
        return "improve retrieval"
    if case["invalid_output_shape"]:
        return "tighten schema and validation"
    if case["repeated_style_gap"] and case["labelled_examples"] >= 100:
        return "evaluate fine-tuning"
    return "inspect examples and task definition"

This is a decision aid, not an automated training plan. A missing current fact points to evidence access. A malformed object points to output constraints. A repeated style gap with many labelled examples makes fine-tuning worth evaluating. The number 100 is illustrative; the needed amount depends on task diversity and model behavior.

The code's order prevents a fine-tuning project from hiding a retrieval or validation defect. Each returned recommendation still requires a measured comparison against the existing system.

04 / THE BOUNDARY

What the result does not say.

Training data may contain personal or licensed material. Preserve its origin and permitted use. Do not assume that data available to read is automatically permitted for model training.

Fine-tuning can reduce prompt length or improve consistency, but those gains should be measured against preparation and serving costs.

05 / KEEP THIS

One clear idea.

Fine-tune for a measured, persistent behavior gap after the task and evidence path are sound.

THE CODE IN CONTEXT

The AI cookbook

Complete, explained local workflows sit alongside this reading course.

Browse the cookbook
Finished reading?
Built with curiosity. By Navan Sami. ↗AI engineering · From model calls to reliable systems.