{"record":{"id":"91dbbc86038d646f","repo":"iflytek/astron-agent","slug":"invalid-lengthrange-format-e-the-lengthrange-must-be-an","errorCode":null,"errorMessage":"Invalid lengthRange format: {e}；The lengthRange must be an array of integers","messagePattern":"Invalid lengthRange format: (.+?)；The lengthRange must be an array of integers","errorType":"validation","errorClass":"ProtocolParamException","httpStatus":400,"severity":"warning","filePath":"core/knowledge/api/v1/api.py","lineNumber":271,"sourceCode":"            cutOff=split_request.cutOff,\n            document_id=split_request.documentId,\n            group=split_request.group,\n            datasetId=split_request.datasetId,\n        )\n\n\nasync def parse_length_range(lengthRange: Optional[str]) -> Optional[List[int]]:\n    parsed_length_range = None\n    if lengthRange:\n        try:\n            parsed_length_range = json.loads(lengthRange)\n            # Invalid\n            if not all(isinstance(x, int) for x in parsed_length_range):\n                raise ProtocolParamException(\n                    msg=\"The lengthRange must be an array of integers\"\n                )\n        except (json.JSONDecodeError, ValueError) as e:\n            raise ProtocolParamException(\n                msg=f\"Invalid lengthRange format: {str(e)}；The lengthRange must be an array of integers\"\n            )\n    return parsed_length_range\n\n\nasync def parse_separator(separator: Optional[str]) -> Optional[List[str]]:\n    parsed_separator = None\n    if separator:\n        try:\n            parsed_separator = json.loads(separator)\n            # Invalid\n            if not all(isinstance(x, str) for x in parsed_separator):\n                raise ProtocolParamException(\n                    msg=\"The separator must be an array of strings\"\n                )\n        except (json.JSONDecodeError, ValueError) as e:\n            raise ProtocolParamException(\n                msg=f\"Invalid separator format: {str(e)}；The separator must be an array of strings\"","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/knowledge/api/v1/api.py#L253-L289","documentation":"ProtocolParamException raised by parse_length_range when the lengthRange parameter is not valid JSON at all — json.loads raises JSONDecodeError (or ValueError), and the API wraps it into a message that restates the expected format: an array of integers.","triggerScenarios":"file_upload receives lengthRange values like '[1,100' (truncated), '1-100' (range string, not JSON), or '1,100' (comma list without brackets).","commonSituations":"Clients passing raw 'min,max' strings instead of JSON arrays; URL-encoding issues where brackets are stripped so json.loads sees '1,100'; template code interpolating Python lists with single quotes producing invalid JSON ('[1, 100]' is fine, but \"['a']\" with single quotes is not).","solutions":["Send a properly encoded JSON array: lengthRange=[1,100] URL-encoded as %5B1%2C100%5D.","Fix the client to serialize with JSON.stringify/json.dumps rather than string concatenation.","If passing a Python list, use json.dumps(lengthRange) — not str(list) — so quotes/booleans are JSON-valid.","Decode the value with JSON.parse client-side first to confirm it is valid JSON before sending."],"exampleFix":"// before\nparams.append('lengthRange', `${min},${max}`)          // \"1,100\" -> JSONDecodeError\n// after\nparams.append('lengthRange', JSON.stringify([min, max])) // \"[1,100]\"","handlingStrategy":"validation","validationCode":"import json\ndef is_valid_json(raw: str) -> bool:\n    try:\n        json.loads(raw)\n        return True\n    except (json.JSONDecodeError, ValueError):\n        return False\n# fix the value until is_valid_json(length_range_param) is True","typeGuard":"def parses_as_json(raw) -> bool:\n    try:\n        json.loads(raw); return True\n    except Exception:\n        return False","tryCatchPattern":null,"preventionTips":["Always produce parameter values via json.dumps/JSON.stringify, never str() or templates.","URL-encode brackets and commas ([,] are percent-encoded in query strings).","Test the exact serialized value with json.loads before wiring it into requests.","Beware shell quoting with curl — prefer --data-urlencode."],"tags":["validation","json","request-params","knowledge"],"backgroundTag":"json-parse-error","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"}