Dataset Quality Validation for LLM Fine-Tuning: Audit and Cleaning
You launched fine-tuning on 100 A100s, spent three days, and the model outputs incoherent gibberish? Or worse—confidentiality leaked? The cause is almost always the dataset. We've seen it dozens of times: in one project, after training, the model started outputting passwords from the training data—it turned out that in QA examples, the answer contained the next question. Empty strings, truncated texts, non-compliance with instructions—all of these kill the model if you don't perform systematic validation before launch.
For example, in a dataset of 50,000 examples, we found 6,000 exact duplicates and 2,000 truncated responses. After cleaning, the models showed a 15% accuracy improvement. Our service checks the dataset in 1–2 days and delivers a detailed report with recommendations. You receive a turnkey dataset ready for training.
How dataset validation prevents model degradation
A bad dataset is not just lost GPU hours. It's the risk of getting a model with low accuracy, bias, or vulnerability to prompt injection. Our experience shows: after validation, the pass rate jumps from 60% to 95% on average due to removing duplicates and truncated examples. The alignment score also rises—we fix instructions that misled the model. The average savings on retraining range from 300,000 to 1,000,000 rubles.
Validation Levels
We use three validation levels, each covering its own class of problems.
Level 1 — Technical (Automated)
Here we check basic things: empty strings, token length, text truncation, encoding, duplicates. All of this can be automated with a script, but it's important not to miss threshold values.
from dataclasses import dataclass
import pandas as pd
@dataclass
class ValidationReport:
total_examples: int
issues: dict
pass_rate: float
recommendations: list[str]
class DatasetValidator:
def validate(self, dataset: list[dict]) -> ValidationReport:
issues = {
'empty_outputs': [],
'too_short': [],
'too_long': [],
'truncated': [],
'encoding_issues': [],
'near_duplicates': [],
}
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-hf")
for i, ex in enumerate(dataset):
output = ex.get('output', '')
# Empty outputs
if not output.strip():
issues['empty_outputs'].append(i)
continue
# Length in tokens
tokens = tokenizer.encode(output)
if len(tokens) < 5:
issues['too_short'].append(i)
elif len(tokens) > 2000:
issues['too_long'].append(i)
# Potentially truncated text (ends with unfinished phrase)
if output.strip()[-1] not in '.!?])"\'':
if len(tokens) > 500: # Long text without ending
issues['truncated'].append(i)
# Encoding issues
try:
output.encode('utf-8').decode('utf-8')
except (UnicodeEncodeError, UnicodeDecodeError):
issues['encoding_issues'].append(i)
total_issues = sum(len(v) for v in issues.values())
pass_rate = 1 - total_issues / len(dataset)
return ValidationReport(
total_examples=len(dataset),
issues=issues,
pass_rate=pass_rate,
recommendations=self._generate_recommendations(issues, len(dataset))
)
Level 2 — Semantic (Automated)
Here we use an LLM-as-judge: the model evaluates how well the output matches the instruction. This is especially important for tasks requiring exact command following. Our pipeline is 10 times faster than manual review and never gets tired.
class SemanticValidator:
def check_instruction_output_alignment(self, dataset: list[dict],
sample_size: int = 200) -> float:
"""How well output corresponds to instruction"""
sample = random.sample(dataset, min(sample_size, len(dataset)))
alignment_scores = []
for ex in sample:
score = self._compute_alignment(
ex['instruction'], ex.get('input', ''), ex['output']
)
alignment_scores.append(score)
return np.mean(alignment_scores)
def _compute_alignment(self, instruction: str, input: str, output: str) -> float:
"""LLM-judge for relevance evaluation"""
prompt = f"""Does this output correctly address the instruction?
Instruction: {instruction}
Input: {input}
Output: {output[:500]}
Rate relevance 1-5, return only number."""
response = llm_client.complete(prompt, max_tokens=5)
try:
score = int(response.strip()) / 5.0
except ValueError:
score = 0.5 # Uncertainty → average score
return score
Level 3 — Content (Manual Review)
Automation doesn't see everything. We take a stratified sample (by response length) and send it for expert review. This catches logical errors, systematic biases, and context leakage.
def sample_for_human_review(dataset: list[dict],
n: int = 100) -> list[dict]:
"""Stratified sample for manual review"""
short = [ex for ex in dataset if len(ex['output'].split()) < 50]
medium = [ex for ex in dataset if 50 <= len(ex['output'].split()) < 200]
long = [ex for ex in dataset if len(ex['output'].split()) >= 200]
sample = []
per_stratum = n // 3
for stratum in [short, medium, long]:
sample.extend(random.sample(stratum, min(per_stratum, len(stratum))))
return sample
Why automated checking is not enough?
Automation catches 80% of technical issues but misses semantic pitfalls. For example, in a dataset of 50,000 examples, we found 12% duplicates—the model simply memorized them. Manual review uncovered 30 examples with context leakage: the answer contained information from a future dialogue. Only a combination of three levels gives confidence before training.
Final Report Before Training
We consolidate everything into a single report with a clear verdict: GO or NO-GO.
def generate_pre_training_report(dataset: list[dict]) -> str:
validator = DatasetValidator()
semantic_val = SemanticValidator()
tech_report = validator.validate(dataset)
alignment_score = semantic_val.check_instruction_output_alignment(dataset)
report = f"""
## Dataset Validation Report
**Total examples:** {tech_report.total_examples:,}
**Technical pass rate:** {tech_report.pass_rate:.1%}
**Instruction-Output alignment:** {alignment_score:.2f}/1.0
### Issues Found:
- Empty outputs: {len(tech_report.issues['empty_outputs'])}
- Too short (<5 tokens): {len(tech_report.issues['too_short'])}
- Too long (>2000 tokens): {len(tech_report.issues['too_long'])}
- Potentially truncated: {len(tech_report.issues['truncated'])}
- Near-duplicates: {len(tech_report.issues['near_duplicates'])}
### Recommendations:
{chr(10).join('- ' + r for r in tech_report.recommendations)}
**GO / NO-GO:** {'GO' if tech_report.pass_rate > 0.9 and alignment_score > 0.7 else 'NO-GO — fix issues before training'}
"""
return report
The threshold for go/no-go: technical pass rate > 90%, alignment score > 0.70. At alignment < 0.70, the dataset contains examples where output does not answer the instruction, which actively degrades the model.
What is included in the validation work?
| Step | Result | Timeline |
|---|---|---|
| Technical audit | List of problematic examples, graphs | 1 day |
| Semantic analysis | Alignment score, low-alignment examples | 1 day |
| Expert review | 100+ example sample, content report | 2 days |
| Final report | GO/NO-GO, recommendations, cleaned dataset | +1 day |
Turnkey: you receive a cleaned dataset with quality metrics and recommendations for improvement. Evaluate your dataset in 1 day—get a consultation.
Typical errors we find
| Error type | Example | Impact on model |
|---|---|---|
| Data leakage | Answer contains context from the next question | Model memorizes future information, breaches causality |
| Systematic biases | Model tends to use masculine gender | Bias, reduced quality on minority groups |
| Tone mismatch | Scientific style instead of conversational | Model doesn't follow style, user disappointed |
All these issues are recorded in the report, and we provide specific fixes.
How to order dataset validation?
- Send us the dataset in JSONL or CSV format.
- We perform technical audit in 1 day.
- Semantic analysis and sample for manual review – another 1 day.
- You receive the report and cleaned dataset.
More on quality metrics
We calculate distribution length, overlap score, lexical diversity. All metrics are visualized so you see the full picture.Our experience and guarantees
Over 5 years, we have conducted more than 50 audits for startups and large companies. Our engineers hold certifications from PyTorch and Hugging Face. We guarantee data confidentiality and accuracy of assessment. Contact us — we will review your dataset for free and propose an optimal validation plan.







