Implementation:Mistralai Client python JSONL Data Format
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Fine_Tuning, Data_Preparation |
| Last Updated | 2026-02-15 14:00 GMT |
Overview
Interface specification for preparing JSONL training data files for Mistral fine-tuning jobs.
Description
This is a Pattern Doc — it documents the user-implemented data preparation pattern. Training data must be formatted as JSONL (JSON Lines) where each line is a valid JSON object containing a messages array. The messages follow the standard chat format with role and content fields.
Usage
Prepare JSONL files before calling client.files.upload(). Each line should be a self-contained training example.
Code Reference
Source Location
- Repository: client-python
- File: N/A (user code pattern)
- Reference: examples/mistral/jobs/jobs.py
Interface Specification
import json
def create_training_jsonl(examples: list, output_path: str) -> str:
"""
Create a JSONL file from training examples.
Args:
examples: List of conversation dicts with 'messages' key
output_path: Path to write the .jsonl file
Returns:
Path to the created file
"""
with open(output_path, "w") as f:
for example in examples:
f.write(json.dumps(example) + "\n")
return output_path
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| examples | List[Dict] | Yes | Training examples with "messages" key |
| output_path | str | Yes | Path to write the .jsonl file |
Outputs
| Name | Type | Description |
|---|---|---|
| .jsonl file | File | JSONL file ready for upload |
Usage Examples
Create Training Data
import json
# Prepare examples
examples = [
{
"messages": [
{"role": "user", "content": "What is machine learning?"},
{"role": "assistant", "content": "Machine learning is a subset of AI..."}
]
},
{
"messages": [
{"role": "system", "content": "You are a coding expert."},
{"role": "user", "content": "Write a Python hello world."},
{"role": "assistant", "content": "print('Hello, World!')"}
]
},
]
# Write JSONL file
with open("train.jsonl", "w") as f:
for ex in examples:
f.write(json.dumps(ex) + "\n")
Related Pages
Implements Principle
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment