{"record":{"id":"cf855e5220efdf83","repo":"infiniflow/ragflow","slug":"categorize-to-of-category-k-can-not-be-empty","errorCode":null,"errorMessage":"[Categorize] 'To' of category {k} can not be empty!","messagePattern":"\\[Categorize\\] 'To' of category (.+?) can not be empty!","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/component/categorize.py","lineNumber":50,"sourceCode":"    Define the categorize component parameters.\n    \"\"\"\n\n    def __init__(self):\n        super().__init__()\n        self.category_description = {}\n        self.query = \"sys.query\"\n        self.message_history_window_size = 1\n        self.update_prompt()\n\n    def check(self):\n        if not isinstance(self.message_history_window_size, int) or self.message_history_window_size < 0:\n            raise ValueError(\"[Categorize] Message window size cannot be negative\")\n        self.check_empty(self.category_description, \"[Categorize] Category examples\")\n        for k, v in self.category_description.items():\n            if not k:\n                raise ValueError(\"[Categorize] Category name can not be empty!\")\n            if not v.get(\"to\"):\n                raise ValueError(f\"[Categorize] 'To' of category {k} can not be empty!\")\n\n    def get_input_form(self) -> dict[str, dict]:\n        return {\"query\": {\"type\": \"line\", \"name\": \"Query\"}}\n\n    def update_prompt(self):\n        cate_lines = []\n        for c, desc in self.category_description.items():\n            for line in desc.get(\"examples\", []):\n                if not line:\n                    continue\n                cate_lines.append('USER: \"' + re.sub(r\"\\n\", \"    \", line, flags=re.DOTALL) + '\" → ' + c)\n\n        descriptions = []\n        for c, desc in self.category_description.items():\n            if desc.get(\"description\"):\n                descriptions.append(\"\\n------\\nCategory: {}\\nDescription: {}\".format(c, desc[\"description\"]))\n\n        self.sys_prompt = \"\"\"","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/agent/component/categorize.py#L32-L68","documentation":"Raised by CategorizeParam.check (agent/component/categorize.py) when a category entry's dict lacks a truthy 'to' value. 'to' names the downstream component/branch the conversation routes to when the LLM picks that category; without it routing is undefined, so validation fails with the category name in the message.","triggerScenarios":"Adding a category with a name and examples but not connecting its output to another component in the canvas; or the 'to' field being an empty string in the JSON. Fires during check() when the canvas is saved or executed.","commonSituations":"Building a new categorize node and forgetting to wire its outgoing connections; deleting a downstream component and leaving the category's 'to' dangling/blank; importing a canvas whose component ids changed so 'to' was reset.","solutions":["In the Categorize editor, connect every category's output to a target component so 'to' is populated","Inspect the canvas JSON category_description entries and fill any empty \"to\" with a valid component id","After deleting or renaming downstream components, re-open the Categorize component and re-link each category"],"exampleFix":"# before\n\"category_description\": {\"faq\": {\"examples\": [...], \"to\": \"\"}}\n\n# after\n\"category_description\": {\"faq\": {\"examples\": [...], \"to\": \"Generate:0\"}}","handlingStrategy":"validation","validationCode":"valid_component_ids = {c['id'] for c in canvas_components}\nfor name, spec in categories.items():\n    if not spec.get('to') or spec['to'].split(':')[0] not in valid_component_ids:\n        raise ValueError(f\"Category '{name}' must route to an existing component\")","typeGuard":"def all_categories_routed(categories: dict) -> bool:\n    return all(v.get('to') for v in categories.values())","tryCatchPattern":"try:\n    param.check()\nexcept ValueError as e:\n    if \"'To' of category\" in str(e):\n        flag_canvas_incomplete('Connect every Categorize category to a downstream component')\n    else:\n        raise","preventionTips":["Finish wiring outgoing connections before saving/running a Categorize node","After deleting a downstream component, re-link each category that pointed to it","Treat an unlinked category as a build error in canvas validation tooling"],"tags":["validation","agent-component","categorize","workflow-routing"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}