{"record":{"id":"ea4e3245e5de2601","repo":"iflytek/astron-agent","slug":"lengthrange-minimum-cannot-exceed-maximum","errorCode":null,"errorMessage":"lengthRange minimum cannot exceed maximum","messagePattern":"lengthRange minimum cannot exceed maximum","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"core/knowledge/infra/ragflow/ragflow_utils.py","lineNumber":522,"sourceCode":"            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)\n\n        parser_config = {","sourceCodeStart":504,"sourceCodeEnd":540,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/knowledge/infra/ragflow/ragflow_utils.py#L504-L540","documentation":"When lengthRange has two values, build_parser_config interprets them as [min, max] for chunk length and raises ValueError if the first exceeds the second, since min > max is an invalid range. This happens after the count/positivity checks, so the values are valid positive ints but wrongly ordered.","triggerScenarios":"Calling build_parser_config with lengthRange=[500, 200] — two positive integers where element 0 > element 1.","commonSituations":"UI slider inputs bound to the wrong fields; locales/APIs that send (max, min) ordering while the backend expects (min, max); swap bugs in client-side range widgets.","solutions":["Sort the pair before calling: lr = sorted(lr)","Confirm the client sends (min, max) in that order and fix the UI field mapping if swapped","Normalize on the server: if len(lr) == 2 and lr[0] > lr[1], swap or reject with 400","Add a form-level min<=max validation in the frontend"],"exampleFix":"// before\nconfig = build_parser_config(cfg={\"lengthRange\": lr})\n// after\nif len(lr) == 2 and lr[0] > lr[1]:\n    lr = [lr[1], lr[0]]\nconfig = build_parser_config(cfg={\"lengthRange\": lr})","handlingStrategy":"validation","validationCode":"def normalize_length_range(lr) -> list[int] | None:\n    if lr in (None, []):\n        return None\n    if len(lr) == 2 and lr[0] > lr[1]:\n        lr = [lr[1], lr[0]]  # or raise, depending on strictness\n    return lr","typeGuard":"def is_ordered_range(v) -> bool:\n    return not (isinstance(v, list) and len(v) == 2 and v[0] > v[1])","tryCatchPattern":"try:\n    config = build_parser_config(cfg=cfg)\nexcept ValueError as e:\n    if \"cannot exceed maximum\" in str(e):\n        lr = sorted(cfg[\"lengthRange\"])\n        cfg[\"lengthRange\"] = lr\n        config = build_parser_config(cfg=cfg)\n    else:\n        raise","preventionTips":["Sort (min, max) pairs client-side before sending","Verify which order your UI range widget emits (max,min vs min,max)","Add min<=max validation in the form and in the API schema","Unit-test build_parser_config with swapped ranges"],"tags":["validation","ragflow","parser-config"],"backgroundTag":"invalid-argument-value","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"}