# Preparing instruction datasets for supervised fine-tuning



Learn how to format, clean, and synthesize high-quality instruction datasets for Supervised Fine-Tuning (SFT) to build better specialized LLMs.



Data · 2026-08-01 · 4 min read



Supervised Fine-Tuning (SFT) is the critical bridge between a raw base model and a functional AI assistant. While base models excel at predicting the next token, SFT teaches them to follow instructions, maintain a specific persona, and output data in structured formats.

However, the quality of your fine-tuned model is directly proportional to the quality of your training data. A dataset with inconsistent formatting, noisy labels, or poor diversity will lead to a model that hallucinates or fails to follow prompts. This guide covers the practical workflow for preparing high-quality instruction datasets for SFT.

## 1. Choosing Your Data Format
Most modern fine-tuning libraries, such as Axolotl or Hugging Face's TRL, expect data in one of two primary formats: **Instruction-Input-Output** or **Conversational (ChatML)**.

For SFT, the conversational format is increasingly preferred because it handles multi-turn dialogues more naturally. A standard JSONL entry for conversational tuning typically looks like this:

```json
{
  "messages": [
    {"role": "system", "content": "You are a helpful coding assistant."},
    {"role": "user", "content": "How do I reverse a list in Python?"},
    {"role": "assistant", "content": "You can use the `.reverse()` method or slicing `[::-1]`."}
  ]
}
```

## 2. Data Synthesis and Augmentation
Getting thousands of hand-written examples is expensive. Most engineers use a "Teacher Model" (like a larger Llama 3 or Mixtral variant) to generate synthetic instructions.

If you have a collection of raw documents, you can use a Python script to transform them into instruction pairs. The goal is to generate a diverse set of questions that your raw data can answer.

```python
import json

def format_sft_entry(system_prompt, user_query, assistant_response):
    return {
        "messages": [
            {"role": "system", "content": system_prompt},
            {"role": "user", "content": user_query},
            {"role": "assistant", "content": assistant_response}
        ]
    }

# Example of converting a raw internal FAQ to SFT format
raw_data = [
    {"q": "API Limit?", "a": "1000 requests per second."}
]

formatted_data = [
    format_sft_entry(
        "You are a technical support bot for Podstack.",
        item['q'],
        item['a']
    ) for item in raw_data
]

with open("train.jsonl", "w") as f:
    for entry in formatted_data:
        f.write(json.dumps(entry) + "\n")
```

## 3. Cleaning and Quality Control
Before you touch a GPU, you must prune your dataset. Here are three non-negotiable checks:

*   **Length Filtering:** Remove examples that are too short to be meaningful or so long they exceed your target context window (e.g., 4096 tokens). Truncating during training can cut off the "assistant" response, teaching the model to stop abruptly.
*   **Format Validation:** Ensure every JSON object is valid. One missing comma in a 50,000-line JSONL file can crash a multi-node training job three hours in.
*   **De-duplication:** Use MinHash or simple string matching to remove near-duplicate instructions. Over-representing specific phrasing causes the model to overfit and lose its generalization capabilities.

## 4. Tokenization and Prompt Templates
Every model has a specific prompt template (e.g., Llama-3 uses `<|begin_of_text|>`, while Mistral uses `[INST]`). When preparing your dataset, you don't necessarily need to bake these tokens into the JSONL file. Most SFT trainers will apply the template automatically using a `tokenizer_config.json`.

However, you *should* calculate the token counts of your prepared dataset. This helps you estimate the VRAM required and decide if you need to use techniques like Packing (combining multiple short sequences into a single block) to increase training efficiency.

## 5. Practical Tips for Better SFT
*   **Balance your categories:** If 90% of your data is about Python and 10% is about SQL, your model will likely struggle with SQL. Aim for an even distribution.
*   **System Prompt Variation:** Don't use the exact same system prompt for every single entry. Subtle variations help the model understand the *intent* of the system role rather than just memorizing a specific string.
*   **Quality over Quantity:** 1,000 high-quality, human-curated examples often outperform 50,000 noisy, machine-generated ones.

## Running the Job on Podstack
Once your `train.jsonl` is ready, the next step is moving to a GPU environment. Podstack makes this seamless by allowing you to trigger training jobs directly via the API or deploy a Python function as a GPU worker.

First, ensure your `PODSTACK_API_KEY` is set in your environment. You can then use the Podstack API to spin up an on-demand instance with the specific VRAM you need (like an A100 or H100) to run your training script.

```text
Podstack does not ship a command-line interface. Use the console, the Python package `podstack-sdk`, or the API at https://podstack.ai/api/v1 with a `ps_live_` key.
```

Because Podstack bills per second, you can upload your dataset, run your SFT job, and tear it down the moment the weights are saved to your storage, ensuring you only pay for the compute used during the actual training iterations.

## Summary
Dataset preparation is 80% of the work in fine-tuning. By focusing on conversational formatting, rigorous cleaning, and diverse synthesis, you create a foundation for a performant model. Once your data is staged, Podstack provides the high-performance GPU infrastructure to turn that data into a specialized model with minimal friction.
