Engineering Guides6 min readUpdated: 2026-11-24

OpenAI & Anthropic Fine-Tuning JSONL Dataset Preparation Guide

Format, convert, validate, deduplicate, and shard ChatML JSONL fine-tuning datasets from CSV, Alpaca, ShareGPT, or Parquet locally in browser RAM.

Quick Answer

OpenAI fine-tuning requires valid UTF-8 JSONL where every line holds a messages array alternating system -> user -> assistant and ending on assistant. Validate every line, enforce per-line BPE token caps, and convert CSV/Alpaca/Parquet sources locally before uploading to your model provider.

Anatomy of a valid ChatML fine-tuning JSONL record

Unlike standard JSON files wrapped in [ ... ], fine-tuning JSONL places one complete JSON object on each newline with zero trailing commas between lines. Missing assistant turns, empty content strings, or unescaped literal newlines inside quotes cause entire training uploads to fail.

Run every training shard through DataTo JSONL Validator to catch exact line numbers, role alternation errors, and lines exceeding your maxTokensPerLine BPE budget.

{"messages":[{"role":"system","content":"You are concise."},{"role":"user","content":"What is Parquet?"},{"role":"assistant","content":"A columnar binary format."}]}

Validate JSONL dataset lines →

Converting Alpaca, ShareGPT, CSV, and Parquet to OpenAI JSONL

Open-source datasets frequently ship as Alpaca {instruction, input, output}, ShareGPT {conversations}, CSV spreadsheets, or HuggingFace .parquet files. DataTo OpenAI Fine-Tune Converter and Parquet to JSONL normalize them into valid messages[] JSONL strictly in browser RAM.

Convert Alpaca/CSV to OpenAI JSONL →

Deduplicating and sharding huge corpora before training

Duplicate training rows waste compute and bias model evaluations. Use JSONL Splitter & Merger to deduplicate exact records and split or merge .jsonl files into fixed-line ZIP shards locally.

Deduplicate & shard JSONL to ZIP →

Tools used in this guide

AI JSONL →

Related formats

Related Comparisons

Frequently asked questions

Why does OpenAI reject JSONL lines ending with a user message?

Supervised fine-tuning trains the model to predict the final assistant turn; any conversation ending on user or system has no completion target.

Can I convert Parquet rows directly from HuggingFace datasets to JSONL?

Yes. Drop any .parquet file into Parquet to JSONL to stream typed rows into .jsonl locally.

Does JSONL Validator estimate per-line token counts?

Yes. It validates both JSON syntax and BPE token thresholds per line so oversized rows can be pruned before training.

Authoritative References

More engineering guides