{"record":{"id":"7f96bb5881dcdac2","repo":"microsoft/qlib","slug":"the-task-does-not-contains-a-handler-part","errorCode":null,"errorMessage":"The task does not contains a handler part.","messagePattern":"The task does not contains a handler part\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/data/dataset/utils.py","lineNumber":142,"sourceCode":"    ----------\n    task : dict\n        the task to be handled\n\n    Returns\n    -------\n    Union[DataHandler, None]:\n        returns\n    \"\"\"\n    # avoid recursive import\n    from .handler import DataHandler  # pylint: disable=C0415\n\n    h_conf = task[\"dataset\"][\"kwargs\"].get(\"handler\")\n    if h_conf is not None:\n        handler = init_instance_by_config(h_conf, accept_types=DataHandler)\n        task[\"dataset\"][\"kwargs\"][\"handler\"] = handler\n        return handler\n    else:\n        raise ValueError(\"The task does not contains a handler part.\")\n","sourceCodeStart":124,"sourceCodeEnd":143,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/data/dataset/utils.py#L124-L143","documentation":"Raised by get_dataset_kwargs / the task-unpacking helper (qlib/data/dataset/utils.py) when a task dict's dataset.kwargs contains no 'handler' entry. Qlib task objects (dataset + handler + model) require an embedded DataHandler config; without it there is nothing to instantiate, so a ValueError is raised with the message 'The task does not contains a handler part.'","triggerScenarios":"init_instance_by_config / task execution where task = {\"dataset\": {\"class\": \"DatasetH\", \"kwargs\": {\"segments\": {...}}}} — kwargs has segments but no \"handler\" key. Also when the handler key exists but its value is None (h_conf is None takes the else branch).","commonSituations":"Hand-building task dicts for qlib workflows (e.g. Rolling benchmarks, QlibRecorder experiments) and omitting the handler; splitting a config across files and dropping the handler section; setting \"handler\": None to 'disable' it, which is not supported.","solutions":["Add a handler config under dataset.kwargs, e.g. \"handler\": {\"class\": \"Alpha158\", \"kwargs\": {\"start_time\": ..., \"end_time\": ..., \"instruments\": ...}}.","If you already have a DataHandler instance, put it directly: task[\"dataset\"][\"kwargs\"][\"handler\"] = my_handler — the helper accepts instances (accept_types=DataHandler).","Check that the handler key is not explicitly set to None; remove the key or give it a real config."],"exampleFix":"# before\ntask = {\n  \"dataset\": {\"class\": \"DatasetH\", \"kwargs\": {\"segments\": {\"train\": (...), \"valid\": (...)}}},\n}\n\n# after\ntask = {\n  \"dataset\": {\"class\": \"DatasetH\", \"kwargs\": {\n      \"handler\": {\"class\": \"Alpha158\", \"kwargs\": {\"instruments\": \"csi300\", \"start_time\": \"2010-01-01\", \"end_time\": \"2020-12-31\"}},\n      \"segments\": {\"train\": (\"2010-01-01\", \"2017-12-31\"), \"valid\": (\"2018-01-01\", \"2020-12-31\")},\n  }},\n}","handlingStrategy":"validation","validationCode":"handler_conf = task.get(\"dataset\", {}).get(\"kwargs\", {}).get(\"handler\")\nif handler_conf is None:\n    raise ValueError(\"task['dataset']['kwargs'] must define 'handler'\")","typeGuard":"def task_has_handler(task: dict) -> bool:\n    return task.get(\"dataset\", {}).get(\"kwargs\", {}).get(\"handler\") is not None","tryCatchPattern":null,"preventionTips":["Build task dicts with a factory function that always injects the handler section.","Validate task structure once before submitting to QlibRecorder/Rolling loops."],"tags":["qlib","task","handler","config"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}