{"record":{"id":"f04655935292853e","repo":"infiniflow/ragflow","slug":"categorize-message-window-size-cannot-be-negativ","errorCode":null,"errorMessage":"[Categorize] Message window size cannot be negative","messagePattern":"\\[Categorize\\] Message window size cannot be negative","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/component/categorize.py","lineNumber":44,"sourceCode":"from common.connection_utils import timeout\nfrom rag.llm.chat_model import ERROR_PREFIX\n\n\nclass 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","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/agent/component/categorize.py#L26-L62","documentation":"Raised by CategorizeParam.check (agent/component/categorize.py) when message_history_window_size is not an int (bools are technically int subclasses and would pass isinstance, floats and strings fail) or is negative. The window size controls how many prior conversation messages the categorizer sees; it must be a non-negative integer.","triggerScenarios":"Setting the Categorize component's message_history_window_size to -1 (meaning 'unlimited' in some other tools), 1.0 (float from JSON), or \"3\" (string) in the canvas; also programmatically building the component with a computed float value. Fires during parameter validation on save/run.","commonSituations":"Users assuming negative means unlimited; frontend numeric inputs yielding floats; API-driven canvas generation writing strings; migrating configs from systems with different semantics.","solutions":["Set message_history_window_size to a non-negative integer such as 1 (the default) or larger, e.g. 5","Coerce programmatic values with int(value) and clamp: max(0, int(value))","Do not use -1 for unlimited — pick an explicit positive window size"],"exampleFix":"# before\n\"message_history_window_size\": -1\n\n# after\n\"message_history_window_size\": 5","handlingStrategy":"validation","validationCode":"window_size = config.get('message_history_window_size', 1)\nif isinstance(window_size, bool) or not isinstance(window_size, int) or window_size < 0:\n    window_size = max(0, int(window_size))  # or reject explicitly\nparam.message_history_window_size = window_size","typeGuard":"def is_valid_window_size(v) -> bool:\n    return isinstance(v, int) and not isinstance(v, bool) and v >= 0","tryCatchPattern":"try:\n    param.check()\nexcept ValueError as e:\n    if 'Message window size' in str(e):\n        param.message_history_window_size = 1  # safe default\n    else:\n        raise","preventionTips":["Use plain non-negative integers for window size; -1 does not mean unlimited here","Coerce float form values with int() before saving the canvas","Validate programmatically generated canvases before persisting them"],"tags":["validation","agent-component","categorize","configuration"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}