{"record":{"id":"12bf45d2d7cce81d","repo":"infiniflow/ragflow","slug":"days-back-must-be-an-integer","errorCode":null,"errorMessage":"days_back must be an integer","messagePattern":"days_back must be an integer","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/tools/bgpt.py","lineNumber":66,"sourceCode":"            },\n        }\n        super().__init__()\n        self.top_n = 10\n        self.api_key = \"\"\n        self.days_back = None\n\n    def check(self):\n        try:\n            if isinstance(self.top_n, str):\n                self.top_n = int(self.top_n.strip())\n        except Exception:\n            pass\n        self.check_positive_integer(self.top_n, \"Top N\")\n        if self.days_back not in (None, \"\"):\n            try:\n                self.days_back = int(self.days_back)\n            except (TypeError, ValueError) as exc:\n                raise ValueError(\"days_back must be an integer\") from exc\n            self.check_positive_integer(self.days_back, \"Days back\")\n\n    def get_input_form(self) -> dict[str, dict]:\n        return {\"query\": {\"name\": \"Query\", \"type\": \"line\"}}\n\n\nclass BGPT(ToolBase, ABC):\n    component_name = \"BGPT\"\n\n    @timeout(int(os.environ.get(\"COMPONENT_EXEC_TIMEOUT\", 30)))\n    def _invoke(self, **kwargs):\n        if self.check_if_canceled(\"BGPT processing\"):\n            return\n\n        query = kwargs.get(\"query\")\n        if not query or not isinstance(query, str) or not query.strip():\n            self.set_output(\"formalized_content\", \"\")\n            return \"\"","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/agent/tools/bgpt.py#L48-L84","documentation":"Raised by the BGPT tool's parameter check when `days_back` is a non-empty value that int() cannot coerce (e.g. \"last week\", \"7d\", [7]). The check tolerates None and \"\" (treated as unset) and successfully coerces numeric strings; only non-numeric input reaches the ValueError. After coercion, days_back must additionally pass check_positive_integer.","triggerScenarios":"Setting the BGPT tool's `days_back` parameter (agent canvas component config or programmatic invocation) to a non-numeric string like 'week', '7 days', or 'recent'. Numeric strings like \"7\" are accepted; None/\"\" skip the check entirely.","commonSituations":"Agent canvas forms filled with human-style text instead of a number; LLM-driven parameter generation writing '7d'; copy-pasting config with units attached.","solutions":["Set days_back to an integer (or numeric string) such as 7, or leave it empty/None for the default window.","Strip units before configuring: use 7 not '7 days'.","Validate/coerce days_back at your own boundary (see defense code) before creating the tool.","If generating parameters with an LLM, constrain days_back in the tool schema (type: integer) so the model emits a number."],"exampleFix":"# before\ntool.days_back = \"last week\"  # check() -> ValueError\n\n# after\ntool.days_back = 7","handlingStrategy":"validation","validationCode":"if days_back not in (None, \"\"):\n    try:\n        days_back = int(str(days_back).strip())\n    except ValueError:\n        raise ValueError(\"days_back must be an integer (e.g. 7)\") from None\n    if days_back <= 0:\n        raise ValueError(\"days_back must be a positive integer\")","typeGuard":"def is_valid_days_back(value) -> bool:\n    if value in (None, \"\"):\n        return True  # treated as unset\n    try:\n        return int(str(value).strip()) > 0\n    except (TypeError, ValueError):\n        return False","tryCatchPattern":"try:\n    tool.check()\nexcept ValueError as e:\n    if \"days_back\" in str(e):\n        tool.days_back = None  # fall back to the default window\n        tool.check()\n    else:\n        raise","preventionTips":["Pass plain integers for days_back; strip units ('7 days' -> 7) at your config boundary.","Leave days_back unset (None/empty) when the default window is acceptable.","Declare days_back as type: integer in tool schemas fed to LLMs so generators emit numbers, not prose."],"tags":["validation","bgpt","tool","parameters","type-coercion"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}