Cross-validation for LLMs: why it matters when testing
Cross-validation for LLMs explained: how k-fold testing gives an honest accuracy score, and why one test split can mislead you about which model to ship.
Updated
Cross-validation tests a model on documents it never trained on, and it uses every labeled document as test data exactly once. For an LLM, you split the labeled set into folds, train on most of them, score the held-out fold, and repeat until every fold has taken a turn as the test. The average is a more honest number than the score from one split, and the spread between folds tells you how much to trust it.
Why one test split can mislead you
A single test set is one sample of your documents. If it happens to hold short, clean contracts, or too many of one document type, the score reflects that luck more than the model. Change the split and the ranking of two close models can flip. That matters most when you compare a fine-tuned model with a large general model, because the gap is often small on any one split.
Leakage is the bigger risk. If the same contract, or a near copy of it such as a redline or a template with different names filled in, lands on both sides of the split, the model has effectively seen the answers. The score rises and tells you nothing about production. Split by document, never by chunk, so every passage from one contract stays on one side.
How k-fold works, with a worked example
Suppose you have 400 labeled contracts, each marked with its governing-law clause and its termination clause, and you choose five folds. Shuffle them with a fixed seed, then cut them into five groups of 80.
Run 1 trains on folds 2 to 5, which is 320 contracts, and scores fold 1. Run 2 trains on folds 1, 3, 4 and 5 and scores fold 2. Keep going until fold 5 has been the test. Each contract is scored once, by a model that never saw it. Chunk the contracts only after the split, so the 320 training contracts produce the training passages and the 80 test contracts produce the test passages.
The cost is five training runs instead of one. For most extraction tasks, that is small next to the cost of shipping the wrong model. Use the same folds for every model you compare, or the comparison is not fair.
What the score looked like on a public exam
CUAD is a public set of 510 commercial contracts, and we scored it with 5-fold cross-validation so that every contract was graded by a model that had not trained on it. Our most accurate model reached 0.717 exact-quote accuracy, against 0.635 for Claude Opus, and it led Opus in every fold. The full results show every model and fold.
The number means what the exam measures: exact quotes of ten clause types, taken from lawyer-marked text. It is one example of the method. It does not promise the same result on your documents, and your own labeled data decides what your number means.
Mistakes that inflate LLM test scores
Most inflated scores come from one of these:
- Tuning on the test fold. Choose prompts, output formats and thresholds on a validation split carved out of the training folds, then score the test fold once at the end.
- Splitting by chunk. Passages from one contract land on both sides, and the model learns wording it will be tested on.
- Reporting the best fold. Fold scores vary, so the best one is a selection, not a result. Report the mean and the lowest fold together.
- Redrawing folds between runs. Fix the seed and write it down. A new shuffle makes last month’s number incomparable to this month’s.
- Unequal setups. Every model gets the same inputs, the same output schema and the same scoring rule. A model given a longer prompt or a looser match rule is not being compared fairly.
A checklist before you trust the number
Before a model choice goes to a client or a board, work through this list:
- Write down the split rule (by document) and the seed.
- Freeze the folds before you compare any two models.
- Search for near-duplicates across folds: redlines, templates, and the same counterparty under different names.
- Score every fold, then read ten wrong answers from the weakest fold. Sort each one into a labeling error or a model error.
- If the decision is expensive, keep a holdout that no experiment has touched, and score it once for the final claim.
When cross-validation is worth the effort
Use cross-validation when your labeled set is small or medium and the decision is expensive. A very large, cleanly separated test set can be enough on its own, because one big split is less sensitive to which documents land in it. Cross-validation is for when you need a score you can defend to someone who will check it.
The trade-off is compute against certainty. More folds mean more runs, and for most tasks they change the conclusion very little. Freeze the folds once you start comparing models, so every new model lands in the same table.
Our evaluation guide covers building the test set itself, and how much data you need covers how many labeled examples to start with. The same method suits contract clause extraction, and for how to read published numbers see reading an LLM benchmark. For the basics of the whole company, start at the homepage.
If you want to see how this test would look on your own documents, book a free audit or a call with the button below. We will look at the task, the data you have and how you score it today.
Questions
What is cross-validation for an LLM?
It scores a model on documents it never trained on, by rotating which slice of the labeled data is held out. Each document is scored once by a model that did not see it during training. The average across the rotations is the number to compare between models.
How many folds should I use?
Five is a common default, and it is what we used on our public exam. More folds mean more training runs and little extra certainty for most tasks. Fewer folds give each test set more documents but leave less training data per run.
Is cross-validation different from a train and test split?
A single split tests on one holdout, so the score depends on which documents landed in it. Cross-validation repeats the split so every document is tested once. It costs more compute, but the score is much less likely to flatter the model by accident.