OpenAIError
openai.OpenAIError
Stack trace
openai.OpenAIError: Invalid fine-tuning request: insufficient training examples provided. Minimum required examples not met.
Why it happens
OpenAI fine-tuning requires a minimum number of training examples to create a reliable model. If the dataset is too small or improperly formatted, the API rejects the request with this error.
Detection
Check the training dataset size before submitting fine-tuning jobs; log the number of examples and validate dataset format to catch issues early.
Causes & fixes
Training dataset contains fewer examples than OpenAI's minimum requirement (usually at least 100 examples).
Add more high-quality training examples to meet or exceed the minimum required count before submitting the fine-tuning job.
Training file is improperly formatted or missing required fields, causing the API to count fewer valid examples.
Validate the JSONL training file format strictly: each line must be a JSON object with 'prompt' and 'completion' fields.
Uploading the wrong file or an empty file by mistake during fine-tuning job creation.
Double-check the file path and contents before upload; ensure the file is not empty and contains the correct training data.
Code: broken vs fixed
from openai import OpenAI
client = OpenAI()
# This will fail if training file has too few examples
response = client.fine_tunes.create(training_file="file-abc123") # triggers error
print(response) import os
from openai import OpenAI
os.environ["OPENAI_API_KEY"] = os.environ.get("OPENAI_API_KEY", "your_api_key_here")
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
# Fixed: ensure training file has sufficient examples and correct format
response = client.fine_tunes.create(training_file="file-abc123") # works if file valid
print(response) Workaround
If you cannot add more examples immediately, try augmenting your dataset with synthetic or paraphrased prompts to increase example count temporarily.
Prevention
Automate dataset validation scripts to check example count and JSONL format before fine-tuning submission to avoid this error entirely.