How to Build a Domain-Specific LLM That Works
How to build a domain-specific LLM: pick one domain task, gather clean examples, adapt a base model with retrieval or fine-tuning, and test on real questions.
On this page
Short answer
To build a domain-specific LLM, pick one task in one domain, gather clean examples of that task written the way your experts write it, and adapt a base model with fine-tuning, retrieval, or both. Test it on real domain questions your team has already answered, and only ship it when it beats the general model on those questions.
What is a domain-specific LLM?
A domain-specific LLM is a language model that has been adapted to work well in one field, such as law, medicine, finance or engineering, instead of answering general questions about everything. It knows the terms, the document types and the style of answers that field expects.
A general model can write a passable summary of a contract, but it may miss the clause that matters or invent a term that does not exist in the field. A domain-specific model is trained or guided on real examples from that field, so its answers follow the field's rules and use its vocabulary correctly.
The difference is scope, not size. A smaller model that has seen thousands of real examples from your domain will often give better answers than a much larger model that has only seen general text. The work is in the data and the testing, not in building a bigger model.
Fine-tuning, retrieval or training from scratch?
The first decision is how to adapt the model, and most teams should not train a model from scratch. Training from scratch costs far more time and data than adapting a good base model, and it rarely gives better results for a single domain.
Use this table to pick the approach that fits your data and your budget.
| Approach | What you need | Best when | What it changes |
|---|---|---|---|
| Retrieval (RAG) | Your documents, searchable | Answers must cite your own material | What the model can look up |
| Fine-tuning | Hundreds of good examples | Answers need a fixed style or format | How the model writes |
| Prompting only | Clear instructions and examples | You are testing an idea | Nothing in the model itself |
| Training from scratch | Very large data and budget | Almost never for one domain | Everything, at high cost |
Most domain projects combine retrieval and fine-tuning: retrieval supplies the facts, and fine-tuning teaches the style. Start with retrieval, because it is cheaper to fix, then fine-tune only if the style or format is still wrong. For a deeper comparison of the two, see LLM fine-tuning services.
What domain data do you need?
You need examples of the exact task, written the way your experts do it. If the model will draft replies to customer questions, gather real questions and the replies your best staff sent. If it will summarise reports, gather real reports and the summaries your team wrote.
Quality matters more than volume. A few hundred clean examples, checked by someone who knows the domain, beat thousands of unreviewed examples. Remove personal data, fix errors, and drop examples where the expert answer is wrong or out of date, because the model will learn those mistakes too.
Check that your examples cover the hard cases, not just the easy ones. If all your examples are short, simple questions, the model will fail on the long, messy ones that matter most. Include edge cases, unusual terms and the documents your team finds hardest to write.
How do you build a domain-specific LLM, step by step?
Build it in six steps, and keep a domain expert involved at every step.
- Define one task and one success measure, such as correct answers to a set of test questions.
- Collect and clean the examples: real questions, real documents and real expert answers.
- Pick a base model that already handles your language and document types well.
- Add retrieval over your own documents so the model can look up facts instead of guessing them.
- Fine-tune on your examples only if the style, format or terminology is still wrong.
- Test on questions the model has never seen, scored by a domain expert, before anyone uses it.
Do not skip step six. A model that looks good on the examples it trained on can still fail on new questions, and only a fresh test set shows that. How to evaluate an LLM application explains how to build a test set your team can trust.
How do you know it works?
You know it works when it beats the general model on questions your team has already answered. Build a test set of real domain questions with answers written or checked by an expert, and score both models on the same set, on accuracy, on whether the answer follows the right format, and on whether it invents facts.
Count the errors by type, not just the total. A model that gets the facts right but writes in the wrong format needs different work from a model that writes beautifully but invents clauses. Fix the biggest error type first, then retest on the same set.
Ask the expert to review a sample of live answers every week after launch. Domains change, new terms appear, and a model that was right in January can drift by June. Regular review catches drift before users do. See LLM development for how teams run this review loop in production.
Example (hypothetical): a legal research assistant
Example (hypothetical): a small law firm wants a model that drafts short summaries of tenancy agreements. The team gathers 400 past agreements and the one-page summaries a senior lawyer wrote for each, removes all client names, and adds retrieval over the firm's own clause library.
On a test set of 60 agreements the general model answers 42 questions correctly, which is 70%. After fine-tuning on the 400 summaries and adding retrieval, the domain model answers 51 of the same 60 correctly, which is 85%. The remaining 9 errors are mostly missing dates, so the team adds a rule that every summary must list the dates it found.
The arithmetic shows the gain clearly: 51 minus 42 is 9 more correct answers out of 60, a rise of 15 points. The team ships the model only for internal drafts, with a lawyer checking every summary before it leaves the firm.
Common mistakes when building a domain-specific LLM
Most domain LLM projects fail for the same few reasons: training on messy data, testing on the training set, and shipping without an expert in the loop.
- Using unreviewed examples, so the model learns your team's mistakes
- Training from scratch when retrieval and fine-tuning would do
- Testing on the same examples the model trained on, which hides real errors
- Measuring only fluency, and never checking whether the facts are right
- Letting the model answer users directly with no expert review at launch
- Forgetting to retest when the domain's terms, rules or documents change
If you need help scoping the first pilot, how to build an AI proof of concept covers the same four-week approach for a single domain task.
Key takeaways
- A domain-specific LLM is a base model adapted to one field's terms, documents and answer style.
- Start with retrieval over your own documents; fine-tune only if the style is still wrong.
- Clean examples from your experts matter more than a large, unreviewed dataset.
- Test on fresh questions scored by an expert, and count errors by type.
- Keep an expert reviewing live answers, because domains change over time.
Frequently asked questions
How much data do I need to build a domain-specific LLM?
A few hundred clean examples of the exact task are usually enough to start, if they are checked by a domain expert. Retrieval needs your documents, not examples, so it can start sooner. Add more examples only after testing shows which errors they would fix.
Is fine-tuning better than retrieval for a domain LLM?
They solve different problems. Retrieval supplies facts from your documents, while fine-tuning teaches style and format. Most projects use both, starting with retrieval because it is cheaper to fix when the facts change.
Can a small team build a domain-specific LLM?
Yes, if the task is narrow. One task, one test set of 50 real questions, and a few hundred clean examples are enough for a first version. The work is mostly data cleaning and testing, not model building.
How do I stop a domain LLM from inventing facts?
Ground its answers in your own documents with retrieval, and test it on questions with known answers. Count invented facts as a separate error type, and do not ship until that count is low on fresh questions.
Should I train a model from scratch for my domain?
Almost never. Adapting a good base model with retrieval and fine-tuning gives better results for far less time and data. Training from scratch only makes sense when no base model handles your language or document type at all.
How often should I retest a domain-specific LLM?
Retest whenever the domain changes, such as new rules, new terms or new document types, and at least once a quarter. A weekly review of a small sample of live answers catches drift early.