{"record":{"id":"ff65801c8aecee2b","repo":"deepset-ai/haystack","slug":"device-id-must-be-an-integer-got-device-id-str","errorCode":null,"errorMessage":"Device id must be an integer, got {device_id_str}","messagePattern":"Device id must be an integer, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"haystack/utils/device.py","lineNumber":540,"sourceCode":"        return Device.mps()\n    return Device.cpu()\n\n\ndef _split_device_string(string: str) -> tuple[str, int | None]:\n    \"\"\"\n    Split a device string into device type and device id.\n\n    :param string:\n        The device string to split.\n    :returns:\n        The device type and device id, if any.\n    \"\"\"\n    if \":\" in string:\n        device_type, device_id_str = string.split(\":\")\n        try:\n            device_id = int(device_id_str)\n        except ValueError as e:\n            raise ValueError(f\"Device id must be an integer, got {device_id_str}\") from e\n    else:\n        device_type = string\n        device_id = None\n    return device_type, device_id\n","sourceCodeStart":522,"sourceCodeEnd":545,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/utils/device.py#L522-L545","documentation":"_split_device_string parses strings like 'cuda:0' into a device type and integer id. If the text after ':' is not a valid integer (e.g. 'cuda:zero', 'gpu:x'), int() fails and this ValueError is raised with the offending fragment.","triggerScenarios":"Calling ComponentDevice.from_str(\"cuda:zero\"), Device.from_str(\"cpu:abc\"), or from_hf with a device string containing a non-numeric id after ':'.","commonSituations":"Typos in config files or CLI args; copying device names from logs that use word ids; localization mistakes like 'gpu:１' (full-width digit).","solutions":["Use a numeric device id, e.g. 'cuda:0' instead of 'cuda:zero'.","Omit the id entirely to mean the whole device type, e.g. 'cpu' or 'cuda'.","Validate the device string format 'type[:int]' before calling from_str/from_hf."],"exampleFix":"// before\nComponentDevice.from_str(\"cuda:zero\")\n// after\nComponentDevice.from_str(\"cuda:0\")","handlingStrategy":"validation","validationCode":"import re\nassert re.fullmatch(r\"[a-zA-Z]+(:\\d+)?\", device_str), f\"invalid device string: {device_str}\"","typeGuard":"def is_valid_device_string(s: str) -> bool:\n    if \":\" not in s:\n        return s.isalpha()\n    t, _, i = s.partition(\":\")\n    return t.isalpha() and i.isdigit()","tryCatchPattern":"try:\n    dev = ComponentDevice.from_str(s)\nexcept ValueError:\n    dev = ComponentDevice.from_str(\"cpu\")","preventionTips":["Use numeric ids in device strings ('cuda:0', not 'cuda:zero').","Omit the id suffix to target a whole device type.","Centralize device-string parsing/validation in one helper."],"tags":["python","device","parsing","haystack"],"backgroundTag":"invalid-number-format","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}