Fine-Tuning LLMs: When, Why and How
What fine-tuning changes, when to choose it over prompting or retrieval, how to build the dataset and how to evaluate the result.

On this page
Fine-tuning means continuing to train an existing model on your own examples so that its default behaviour shifts toward what you need. It's one of the most powerful tools in applied AI, and one of the most often misused. This guide covers what fine-tuning actually changes, when it's the right call, and how to run a project that ships a better model rather than just a different one.
What fine-tuning changes
A modern language model goes through two broad training stages before you meet it:
- Pretraining on a huge text corpus teaches it language, facts and reasoning patterns by predicting the next token, billions of times over.
- Post-training (instruction tuning and preference tuning) turns that raw predictor into an assistant that follows instructions and stays polite.
Fine-tuning is a small, targeted extra round of post-training on your data. It nudges the model's weights so that, given inputs like yours, the outputs you showed it become the most likely ones.
The key word is behaviour. Fine-tuning is very good at teaching:
- a strict output format or schema, every time;
- a house tone of voice or writing style;
- a classification or extraction task with your labels and edge cases;
- domain conventions (how your clinicians abbreviate, how your lawyers structure a clause).
It's poor at teaching facts. A model fine-tuned on your product catalogue will half-remember it, mix it with what it already knew, and be unable to tell you where an answer came from. When the catalogue changes, the model is out of date until you retrain. Facts belong in retrieval.
Should you fine-tune?
Answer five questions and get a recommendation. Notice how often the answer is "not yet":
The pattern behind it: try prompting and examples first, measured against an eval set. If the gap is missing knowledge, add retrieval. Fine-tune when the gap is behaviour that prompting can't hold reliably, and you have good examples, or when you need a small, cheap model to do one narrow job as well as a large one.
Kinds of fine-tuning
| Method | What you provide | What it teaches | Typical use |
|---|---|---|---|
| Supervised fine-tuning (SFT) | Input → ideal output pairs | Imitate these outputs | Formats, extraction, style |
| Preference tuning (e.g. DPO) | Input + preferred and rejected outputs | Prefer better over worse | Helpfulness, tone, safety nuances |
| Continued pretraining | Large amounts of raw domain text | Domain vocabulary and patterns | Specialised fields with unusual language |
| Distillation | Outputs of a large model on your task | Copy a big model's behaviour | Cheaper, faster production models |
Most business projects start and end with SFT. Preference tuning becomes useful once SFT gets the format right but you still want to steer quality in ways that are easier to compare than to write out.
Data is the product
The model will learn whatever your examples contain, including their mistakes. A few hundred excellent examples routinely beat tens of thousands of noisy ones.
Most fine-tuning stacks accept chat-formatted examples, one per line (JSONL):
{"messages": [
{"role": "system", "content": "Extract the claim details as JSON."},
{"role": "user", "content": "Hi, my parcel 88-1204 arrived on 3 March with a cracked screen..."},
{"role": "assistant", "content": "{\"order_id\": \"88-1204\", \"issue\": \"damaged\", \"component\": \"screen\", \"reported_on\": \"2026-03-03\"}"}
]}A data checklist that saves projects:
- Use real inputs. Pull them from logs or tickets, with personal data removed. Synthetic inputs are too clean.
- Have experts write or correct the outputs. The model can't be better than its teachers.
- Cover the edge cases on purpose: empty fields, ambiguous requests, things the model should refuse or flag.
- Balance the labels. If 90% of examples say "approve", the model learns to approve.
- Deduplicate, and keep near-duplicates of test cases out of training.
- Hold out an eval set before you train anything, and never train on it.
import json, random
def split_dataset(path, eval_share=0.1, seed=13):
rows = [json.loads(line) for line in open(path)]
unique = {json.dumps(r["messages"], sort_keys=True): r for r in rows}.values() # exact-duplicate removal
rows = list(unique)
random.Random(seed).shuffle(rows)
cut = int(len(rows) * (1 - eval_share))
return rows[:cut], rows[cut:]Full fine-tuning vs parameter-efficient methods
Updating every weight in a large model needs a lot of GPU memory: the weights, their gradients and the optimizer's bookkeeping, often 16 bytes or more per parameter. For a 7-billion-parameter model that's over 100 GB before activations.
Parameter-efficient fine-tuning (PEFT) freezes the original weights and trains a small set of new ones, typically well under 1% of the model. Results on narrow tasks are usually close to full fine-tuning, at a fraction of the memory and cost, and the output is a small adapter file instead of a whole new model. The most popular method, LoRA, is covered in PEFT and LoRA, and its memory-saving extension in QLoRA.
Evaluate before you ship
Training loss going down tells you the model is fitting your data. It doesn't tell you the model got better at the job. Before release, compare the fine-tuned model to the base model with your best prompt, on the held-out set:
- Task metrics: exact-match on fields, F1 for extraction, accuracy for classification, or rubric scores from expert review.
- Regression checks: general instructions it used to follow, safety refusals, other tasks in your product. Fine-tuning can make a model forget skills it didn't practise (catastrophic forgetting).
- Format validity: the share of outputs that parse against your schema.
- Cost and latency: often the real reason for the project. Measure them under realistic load.
Life after launch
A fine-tuned model is tied to its base model version. When the provider or the open-source community releases a better base, your adapter doesn't transfer; you retrain on the new base and re-run the evals. Plan for it:
- Keep the dataset, training config and eval set in version control together.
- Log production inputs and outputs (with consent and redaction) so the next dataset improves on the last one.
- Automate the train → evaluate → compare pipeline, so a retrain takes a day, not a quarter.
Fine-tuning works best as a repeatable process, not a one-off event.