{"record":{"id":"fbfb55f4b76e9312","repo":"infiniflow/ragflow","slug":"categorize-category-name-can-not-be-empty","errorCode":null,"errorMessage":"[Categorize] Category name can not be empty!","messagePattern":"\\[Categorize\\] Category name can not be empty!","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/component/categorize.py","lineNumber":48,"sourceCode":"class CategorizeParam(LLMParam):\n    \"\"\"\n    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\"]))","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/agent/component/categorize.py#L30-L66","documentation":"Raised by CategorizeParam.check (agent/component/categorize.py) when iterating category_description and a dictionary key is empty/falsy. Each category entry needs a non-empty name because the name is used in the LLM prompt ('USER: ... → <name>') and as the routing label for downstream components.","triggerScenarios":"In the Categorize component's category configuration, adding a category row and leaving its name blank; or canvas JSON where a category_description entry has \"\" as key. Fires during check() on save or run.","commonSituations":"UI allowing an empty name to be saved; hand-edited canvas JSON; renaming a category to empty while its examples and 'to' remain; copy-paste artifacts creating an empty key.","solutions":["Give every category a non-empty, distinct name in the Categorize component editor","Remove fully empty category rows instead of leaving blank ones","When generating canvases programmatically, filter out empty keys: {k: v for k, v in cats.items() if k}"],"exampleFix":"# before\n\"category_description\": {\"\": {\"examples\": [...], \"to\": \"x\"}}\n\n# after\n\"category_description\": {\"complaint\": {\"examples\": [...], \"to\": \"x\"}}","handlingStrategy":"validation","validationCode":"categories = {k: v for k, v in raw_categories.items() if k and k.strip()}\nif not categories:\n    raise ValueError('Categorize needs at least one named category')\nparam.category_description = categories","typeGuard":"def has_no_empty_category_names(categories: dict) -> bool:\n    return all(str(k).strip() for k in categories)","tryCatchPattern":"try:\n    param.check()\nexcept ValueError as e:\n    if 'Category name can not be empty' in str(e):\n        param.category_description = {k: v for k, v in param.category_description.items() if k}\n    else:\n        raise","preventionTips":["Trim category names on save in the UI","Delete blank category rows instead of leaving them","When generating canvases programmatically, filter empty keys from category_description"],"tags":["validation","agent-component","categorize","configuration"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}