{"record":{"id":"e00f6dc6840fc850","repo":"iflytek/astron-agent","slug":"the-lengthrange-must-be-an-array-of-integers","errorCode":null,"errorMessage":"The lengthRange must be an array of integers","messagePattern":"The lengthRange must be an array of integers","errorType":"validation","errorClass":"ProtocolParamException","httpStatus":400,"severity":"warning","filePath":"core/knowledge/api/v1/api.py","lineNumber":267,"sourceCode":"            lengthRange=split_request.lengthRange,\n            overlap=split_request.overlap,\n            separator=split_request.separator,\n            titleSplit=split_request.titleSplit,\n            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\"","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/knowledge/api/v1/api.py#L249-L285","documentation":"ProtocolParamException raised by parse_length_range in the knowledge service upload API when the lengthRange query/form parameter parses as JSON but contains non-integer elements (e.g. floats or strings). The API requires an array of integers like [1,100].","triggerScenarios":"file_upload receives lengthRange='[1.0, 100]' or '[\"1\", \"100\"]' — json.loads succeeds but all(isinstance(x, int)) fails, so ProtocolParamException is raised intentionally.","commonSituations":"Frontend serializes numbers as floats (1.0) or strings; clients send ranges quoted incorrectly; Swagger/curl users passing JSON with decimal bounds; JS JSON.stringify producing floats from computed values.","solutions":["Send lengthRange as a JSON array of plain integers, e.g. lengthRange=%5B1%2C100%5D for [1,100].","On the client, coerce values before sending: JSON.stringify([Math.trunc(min), Math.trunc(max)]).","If decimals are legitimate, ask the backend to relax the check or round server-side.","Validate the payload with JSON.parse and Array.every(Number.isInteger) before calling the API."],"exampleFix":"// before\nconst lengthRange = [chunkMin.toFixed(0) + '', chunkMax + '']; // [\"1\",\"100\"] strings\n// after\nconst lengthRange = [Math.trunc(chunkMin), Math.trunc(chunkMax)]; // [1,100]\nif (!lengthRange.every(Number.isInteger)) throw new Error('lengthRange must be integers');\nbody.append('lengthRange', JSON.stringify(lengthRange));","handlingStrategy":"validation","validationCode":"import json\ndef valid_length_range(raw):\n    try:\n        val = json.loads(raw)\n    except (json.JSONDecodeError, ValueError):\n        return False\n    return isinstance(val, list) and len(val) == 2 and all(isinstance(x, int) and not isinstance(x, bool) for x in val)\n# call the API only if valid_length_range(length_range_param)","typeGuard":"def is_int_array(val) -> bool:\n    return isinstance(val, list) and all(isinstance(x, int) and not isinstance(x, bool) for x in val)","tryCatchPattern":null,"preventionTips":["Serialize numeric params with JSON.stringify/json.dumps, never string concatenation.","Note that Python bool is a subclass of int — reject true/false explicitly if ambiguity matters.","Validate parameters client-side before each upload request.","Document the exact expected format ([min,max] integers) in the API client."],"tags":["validation","request-params","knowledge","json"],"backgroundTag":"schema-validation-failed","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"}