---
title: "Chapter 04: The Toy Task"
description: "Set up mlx-lm and generate a chat-format JSONL dataset for a behavior the base model definitively does not have."
type: lesson
order: 4
chapter: "02-the-pipeline"
---

# Chapter 04: The Toy Task

## Objective

Build a working, repeatable `data → train → fuse → serve` pipeline on a model small enough that the whole loop runs in minutes. Prove the pipeline works using a behavior so trivial that success and failure are unambiguous.

## Why This Is Here

Part 5's flywheel spins this pipeline hundreds of times. Every defect you leave in it now gets multiplied. The most expensive bug in agent fine-tuning — loss masking — is invisible unless you deliberately test for it. So we test for it here, on a 1B model, in a task where a broken tune is obvious in one glance.

## Setup

```bash
uv pip install mlx-lm
```

## The Task

**"Always respond with a JSON object containing keys `answer` and `confidence`."**

That's it. Twenty examples. It's the "replace every number with BANANA" of fine-tuning: a behavior the base model definitively does not have, that you can verify in one look, that requires zero domain knowledge.

## Data Format

`mlx-lm` reads a directory containing `train.jsonl`, `valid.jsonl`, and optionally `test.jsonl`. Use the **chat** format — it's what Part 3 needs:

```jsonl
{"messages": [{"role": "user", "content": "What is the capital of France?"}, {"role": "assistant", "content": "{\"answer\": \"Paris\", \"confidence\": 0.99}"}]}
```

## Write a Generator, Not a File

Write a script that generates these. **Do not hand-write JSONL.** You will regenerate this file two hundred times before you're done — different sizes, different splits, different tasks. The script is the artifact; the JSONL is disposable output.

---

[← Part 2 Index](/fine-tune-local-agent/02-the-pipeline/) · [Next: Chapter 05 →](/fine-tune-local-agent/02-the-pipeline/05-train-and-check/)
