---
title: "Chapter 08: The Logger"
description: "Wrap the harness so every run emits one JSONL trajectory. The schema decisions here — outcome field, masking, logging failures — are load-bearing for Parts 4 and 5."
type: lesson
order: 8
chapter: "03-trajectories"
---

# Chapter 08: The Logger

The logger is the actual artifact of Part 3. Wrap the harness so every run emits one JSONL line:

```json
{
  "task_id": "...",
  "task": "What does the retry logic in client.py do?",
  "messages": [
    {"role": "system", "content": "..."},
    {"role": "user", "content": "..."},
    {"role": "assistant", "content": "<thinking>...</thinking><tool>read_file('client.py')</tool>"},
    {"role": "tool", "content": "<file contents>"},
    {"role": "assistant", "content": "The retry logic uses exponential backoff..."}
  ],
  "outcome": null,
  "steps": 3,
  "meta": {"model": "...", "timestamp": "..."}
}
```

## Design Notes That Will Bite You Later If You Skip Them

- **`outcome` is null for now.** Part 4's verifier fills it. Leave the field.
- **Every `tool` role message is masked out of the loss.** This is Check 2 from [Chapter 05](/fine-tune-local-agent/02-the-pipeline/05-train-and-check/), now load-bearing. The model must be trained to *produce* the assistant turns and to *condition on* the tool turns — never to produce them.
- **Log failures too.** Part 5's preference-learning variant needs them. Storage is free.
- **Version the schema.** You will change it.

## The Converter

Write `to_training_data.py`: trajectory JSONL → mlx-lm chat JSONL, with masking applied. This is the bridge between "what the agent did" and "what the model trains on," and it's the file you'll edit most in Part 5.

Because you built the generator-script habit in [Chapter 04](/fine-tune-local-agent/02-the-pipeline/04-the-toy-task/), regenerating the entire training set from raw trajectories should be one command.

---

[← Chapter 07](/fine-tune-local-agent/03-trajectories/07-the-harness/) · [Next: Chapter 09 →](/fine-tune-local-agent/03-trajectories/09-teacher-traces/)
