{"record":{"id":"979b331ef18080fa","repo":"roboflow/supervision","slug":"malformed-createml-annotation-entry-annotation","errorCode":null,"errorMessage":"Malformed CreateML annotation entry {annotation}: {exc}","messagePattern":"Malformed CreateML annotation entry (.+?): (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/dataset/formats/createml.py","lineNumber":113,"sourceCode":"        array([0])\n\n        ```\n    \"\"\"\n    if not image_annotations:\n        return Detections.empty()\n\n    xyxy = []\n    class_ids = []\n    for annotation in image_annotations:\n        try:\n            coordinates = annotation[\"coordinates\"]\n            x_center = float(coordinates[\"x\"])\n            y_center = float(coordinates[\"y\"])\n            width = float(coordinates[\"width\"])\n            height = float(coordinates[\"height\"])\n            label = annotation[\"label\"]\n        except (KeyError, TypeError) as exc:\n            raise ValueError(\n                f\"Malformed CreateML annotation entry {annotation!r}: {exc}\"\n            ) from exc\n        xyxy.append(\n            [\n                x_center - width / 2,\n                y_center - height / 2,\n                x_center + width / 2,\n                y_center + height / 2,\n            ]\n        )\n        class_ids.append(class_to_index[label])\n\n    return Detections(\n        xyxy=np.array(xyxy, dtype=np.float32),\n        class_id=np.array(class_ids, dtype=int),\n    )\n\n","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/dataset/formats/createml.py#L95-L131","documentation":"Raised by createml_annotations_to_detections when an annotation lacks required fields — coordinates, or any of x/y/width/height inside coordinates, or label — or when values cannot be converted (TypeError on non-numeric strings). It wraps KeyError/TypeError from the field extraction with the full annotation echoed.","triggerScenarios":"An annotation dict missing \"coordinates\", or coordinates missing one of \"x\"/\"y\"/\"width\"/\"height\" (e.g. only x/y present with no size), or \"label\" absent, during load_createml_annotations.","commonSituations":"Annotations from a keypoint or polygon-oriented tool that writes different coordinate fields; partially written files; coordinates written as nested strings ('{\"x\": ...}') instead of numbers.","solutions":["Ensure every annotation has label plus coordinates with numeric x, y, width, height.","Convert CreateML-incompatible schemas before loading (e.g. compute width/height from x1/y1/x2/y2: x=(x1+x2)/2, width=x2-x1).","Pre-scan and drop/repair malformed annotations before calling the loader."],"exampleFix":"// before\n{\"label\": \"dog\", \"coordinates\": {\"x\": 50, \"y\": 50}}\n\n// after\n{\"label\": \"dog\", \"coordinates\": {\"x\": 50, \"y\": 50, \"width\": 20, \"height\": 20}}","handlingStrategy":"validation","validationCode":"def is_valid_createml_annotation(ann: object) -> bool:\n    \"\"\"Check the full CreateML annotation shape before loading.\"\"\"\n    if not isinstance(ann, dict):\n        return False\n    coords = ann.get(\"coordinates\")\n    if not isinstance(coords, dict):\n        return False\n    try:\n        float(coords[\"x\"]), float(coords[\"y\"]), float(coords[\"width\"]), float(coords[\"height\"])\n    except (KeyError, TypeError, ValueError):\n        return False\n    return isinstance(ann.get(\"label\"), str)","typeGuard":"def createml_entry_is_well_formed(entry: dict) -> bool:\n    \"\"\"True when all annotations in the entry pass shape validation.\"\"\"\n    return all(is_valid_createml_annotation(a) for a in (entry.get(\"annotations\") or []))","tryCatchPattern":"try:\n    sv.DetectionDataset.from_createml(images_directory_path=d, annotations_path=a)\nexcept ValueError as exc:\n    if \"Malformed CreateML annotation entry\" in str(exc):\n        bad = [a for e in json.load(open(a)) for a in (e.get('annotations') or []) if not is_valid_createml_annotation(a)]\n        raise ValueError(f\"Repair {len(bad)} malformed annotations\") from exc\n    raise","preventionTips":["Every annotation needs label plus numeric x, y, width, height inside coordinates.","Convert from corner-box schemas explicitly: x=(x1+x2)/2, y=(y1+y2)/2, width=x2-x1, height=y2-y1.","Run a shape validator over annotation files from external tools before training."],"tags":["createml","dataset-load","schema","coordinates"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}