Skip to content

GuidePart of: Schema

SFT Dataset Format: JSONL Records, Examples and Checks

Published 6 min read

Two engineers at a desk in a dark office at night, reading rows of structured records on a large monitor in teal and green light.
On this page

The SFT dataset format is a JSONL file where each line is one training example. Most examples are a messages list of chat turns, each with a role (system, user, assistant or tool) and content. The model learns to write the assistant turns. Some sets use a simpler prompt and completion pair instead. Either way, one line is one complete example.

Supervised fine-tuning (SFT) means training a model on examples of the answers you want it to give. This guide covers the record shapes, which tokens the model learns from, how to turn an enterprise thread into examples, and the checks to run before training. For the wider set of record types, from pretraining text to agent logs, see what LLM training data looks like at each stage.

What does an SFT dataset example look like?

It looks like a short chat. Here is one fictional record from a support setting, pretty-printed for reading. In the file it sits on a single line.

{"messages": [
  {"role": "system", "content": "You answer billing questions for a field service company."},
  {"role": "user", "content": "Hi, invoice <ID_1> lists two call-out fees. We only had one visit."},
  {"role": "assistant", "content": "You're right, the second fee is a duplicate. I've credited it, and a corrected invoice goes to <EMAIL_1> today."}
]}

Three things make this a good example. The system turn sets the job. The user turn is a real question in real words. The assistant turn is the answer you would be proud to ship.

The tokens in angle brackets are typed placeholders. They replace an invoice number and an email address, so the record keeps its structure without exposing anyone. Our JSONL schema for conversation and ticket data defines the full set.

Which SFT data formats do training tools accept?

Most tools accept four shapes. They differ in two ways: plain text or chat turns, and one field or a prompt split from the answer.

Shape Fields Best for
Standard language modeling text Continued pretraining on documents
Conversational language modeling messages Multi-turn chat and assistants
Standard prompt-completion prompt, completion Single-step tasks such as classification or extraction
Conversational prompt-completion prompt and completion as message lists Chat tasks where only the final reply is the target

The Hugging Face TRL SFT Trainer docs list exactly these shapes and apply the model's chat template to the conversational ones. Hosted fine-tuning APIs are stricter. OpenAI's guide asks for the chat completions format in JSONL, with at least 10 lines.

Messages or prompt and completion?

Use messages when the model will hold conversations. Use prompt and completion when there is one input and one output, such as tagging a ticket with a category. Pick one shape per file and stick to it. Mixed shapes in one file are a common cause of silent bugs.

What about tool calls?

A tool-use example adds two kinds of turn. The assistant turn carries a tool_calls field with a function name and arguments. A tool turn returns the result. A final assistant turn then answers the user. Keep the tool definitions with the dataset, so the training run sees the same functions the model will see later.

Which part of an SFT record does the model learn from?

Only the assistant turns, in most setups. The other turns are context. This is called loss masking: the training step scores the model only on the tokens it should learn to produce.

In TRL, a prompt-completion set trains on the completion by default. For a conversational set you switch on assistant_only_loss. If you train on every token instead, the model also learns to imitate your users. That can teach it typos, angry phrasing and half-finished questions.

This has a direct effect on dataset design. Anything you want the model to say must be in an assistant turn. Anything you only want it to read can sit in system, user or tool turns.

Three people in a dim office at night mapping a conversation onto a glass board while two colleagues point at the boxes.

How do you turn enterprise data into SFT records?

You map each thread or ticket onto roles, then cut it into examples. Enterprise sources don't arrive in chat format. A support ticket has a customer, one or more agents, internal notes and status changes. A Slack thread has many people and no assistant at all.

1. Choose the role the model will play

Decide who the model is. In a support set, it is usually the agent. Every agent reply becomes an assistant turn. Customer messages become user turns.

2. Decide what to do with internal notes

Internal notes are not visible to the customer. Drop them, move them to a system turn as context, or keep them as a separate reasoning field if your training code supports one. Write the choice down in the datasheet, since it changes what the model learns.

3. Cut long threads into examples

A ticket with four agent replies can give four examples. Each one ends at a different agent reply and holds everything before it. This multiplies examples without inventing text. Keep all cuts from one ticket in the same split.

4. Filter on outcomes

Enterprise records often carry an outcome: solved, reopened, escalated, rated. Train on the threads that went well. A reopened ticket shows what not to say, which is more useful for preference data than for SFT.

5. Replace personal data before anything else

Build records only from text where names, contact details and account numbers are already replaced. Our guide to PII redaction for training data covers methods and recall checks. The support ticket dataset spec lists which fields to keep.

How many SFT examples do you need?

Not many, if they are good. The OpenAI supervised fine-tuning guide reports improvements from 50 to 100 examples and suggests starting with 50 well-crafted demonstrations. Then you evaluate, and add data where the model is weak.

That advice is for narrow tasks on a hosted model. Broader goals need more. A model that must handle every billing, scheduling and complaint flow for a whole industry needs thousands of varied examples. Coverage matters more than count. Ten thousand near-identical password resets teach one thing.

One clean, representative example beats ten noisy ones. Volume only helps once quality and coverage are under control.

What checks should an SFT dataset pass before training?

Run these on every file, before the first training job. Most take a few lines of code.

  1. Parse every line. Each line must be valid JSON with the expected top-level fields.
  2. Check roles. Roles come from the allowed set, and every example ends with an assistant turn.
  3. Check turn order. No two assistant turns in a row unless a tool turn sits between them.
  4. Measure length. Count tokens with the target model's tokenizer. TRL truncates at 1024 tokens by default and keeps the start, so long threads lose their ending, which is often the answer.
  5. Scan for leaks. Search for raw email addresses, phone numbers, IBANs and secrets that slipped past redaction.
  6. Find duplicates. Exact and near duplicates inflate some behaviours and leak across splits.
  7. Split by source. Put all examples from one thread, team or customer in the same split, so the test set is truly unseen.
  8. Read a sample. Twenty random records, read by a person, catch problems no script finds.

Ask a supplier to ship the results of these checks with the delivery. A datasheet with record counts, token counts per language and the redaction method makes acceptance much faster.

What should you put in an SFT data spec?

Name the shape, the roles and the masking you expect. Then add the numbers you will accept against.

  • Shape: messages or prompt and completion, plus whether tool turns are allowed.
  • Role mapping: who the assistant is, and what happens to notes and bot messages.
  • Cutting rule: one example per thread, or one per assistant reply.
  • Limits: maximum tokens per example, measured with your tokenizer.
  • Filters: which outcomes qualify.
  • Privacy: the placeholder set and the minimum redaction recall.
  • Splits: the grouping key for train, validation and test.

A spec this clear lets two suppliers deliver files you can load with the same code. It also makes the acceptance test a script rather than a debate.

FAQ

Questions about this guide

Is SFT data always JSONL?

Nearly always for delivery and fine-tuning APIs, because one object per line is easy to stream, split and validate. Large sets are sometimes stored as Parquet with the same fields. The training library converts either into tokens with the model's chat template.

What is the difference between SFT data and instruction data?

Instruction data is a kind of SFT data. It pairs an instruction with the answer you want. SFT data is the wider term for any demonstration the model should copy, including multi-turn conversations and tool calls.

Should the system prompt be in every SFT record?

Include it if the model will see a system prompt in production. Use the same wording you plan to deploy, or a small set of variants. A model trained without one can behave differently once a system prompt appears.

Can one support ticket become several SFT examples?

Yes. A ticket with four agent replies can yield four examples, each ending at a different reply. Keep all of them in the same split, or the model will be tested on text it already saw in training.

How do I keep personal data out of an SFT dataset?

Replace names, contact details and account numbers with typed placeholders before records are built, and check a sample by hand. Placeholders keep who said what without saying who anyone is. Ask the supplier for its recall figures per data type.

What does an SFT dataset example with a tool call look like?

The assistant message carries a tool_calls field instead of plain content, a tool message returns the result, and a final assistant message answers the user. The tool definitions travel with the record or the training config, so the model learns when to call them.

Related