DPO dataset format: chosen and rejected pairs with examples
For agent builders4 min read

The DPO dataset format is built from preference pairs: for each prompt, one answer marked chosen and one marked rejected. In TRL this is the preference type, with a prompt, a chosen and a rejected column. This post shows the formats, a JSONL example, how to convert between them, and a script that finds pairs that teach nothing.
The DPO dataset format: the preference type
The TRL docs describe a preference dataset as one where the model is trained to select a chosen response over a rejected one for the same prompt. The DPO trainer expects this type, and the guide recommends an explicit prompt column.
Source: TRL: dataset formats and types(opens in a new tab)
In conversational form, one row looks like this. In a file, it sits on one line.
{"prompt": [{"role": "user", "content": "What color is the sky?"}], "chosen": [{"role": "assistant", "content": "It is blue."}], "rejected": [{"role": "assistant", "content": "It is green."}]}There is also an implicit prompt form, where the prompt is repeated at the start of both chosen and rejected and there is no prompt column. The guide says it recommends explicit prompts whenever possible, and that the reward trainer prefers the implicit form.
{"chosen": [{"role": "user", "content": "What color is the sky?"}, {"role": "assistant", "content": "It is blue."}], "rejected": [{"role": "user", "content": "What color is the sky?"}, {"role": "assistant", "content": "It is green."}]}Converting between forms
TRL provides helpers. The extract_prompt function turns the implicit form into the explicit one, and unpair_preference_dataset turns pairs into single completions with a label, which the unpaired preference type uses.
from datasets import Datasetfrom trl import extract_prompt dataset = Dataset.from_dict({ "chosen": [[{"role": "user", "content": "What color is the sky?"}, {"role": "assistant", "content": "It is blue."}]], "rejected": [[{"role": "user", "content": "What color is the sky?"}, {"role": "assistant", "content": "It is green."}]],})dataset = dataset.map(extract_prompt)The guide carries a warning for the unpairing step. Chosen answers can be both good or both bad, so confirm that every chosen answer is genuinely good and every rejected one genuinely bad before you convert, for example with absolute ratings.
Find the bad pairs yourself
A pair teaches the model only if the two answers differ in a way that matters. This script checks the cheap problems: identical answers, an empty side, and a chosen answer that is much longer, which can teach the model that longer is better.
import json def check_pair(line, max_len_ratio=3.0): row = json.loads(line) c = row["chosen"][-1]["content"] r = row["rejected"][-1]["content"] problems = [] if not c.strip() or not r.strip(): problems.append("empty side") if c.strip() == r.strip(): problems.append("chosen equals rejected") if len(c) > max_len_ratio * max(len(r), 1): problems.append("chosen is far longer") return problems line = json.dumps({ "prompt": [{"role": "user", "content": "Capital of France?"}], "chosen": [{"role": "assistant", "content": "Paris is the capital of France."}], "rejected": [{"role": "assistant", "content": "Paris."}],})print(check_pair(line))Who decides chosen and rejected
The labels come from a person, a model, or a mix. A human ranker reads two answers and picks the better one by a written rule. The rule is what you are really training, so spell it out: correct before polite, safe before helpful, shorter when equal. Ask the ranker to write one sentence on why. Those reasons let you audit disagreements later.
- Write the ranking rule on one page, with three worked examples.
- Have two rankers label the same sample, and compare their picks.
- Review the pairs where they differ. Fix the rule, not the people.
- Drop pairs where neither answer is acceptable. A less bad answer is a poor target.
- Check that length and style do not predict the label.
Keep a held-out slice of pairs that the training never sees. After training, compare how often the model's answers match the chosen side on that slice. If the match rate does not move, or moves only on pairs where chosen is longer, the dataset taught style and not quality. That check costs little and is far easier to do before the data is large.
Start smaller than you think. A few hundred carefully ranked pairs on one narrow behavior, such as declining unsafe requests politely, give you something you can test and debug. Train on that, read the outputs, and only then collect more. A large pile of pairs ranked by a vague rule teaches the model the vague rule.
Preference data of this kind is what Curatrain calls preference ranking (RLHF), done by specialists who can tell which of two answers is correct in their field. For you as a builder, the important point is the same: a pair is only as good as the judgment behind it.