iflytek/astron-agent · error · ValueError

lengthRange minimum cannot exceed maximum

Error message

lengthRange minimum cannot exceed maximum

What it means

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.

Solutions

  1. Sort the pair before calling: lr = sorted(lr)
  2. Confirm the client sends (min, max) in that order and fix the UI field mapping if swapped
  3. Normalize on the server: if len(lr) == 2 and lr[0] > lr[1], swap or reject with 400
  4. Add a form-level min<=max validation in the frontend

Example fix

// before
config = build_parser_config(cfg={"lengthRange": lr})
// after
if len(lr) == 2 and lr[0] > lr[1]:
    lr = [lr[1], lr[0]]
config = build_parser_config(cfg={"lengthRange": lr})
Defensive patterns

Strategy: validation

Validate before calling

def normalize_length_range(lr) -> list[int] | None:
    if lr in (None, []):
        return None
    if len(lr) == 2 and lr[0] > lr[1]:
        lr = [lr[1], lr[0]]  # or raise, depending on strictness
    return lr

Type guard

def is_ordered_range(v) -> bool:
    return not (isinstance(v, list) and len(v) == 2 and v[0] > v[1])

Try / catch

try:
    config = build_parser_config(cfg=cfg)
except ValueError as e:
    if "cannot exceed maximum" in str(e):
        lr = sorted(cfg["lengthRange"])
        cfg["lengthRange"] = lr
        config = build_parser_config(cfg=cfg)
    else:
        raise

Prevention

When it happens

Trigger: Calling build_parser_config with lengthRange=[500, 200] — two positive integers where element 0 > element 1.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/ea4e3245e5de2601. Report an issue: GitHub.

Appendix: source

Thrown at core/knowledge/infra/ragflow/ragflow_utils.py:522

            Parser configuration dictionary
        """
        # RAGFlow's parser uses the configured maximum as its target chunk
        # size. ``overlap`` and ``titleSplit`` are intentionally not forwarded:
        # v0.20.5 has no overlap field, and title splitting is not equivalent
        # to changing PDF layout recognition/OCR mode.
        _ = overlap, titleSplit
        if lengthRange is None:
            chunk_token_num = 256
        else:
            if len(lengthRange) not in (1, 2) or any(
                isinstance(value, bool) or not isinstance(value, int)
                for value in lengthRange
            ):
                raise ValueError("lengthRange must contain one or two integers")
            if any(value <= 0 for value in lengthRange):
                raise ValueError("lengthRange values must be greater than zero")
            if len(lengthRange) == 2 and lengthRange[0] > lengthRange[1]:
                raise ValueError("lengthRange minimum cannot exceed maximum")
            chunk_token_num = lengthRange[-1]

        # The Astron UI can send either a literal ``\\n`` or an actual newline.
        # In RAGFlow v0.20.5, unquoted delimiter characters are independent;
        # a multi-character delimiter must be wrapped in backticks.
        normalized_separators = []
        for value in separator or []:
            normalized = value.replace("\\n", "\n")
            if not normalized:
                continue
            normalized_separators.append(
                normalized if len(normalized) == 1 else f"`{normalized}`"
            )
        if not any("\n" in value for value in normalized_separators):
            normalized_separators.append("\n")
        delimiter = "".join(normalized_separators)

        parser_config = {

View on GitHub (pinned to 5e758547a8)