Preparing Fine-Tuning Data: Chat Format, JSONL, Cleaning, Train and Validation Splits and Quality Checks

LLM Development 55 min min read Updated: Nov 21, 2026 Advanced
Preparing Fine-Tuning Data: Chat Format, JSONL, Cleaning, Train and Validation Splits and Quality Checks
Advanced Topic 3 of 3

Data Is the Main Ingredient

A model learns what the examples show. If your examples are messy or inconsistent, the model will be too. A few hundred excellent examples can be better than thousands of poor ones.

Typical Format

Most tools accept JSONL: one JSON object per line. A common shape is a list of chat messages. The exact field names depend on your provider or training library, so check its guide.

python import json rows = [ {"messages": [ {"role": "system", "content": "You write short, polite support replies."}, {"role": "user", "content": "Where is my order?"}, {"role": "assistant", "content": "Thanks for waiting. Please share your order number and I will check it right away."}]}, ] for r in rows: print(json.dumps(r))
Result

{"messages": [{"role": "system", "content": "You write short, polite support replies."}, {"role": "user", "content": "Where is my order?"}, {"role": "assistant", "content": "Thanks for waiting. Please share your order number and I will check it right away."}]}

Cleaning Steps

  1. Collect real, representative examples
  2. Remove duplicates and near duplicates
  3. Remove private data: names, emails, phone numbers, keys
  4. Fix wrong or inconsistent answers
  5. Keep the same style and format across examples
  6. Include some hard and edge cases
python import re, random data = [ ("Where is my order?", "Please share your order number."), ("Where is my order?", "Please share your order number."), ("My email is raj@example.com, help", "Sure, how can I help?"), ("Cancel my plan", "I can help you cancel it."), ("Refund status?", "Please share your order number."), ("Change address", "I can update your address."), ] seen, clean = set(), [] for q, a in data: if (q, a) in seen: continue seen.add((q, a)) q = re.sub(r"[\w.]+@[\w.]+", "[EMAIL]", q) clean.append((q, a)) random.seed(0); random.shuffle(clean) cut = int(len(clean) * 0.8) train, valid = clean[:cut], clean[cut:] print("kept", len(clean), "of", len(data), "| train", len(train), "| validation", len(valid)) print([q for q, _ in clean])
Result

kept 5 of 6 | train 4 | validation 1 | ['Cancel my plan', 'My email is [EMAIL], help', 'Where is my order?', 'Change address', 'Refund status?']

The demo removed one exact duplicate, replaced an email with a placeholder and split the data into training and validation parts. Real emails and names can take more rules, so use a proper privacy tool for real projects.

Train and Validation Sets

  • Training set: examples the model learns from
  • Validation set: examples it never trains on, used to check progress
  • Keep a separate test set for your final check
  • Never let the same example appear in both

Quality Checks

  • Read a random sample yourself
  • Check length and format consistency
  • Check label balance, for example not 95% one category
  • Test the tuned model against your evaluation set and compare with the original
Rights and privacy Make sure you may use the data, and remove personal data before training or sharing.

Practice

  1. Add three new examples and rerun the cleaning demo
  2. Add a rule that removes phone numbers
  3. Write five hard cases for your own task

Conclusion

Clean, consistent, rights-cleared data with a proper validation split is the base of a good fine-tune.

Quick Summary: JSONL; cleaning; splits; checks.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators