{
  "id": "llm/fine-tuning-data-format-invalid",
  "signature": "openai.BadRequestError: Invalid training file: 'messages' must be a list of objects, but got <class 'str'> for line 42",
  "signature_zh": "openai.BadRequestError: 训练文件无效：第42行的'messages'必须是对象列表，但得到的是<class 'str'>",
  "regex": "openai\\.BadRequestError: Invalid training file: 'messages' must be a list of objects, but got <class 'str'> for line \\d+",
  "domain": "llm",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "A JSONL training file for fine-tuning contains a malformed line where the 'messages' field is a string instead of a list of message objects, often due to a missing comma or incorrect JSON serialization.",
  "root_cause_type": "generic",
  "root_cause_zh": "用于微调的JSONL训练文件中存在格式错误的行，其中'messages'字段是字符串而不是消息对象列表，通常是由于缺少逗号或JSON序列化不正确所致。",
  "versions": [
    {
      "version": "openai==1.30.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "python==3.11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The error may be caused by a systemic issue (e.g., incorrect serialization logic) that affects multiple lines; fixing only line 42 won't prevent the same error on other lines.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Standard JSON validators will pass a string value for 'messages' as valid JSON; the error is a semantic validation that the OpenAI API performs.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "If the code that writes JSONL is buggy, regenerating will produce the same error on the same or different lines.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Validate the training file locally before uploading: `import json; with open('training.jsonl') as f: for i, line in enumerate(f, 1): try: obj = json.loads(line); assert isinstance(obj['messages'], list), f'Line {i}: messages is not a list'; for msg in obj['messages']: assert 'role' in msg and 'content' in msg, f'Line {i}: message missing role or content' except (json.JSONDecodeError, AssertionError) as e: print(f'Error on line {i}: {e}')`",
      "success_rate": 0.95,
      "how": "Validate the training file locally before uploading: `import json; with open('training.jsonl') as f: for i, line in enumerate(f, 1): try: obj = json.loads(line); assert isinstance(obj['messages'], list), f'Line {i}: messages is not a list'; for msg in obj['messages']: assert 'role' in msg and 'content' in msg, f'Line {i}: message missing role or content' except (json.JSONDecodeError, AssertionError) as e: print(f'Error on line {i}: {e}')`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use the OpenAI CLI tool to validate the file: `openai api fine_tunes.create -t training.jsonl -v` which provides detailed error messages for each malformed line.",
      "success_rate": 0.9,
      "how": "Use the OpenAI CLI tool to validate the file: `openai api fine_tunes.create -t training.jsonl -v` which provides detailed error messages for each malformed line.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Validate the training file locally before uploading: `import json; with open('training.jsonl') as f: for i, line in enumerate(f, 1): try: obj = json.loads(line); assert isinstance(obj['messages'], list), f'Line {i}: messages is not a list'; for msg in obj['messages']: assert 'role' in msg and 'content' in msg, f'Line {i}: message missing role or content' except (json.JSONDecodeError, AssertionError) as e: print(f'Error on line {i}: {e}')`",
    "Use the OpenAI CLI tool to validate the file: `openai api fine_tunes.create -t training.jsonl -v` which provides detailed error messages for each malformed line."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://platform.openai.com/docs/guides/fine-tuning/preparing-your-dataset",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.9,
  "fix_success_rate": 0.88,
  "resolvable": "true",
  "first_seen": "2024-06-01",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}