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.
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."}]}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.
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.
Tools used in this guide
AI JSONL →Audit every JSONL line for syntax errors, OpenAI ChatML role alternation, missing assistant turns, and per-line BPE token limits.
OpenAI Fine-Tune ConverterConvert Alpaca, ShareGPT, CSV, or prompt/completion pairs into validated OpenAI ChatML messages[] fine-tuning JSONL.
Convert CSV/TSV tables into raw JSONL, OpenAI ChatML messages[], Alpaca, or ShareGPT fine-tuning records locally.
JSONL Splitter & MergerSplit large JSONL datasets into exact-line ZIP shards or merge and deduplicate multiple JSONL files in browser memory.
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
How OpenAI Strict Mode, Anthropic Tool Use, Zod v4, and Pydantic v2 map through a Unified Type IR—and how to generate all three locally.
Convert HuggingFace Parquet Files to JSONL & CSV Without PythonConvert HuggingFace Parquet shards to JSONL, JSON, or UTF-8 BOM CSV locally in browser RAM using hyparquet and sql.js WASM—zero Python or uploads required.
OpenAI Batch API JSONL: Unwrapping, Sharding & Validation GuidePrepare OpenAI Batch API JSONL files locally: unwrap nested JSON arrays, deduplicate lines, split shards into ZIP archives, and flatten results to CSV.
Offline LLM BPE Token Counting & Prompt Cost Optimization GuideCount exact o200k_base and cl100k_base BPE tokens offline, visualize token boundary segments, prune null JSON fields, and cut prompt API costs locally.