{"record":{"id":"aed70c33a83d288f","repo":"iflytek/astron-agent","slug":"lengthrange-values-must-be-greater-than-zero","errorCode":null,"errorMessage":"lengthRange values must be greater than zero","messagePattern":"lengthRange values must be greater than zero","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"core/knowledge/infra/ragflow/ragflow_utils.py","lineNumber":520,"sourceCode":"\n        Returns:\n            Parser configuration dictionary\n        \"\"\"\n        # RAGFlow's parser uses the configured maximum as its target chunk\n        # size. ``overlap`` and ``titleSplit`` are intentionally not forwarded:\n        # v0.20.5 has no overlap field, and title splitting is not equivalent\n        # to changing PDF layout recognition/OCR mode.\n        _ = overlap, titleSplit\n        if lengthRange is None:\n            chunk_token_num = 256\n        else:\n            if len(lengthRange) not in (1, 2) or any(\n                isinstance(value, bool) or not isinstance(value, int)\n                for value in lengthRange\n            ):\n                raise ValueError(\"lengthRange must contain one or two integers\")\n            if any(value <= 0 for value in lengthRange):\n                raise ValueError(\"lengthRange values must be greater than zero\")\n            if len(lengthRange) == 2 and lengthRange[0] > lengthRange[1]:\n                raise ValueError(\"lengthRange minimum cannot exceed maximum\")\n            chunk_token_num = lengthRange[-1]\n\n        # The Astron UI can send either a literal ``\\\\n`` or an actual newline.\n        # In RAGFlow v0.20.5, unquoted delimiter characters are independent;\n        # a multi-character delimiter must be wrapped in backticks.\n        normalized_separators = []\n        for value in separator or []:\n            normalized = value.replace(\"\\\\n\", \"\\n\")\n            if not normalized:\n                continue\n            normalized_separators.append(\n                normalized if len(normalized) == 1 else f\"`{normalized}`\"\n            )\n        if not any(\"\\n\" in value for value in normalized_separators):\n            normalized_separators.append(\"\\n\")\n        delimiter = \"\".join(normalized_separators)","sourceCodeStart":502,"sourceCodeEnd":538,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/knowledge/infra/ragflow/ragflow_utils.py#L502-L538","documentation":"build_parser_config requires every entry in lengthRange to be a strictly positive integer because the values become chunk token/length bounds in the RAGFlow parser config. A zero or negative value would produce an invalid chunking configuration, so it raises ValueError.","triggerScenarios":"Calling build_parser_config with lengthRange=[0], lengthRange=[-5, 100], or lengthRange=[100, 0] — any element <= 0.","commonSituations":"UI sending 0 as a 'no limit' placeholder; negative numbers from subtractive range computations; config templates with unfilled 0 defaults; user input not clamped to >= 1.","solutions":["Clamp client values before calling: lr = [max(1, v) for v in lr]","Validate at the API boundary and reject values <= 0 with a clear message","Treat 0/negative as 'unset' and omit lengthRange so the 256 default applies","Fix UI forms to enforce min=1 on length inputs"],"exampleFix":"// before\nconfig = build_parser_config(cfg={\"lengthRange\": user_range})\n// after\nlr = [v for v in (user_range or []) if isinstance(v, int) and not isinstance(v, bool) and v > 0]\nconfig = build_parser_config(cfg={\"lengthRange\": lr or None})","handlingStrategy":"validation","validationCode":"def validate_positive_length_range(lr) -> list[int] | None:\n    if lr in (None, []):\n        return None\n    if any(v <= 0 for v in lr):\n        raise ValueError(\"lengthRange values must be > 0\")\n    return lr","typeGuard":"def has_positive_values(v) -> bool:\n    return isinstance(v, list) and all(\n        isinstance(x, int) and not isinstance(x, bool) and x > 0 for x in v)","tryCatchPattern":"try:\n    config = build_parser_config(cfg=cfg)\nexcept ValueError as e:\n    if \"greater than zero\" in str(e):\n        cfg[\"lengthRange\"] = None  # default chunk size\n        config = build_parser_config(cfg=cfg)\n    else:\n        raise","preventionTips":["Enforce min=1 on length inputs in UI forms","Treat 0/negatives as 'unset' and drop them before calling","Clamp values with max(1, v) when a soft correction is acceptable","Add boundary tests for 0, -1, and 1 in parser-config tests"],"tags":["validation","ragflow","parser-config"],"backgroundTag":"value-out-of-range","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}