infiniflow/ragflow · error · ValueError

days_back must be an integer

Error message

days_back must be an integer

What it means

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.

Source

Thrown at agent/tools/bgpt.py:66

            },
        }
        super().__init__()
        self.top_n = 10
        self.api_key = ""
        self.days_back = None

    def check(self):
        try:
            if isinstance(self.top_n, str):
                self.top_n = int(self.top_n.strip())
        except Exception:
            pass
        self.check_positive_integer(self.top_n, "Top N")
        if self.days_back not in (None, ""):
            try:
                self.days_back = int(self.days_back)
            except (TypeError, ValueError) as exc:
                raise ValueError("days_back must be an integer") from exc
            self.check_positive_integer(self.days_back, "Days back")

    def get_input_form(self) -> dict[str, dict]:
        return {"query": {"name": "Query", "type": "line"}}


class BGPT(ToolBase, ABC):
    component_name = "BGPT"

    @timeout(int(os.environ.get("COMPONENT_EXEC_TIMEOUT", 30)))
    def _invoke(self, **kwargs):
        if self.check_if_canceled("BGPT processing"):
            return

        query = kwargs.get("query")
        if not query or not isinstance(query, str) or not query.strip():
            self.set_output("formalized_content", "")
            return ""

View on GitHub (pinned to 554fb1133a)

Solutions

  1. Set days_back to an integer (or numeric string) such as 7, or leave it empty/None for the default window.
  2. Strip units before configuring: use 7 not '7 days'.
  3. Validate/coerce days_back at your own boundary (see defense code) before creating the tool.
  4. If generating parameters with an LLM, constrain days_back in the tool schema (type: integer) so the model emits a number.

Example fix

# before
tool.days_back = "last week"  # check() -> ValueError

# after
tool.days_back = 7
Defensive patterns

Strategy: validation

Validate before calling

if days_back not in (None, ""):
    try:
        days_back = int(str(days_back).strip())
    except ValueError:
        raise ValueError("days_back must be an integer (e.g. 7)") from None
    if days_back <= 0:
        raise ValueError("days_back must be a positive integer")

Type guard

def is_valid_days_back(value) -> bool:
    if value in (None, ""):
        return True  # treated as unset
    try:
        return int(str(value).strip()) > 0
    except (TypeError, ValueError):
        return False

Try / catch

try:
    tool.check()
except ValueError as e:
    if "days_back" in str(e):
        tool.days_back = None  # fall back to the default window
        tool.check()
    else:
        raise

Prevention

When it happens

Trigger: 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.

Common situations: Agent canvas forms filled with human-style text instead of a number; LLM-driven parameter generation writing '7d'; copy-pasting config with units attached.

Related errors


AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15). Data as JSON: /api/errors/12bf45d2d7cce81d. Report an issue: GitHub.