{"record":{"id":"d3e714bcca52416c","repo":"roboflow/supervision","slug":"malformed-createml-annotation-entry-missing-or-no","errorCode":null,"errorMessage":"Malformed CreateML annotation entry (missing or non-string 'label'): {exc}","messagePattern":"Malformed CreateML annotation entry \\(missing or non-string 'label'\\): (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/dataset/formats/createml.py","lineNumber":188,"sourceCode":"    createml_data = cast(\n        \"list[CreateMLDict]\", read_json_file(file_path=annotations_path)\n    )\n    if not isinstance(createml_data, list):\n        raise ValueError(\n            f\"CreateML annotation file must contain a JSON list at the root, \"\n            f\"got {type(createml_data).__name__}.\"\n        )\n\n    try:\n        classes = sorted(\n            {\n                annotation[\"label\"]\n                for entry in createml_data\n                for annotation in (entry.get(\"annotations\") or [])\n            }\n        )\n    except (KeyError, TypeError) as exc:\n        raise ValueError(\n            f\"Malformed CreateML annotation entry \"\n            f\"(missing or non-string 'label'): {exc}\"\n        ) from exc\n    class_to_index = {class_name: index for index, class_name in enumerate(classes)}\n\n    image_paths: list[str] = []\n    annotations: dict[str, Detections] = {}\n    for entry in tqdm(\n        createml_data,\n        desc=\"Loading CreateML annotations\",\n        disable=not show_progress,\n    ):\n        image_name = entry.get(\"image\")\n        if image_name is None:\n            raise ValueError(\n                f\"CreateML annotation entry is missing the required 'image' key: \"\n                f\"{entry!r}\"\n            )","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/dataset/formats/createml.py#L170-L206","documentation":"Raised by load_createml_annotations when collecting the class set across all entries fails with KeyError/TypeError — i.e. some annotation lacks a 'label' key or has a non-subscriptable shape. The loader derives the sorted class list from every annotation's label before building class_to_index, so one malformed annotation aborts the load.","triggerScenarios":"Any entry in the annotations array of the CreateML JSON missing \"label\", or an annotations list containing non-dict items (TypeError on annotation[\"label\"]).","commonSituations":"Partially exported or hand-edited files; annotations written by a tool that names the field differently (e.g. 'class' or 'category'); null entries inside annotations arrays.","solutions":["Scan the JSON for annotations without a string 'label' field and add or rename it.","If your source uses a different key, transform it: ann['label'] = ann.pop('category').","Drop null/non-dict items from annotations arrays before loading."],"exampleFix":"// before\n{\"image\": \"a.jpg\", \"annotations\": [{\"coordinates\": {...}}]}\n\n// after\n{\"image\": \"a.jpg\", \"annotations\": [{\"label\": \"dog\", \"coordinates\": {...}}]}","handlingStrategy":"validation","validationCode":"import json\nfrom pathlib import Path\n\ndef validate_createml_labels(annotations_path: str) -> None:\n    \"\"\"Fail fast if any annotation lacks a string 'label'.\"\"\"\n    entries = json.loads(Path(annotations_path).read_text())\n    for e in entries:\n        for ann in e.get(\"annotations\") or []:\n            if not isinstance(ann, dict) or not isinstance(ann.get(\"label\"), str):\n                raise ValueError(f\"Malformed annotation in entry {e.get('image')!r}: {ann!r}\")","typeGuard":"def has_valid_labels(entry: dict) -> bool:\n    \"\"\"True when every annotation in the entry carries a string label.\"\"\"\n    anns = entry.get(\"annotations\") or []\n    return all(isinstance(a, dict) and isinstance(a.get(\"label\"), str) for a in anns)","tryCatchPattern":"try:\n    sv.DetectionDataset.from_createml(images_directory_path=d, annotations_path=a)\nexcept ValueError as exc:\n    if \"missing or non-string 'label'\" in str(exc):\n        validate_createml_labels(a)  # raises with the precise offending entry\n    raise","preventionTips":["Schema-check third-party CreateML files before bulk loading.","Standardize on the 'label' key in any converter you write.","Filter null/non-dict items out of annotations arrays at ingest time."],"tags":["createml","dataset-load","schema","data-quality"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}