{"record":{"id":"06a5f3b1e6ac16aa","repo":"infiniflow/ragflow","slug":"the-input-of-list-operations-should-be-an-array","errorCode":null,"errorMessage":"The input of List Operations should be an array.","messagePattern":"The input of List Operations should be an array\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"agent/component/list_operations.py","lineNumber":57,"sourceCode":"            self.operations,\n            \"Support operations\",\n            [\"nth\", \"head\", \"tail\", \"filter\", \"sort\", \"drop_duplicates\"],\n        )\n\n    def get_input_form(self) -> dict[str, dict]:\n        return {}\n\n\nclass ListOperations(ComponentBase, ABC):\n    component_name = \"ListOperations\"\n\n    @timeout(int(os.environ.get(\"COMPONENT_EXEC_TIMEOUT\", 10 * 60)))\n    def _invoke(self, **kwargs):\n        self.input_objects = []\n        inputs = getattr(self._param, \"query\", None)\n        self.inputs = self._canvas.get_variable_value(inputs)\n        if not isinstance(self.inputs, list):\n            raise TypeError(\"The input of List Operations should be an array.\")\n        self.set_input_value(inputs, self.inputs)\n        if self._param.operations == \"nth\":\n            self._nth()\n        elif self._param.operations == \"head\":\n            self._head()\n        elif self._param.operations == \"tail\":\n            self._tail()\n        elif self._param.operations == \"filter\":\n            self._filter()\n        elif self._param.operations == \"sort\":\n            self._sort()\n        elif self._param.operations == \"drop_duplicates\":\n            self._drop_duplicates()\n\n    def _coerce_n(self):\n        try:\n            return int(getattr(self._param, \"n\", 0))\n        except Exception:","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/agent/component/list_operations.py#L39-L75","documentation":"TypeError from the ListOperations component. Its query parameter is resolved through canvas.get_variable_value and must be a Python list; any other type aborts execution before any operation (nth/head/tail/filter/sort/drop_duplicates) runs.","triggerScenarios":"Wiring the ListOperations 'query' input to a string, dict, number, or None. Common with a template/LLM output that is a JSON string rather than a parsed array, or a dangling component reference.","commonSituations":"Feeding a retriever's chunk list through a transform that collapses it to a string; referencing an upstream variable that only populates on some branches, leaving None; passing a dict of outputs instead of one list field.","solutions":["Insert a Code component that does json.loads on the string (or wraps scalars) and outputs a real list.","Point the query selector at an output that is guaranteed to be an array (e.g. a specific list-typed output pin, not the whole output object).","Check for empty/None early: return [] upstream so ListOperations receives a valid (empty) list instead of None."],"exampleFix":"# before\ninputs = canvas.get_variable_value(\"{{str_output}}\")  # \"[1,2,3]\" as text -> TypeError\n\n# after (Code component before ListOperations)\nimport json\ndef main(s):\n    return json.loads(s) if isinstance(s, str) else s","handlingStrategy":"type-guard","validationCode":"inputs = canvas.get_variable_value(query_ref)\nassert isinstance(inputs, list), f'ListOperations input is {type(inputs).__name__}, expected list'","typeGuard":"def is_list(v) -> bool:\n    return isinstance(v, list)","tryCatchPattern":"try:\n    component._invoke()\nexcept TypeError as e:\n    if 'should be an array' in str(e):\n        # normalize input to list and retry\n        ...","preventionTips":["Ensure the query input is produced by a component whose output type is an array.","json.loads any string payloads before connecting them to ListOperations.","Prefer selecting a specific list-typed output pin over whole-output references."],"tags":["list-operations","type-mismatch","agent-canvas"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}