Task specialization
A task needs consistent learned behavior that prompting alone does not reliably produce.
AI & ML · Module
Fine-tuning adapts an OpenAI base model to task-specific behavior using representative input-output examples. Prepare JSONL data, upload it, create a job, and evaluate the resulting model.
Fine-tuning adapts an OpenAI base model to task-specific behavior by training it on representative input-output examples. The workflow is to prepare JSONL data, upload it, create a job, and evaluate the resulting model; reinforcement fine-tuning additionally uses a grader.
client.fine_tuning.jobs.create(model="MODEL_ID", training_file="FILE_ID", validation_file="FILE_ID")| Name | Type | Description |
|---|---|---|
model | string | Identifier of the supported base model to fine-tune. |
training_file | string | ID of the uploaded JSONL file containing training examples; the file must use the fine-tune purpose. |
validation_file | string | Optional ID of the uploaded JSONL validation file used for periodic validation metrics. |
hyperparameters | object | Optional hyperparameters controlling the fine-tuning job. |
A fine-tuning job object containing details about the enqueued job, including status and the fine-tuned model name once available.
from openai import OpenAI
client = OpenAI()
job = client.fine_tuning.jobs.create(
training_file="file-ABC123",
model="gpt-4.1-mini",
)
print(job.id)Creates a fine-tuning job from an uploaded JSONL training file and prints the job identifier.
A task needs consistent learned behavior that prompting alone does not reliably produce.
A smaller model should achieve the required accuracy with fewer prompt tokens.
A behavior must be optimized against a measurable reward rather than fixed target outputs.
A model needs evaluation-driven iteration on representative production-like examples.
Fine-tuning trains an OpenAI base model on examples representing the inputs and outputs expected in an application. The normal workflow is to collect examples, upload JSONL, create a job, and evaluate the result.
Follow-up: When should you fine-tune instead of relying only on prompting? Fine-tuning is appropriate when a specific task benefits from learned behavior; evaluation should establish whether it improves representative real-world performance.
The training dataset is uploaded as a JSONL file, and the file is supplied when creating the fine-tuning job. A validation file is optional and produces periodic validation metrics during training.
Follow-up: Why keep validation data separate? Overlapping training and validation examples make the validation measurements less representative of generalization.
Reinforcement fine-tuning adds a grader that scores the model's behavior. That score guides the training process, unlike ordinary supervised examples that directly specify desired outputs.
Follow-up: What extra design problem does reinforcement fine-tuning introduce? The grader must reliably measure the target behavior, or optimization can reward undesirable outputs.
model optimization workflowJSONLfine-tuning jobvalidation metricsreinforcement fine-tuninggradertraining filefine-tuned model