iflytek/astron-agent · warning · ProtocolParamException
Invalid lengthRange format
Error message
Invalid lengthRange format: {e};The lengthRange must be an array of integers What it means
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.
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.
Example fix
// before
params.append('lengthRange', `${min},${max}`) // "1,100" -> JSONDecodeError
// after
params.append('lengthRange', JSON.stringify([min, max])) // "[1,100]" Defensive patterns
Strategy: validation
Validate before calling
import json
def is_valid_json(raw: str) -> bool:
try:
json.loads(raw)
return True
except (json.JSONDecodeError, ValueError):
return False
# fix the value until is_valid_json(length_range_param) is True Type guard
def parses_as_json(raw) -> bool:
try:
json.loads(raw); return True
except Exception:
return False Prevention
- 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.
When it happens
Trigger: file_upload receives lengthRange values like '[1,100' (truncated), '1-100' (range string, not JSON), or '1,100' (comma list without brackets).
Common situations: 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).
Understand the failure class
Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.
Related errors
- The lengthRange must be an array of integers
- The separator must be an array of strings
- Invalid separator format
- PARAMS_ERROR
- PARAMETER_ERROR
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/91dbbc86038d646f.
Report an issue: GitHub.
Appendix: source
Thrown at core/knowledge/api/v1/api.py:271
cutOff=split_request.cutOff,
document_id=split_request.documentId,
group=split_request.group,
datasetId=split_request.datasetId,
)
async def parse_length_range(lengthRange: Optional[str]) -> Optional[List[int]]:
parsed_length_range = None
if lengthRange:
try:
parsed_length_range = json.loads(lengthRange)
# Invalid
if not all(isinstance(x, int) for x in parsed_length_range):
raise ProtocolParamException(
msg="The lengthRange must be an array of integers"
)
except (json.JSONDecodeError, ValueError) as e:
raise ProtocolParamException(
msg=f"Invalid lengthRange format: {str(e)};The lengthRange must be an array of integers"
)
return parsed_length_range
async def parse_separator(separator: Optional[str]) -> Optional[List[str]]:
parsed_separator = None
if separator:
try:
parsed_separator = json.loads(separator)
# Invalid
if not all(isinstance(x, str) for x in parsed_separator):
raise ProtocolParamException(
msg="The separator must be an array of strings"
)
except (json.JSONDecodeError, ValueError) as e:
raise ProtocolParamException(
msg=f"Invalid separator format: {str(e)};The separator must be an array of strings"View on GitHub (pinned to 5e758547a8)