Book a free call

How to Train Domain-Specific LLMs: A Practical Guide

Training a domain-specific LLM means teaching a general model your field's language and tasks. Learn when to fine-tune, what data you need, and how to test it.

Hertiv engineering teamReviewed by a senior engineer
7 min read
How to Train Domain-Specific LLMs: A Practical Guide
On this page

Short answer

Training a domain-specific LLM means adapting a general language model so it handles the language, facts and tasks of one field, such as support, legal or medical work. Most teams do this with fine-tuning on their own examples, or with retrieval over their own documents, rather than training a model from scratch.

What is a domain-specific LLM?

A domain-specific LLM is a language model adapted to one field, so it understands the terms, the documents and the typical tasks of that field. A general model knows a little about many subjects; a domain model is tuned to answer well on the subjects your team actually works with.

It differs from a general model in three ways: it uses the vocabulary of the field, it follows the style and format your work needs, and it is tested against real tasks from that field rather than general questions. A support model, for example, is judged on whether its answers match the help articles, not on trivia.

The three ways to adapt a model are:

Method What it does When to use it
Prompting Gives instructions and examples Small task, quick test
Retrieval Answers from your documents Facts change often
Fine-tuning Trains on your examples Style and tasks are stable

Most teams start with prompting, add retrieval when facts matter, and fine-tune only when the behaviour itself needs to change. For the tuning step itself, LLM fine-tuning services covers what a tuning project involves.

When should you train a domain model, and when not?

You should train a domain model when the general model keeps making the same mistakes on your tasks: it uses the wrong terms, ignores your format, or cannot follow a multi-step task your team does every day. If the errors are the same each time, training on your own examples can fix them.

You should not train one when the problem is missing facts. If the model gives a wrong price or an outdated policy, the fix is retrieval over current documents, not training. Training bakes knowledge in at one point in time, so it goes stale as soon as the facts change.

Train when:

  • The style is stable. Answers should always follow the same format, tone and length.
  • The vocabulary is specific. Your field uses terms the general model treats as rare or vague.
  • The task repeats. The same task happens hundreds of times a month, so small gains add up.
  • You have labelled examples. At least a few hundred real examples with known good answers.

Do not train when the facts change weekly, when you have no labelled examples, or when a better prompt and a retrieval step would fix the same problem for less work.

What data do you need to train a domain LLM?

You need labelled examples of the real task, written in the form the model will see at run time: the input it receives and the output you want. The quality of those examples matters far more than the number of them.

A useful starting set is a few hundred to a few thousand examples, covering the main cases and the common edge cases. Each example should be reviewed by someone who knows the field, because a wrong example teaches the model to be wrong in the same way.

Good training data has:

  • Real inputs. Actual questions, tickets or documents from your work, not invented ones.
  • Known good outputs. Answers a skilled person wrote or approved, in the format you want.
  • Coverage of edge cases. The tricky cases, such as ambiguous questions and requests the model should refuse.
  • Consistent style. The same tone, length and structure across examples, so the model learns one pattern.
  • No personal data. Names, emails and account details removed before training.

Keep a separate evaluation set of 100 to 200 examples that the model never trains on. That set is how you know whether the training actually helped. For how to test a model properly, how to test AI models covers evaluation sets and what to measure.

How do you train a domain-specific LLM step by step?

You train a domain-specific LLM by preparing the data, choosing a base model, running a short training pass, and testing the result against your evaluation set. The whole loop is short on purpose: train a little, test, then decide whether to train more.

  1. Pick a base model. Choose a general model that already handles your language and task type well, and check its licence allows fine-tuning.
  2. Prepare the data. Clean the examples, remove personal data, and split them into training and evaluation sets.
  3. Choose the method. Full fine-tuning changes all weights; a lightweight adapter changes a small part and is cheaper to run and to replace.
  4. Run a short training pass. Train for a small number of steps on a sample, then test, before committing to a full run.
  5. Evaluate on real tasks. Score the model on the evaluation set, and compare it with the general model on the same set.
  6. Check for new mistakes. Look for cases the general model got right and the tuned model now gets wrong.
  7. Deploy with a fallback. Ship the tuned model with a review queue and a way to fall back to the general model if it fails.

Keep the training run small at first. A short run that you can repeat is more useful than a long run you cannot afford to redo. For scoping a first AI project, how to build an AI proof of concept shows how to set a clear test.

Example (hypothetical): a support team tunes a model on its own answers

Example (hypothetical): a support team answers 500 questions a day. It collects 2,000 past questions with the answers staff actually sent, and a senior agent reviews them. Writing and reviewing those 2,000 examples takes about 3 minutes each, which is 6,000 minutes, or 100 hours of staff time.

The team splits the data: 1,800 examples for training and 200 for evaluation. Before tuning, the general model answers 148 of the 200 evaluation questions correctly, which is 74%. After a short fine-tuning run, it answers 172 of the 200 correctly, which is 86%.

The team also checks the 28 questions it still gets wrong. Most are cases where the help article is out of date, so the fix is to update the article and add retrieval, not to train more. The tuned model ships with a review queue for answers it is unsure about, and the team re-runs the evaluation set every month.

The lesson is the split: training fixed the style and the common cases, while retrieval and fresh articles fixed the facts. Neither step alone would have reached the same result.

How do you know the training worked?

You know the training worked when the tuned model scores better than the general model on your evaluation set, and when the improvement holds on new questions it has never seen. A score that only rises on the training data means the model memorised the examples, not that it learned the task.

The checks that matter:

Check What it shows How to read it
Evaluation score Correct answers on unseen cases Higher than the base model
Error review What the tuned model gets wrong No new error types
Style check Format, tone and length Matches the examples
Stability Answers on repeated prompts Same answer each time
Cost per answer Running cost after tuning Within budget

Review the errors by hand. A score tells you how many answers were right; reading the wrong ones tells you why. For the technology underneath, what is machine learning explains training and evaluation in plain terms.

What are the common mistakes?

The most common mistakes when training a domain LLM are training on unreviewed data, training for facts instead of behaviour, and skipping the evaluation set. Each one wastes the training run and leaves the team with a model they cannot trust.

  • Unreviewed data. Examples nobody checked teach the model the same mistakes the team already makes.
  • Training for facts. Facts that change need retrieval, not training, or the model goes stale fast.
  • No evaluation set. Without a held-out set, there is no honest way to know if training helped.
  • Too much training. Long runs on small data make the model repeat the examples instead of learning the task.
  • Personal data in training. Names and account details in the data can leak into answers later.
  • No fallback. A tuned model that fails needs a review queue and a way back to the general model.

Key takeaways

  • Most teams adapt a model with prompting, retrieval or fine-tuning, not training from scratch
  • Fine-tuning fixes stable behaviour and style; retrieval fixes changing facts
  • A few hundred reviewed examples beat thousands of unreviewed ones
  • A held-out evaluation set is the only honest test of whether training helped
  • Ship with a review queue and a fallback to the general model

Frequently asked questions

What is the difference between fine-tuning and retrieval?

Fine-tuning trains the model on your examples so its behaviour changes: style, format and how it handles your tasks. Retrieval leaves the model unchanged and gives it your documents at run time, so it can answer from current facts. Use fine-tuning for stable behaviour and retrieval for facts that change.

How many examples do I need to fine-tune an LLM?

A useful starting set is a few hundred to a few thousand reviewed examples of the real task. More helps, but a clean, reviewed set beats a large, messy one. Start small, evaluate, and add more examples only for the cases the model still gets wrong.

Can I train a domain LLM on my own documents?

Yes, but remove personal data first and check you have the right to use the documents for training. Contracts, tickets and help articles are common sources. Keep a separate evaluation set that the model never trains on, so you can measure the result honestly.

Is training a model from scratch worth it?

Almost never for a single team. Training from scratch needs huge amounts of data, compute and time, and the result is usually worse than a fine-tuned general model. Start from a general base model and adapt it to your field.

How do I stop a fine-tuned model from giving wrong answers?

Ground it in your own documents with retrieval, require a source for factual answers, and keep a human review queue for anything uncertain. Review the errors on your evaluation set and fix the data or the documents behind them.

How long does it take to train a domain-specific LLM?

A first fine-tuning run on a small dataset usually takes hours to a day of compute, but preparing and reviewing the data takes weeks. The data work is the long part, so start collecting and reviewing examples before you book any compute.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: AI and agent systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Planning to adapt an LLM to your field? Talk to Hertiv.

A senior engineer replies within one business day. Or see our LLM Fine-Tuning service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to [email protected].

Prefer email? Write to [email protected]
Estimate costBook a call