iflytek/astron-agent · error · ValueError

lengthRange values must be greater than zero

Error message

lengthRange values must be greater than zero

What it means

build_parser_config requires every entry in lengthRange to be a strictly positive integer because the values become chunk token/length bounds in the RAGFlow parser config. A zero or negative value would produce an invalid chunking configuration, so it raises ValueError.

Solutions

  1. Clamp client values before calling: lr = [max(1, v) for v in lr]
  2. Validate at the API boundary and reject values <= 0 with a clear message
  3. Treat 0/negative as 'unset' and omit lengthRange so the 256 default applies
  4. Fix UI forms to enforce min=1 on length inputs

Example fix

// before
config = build_parser_config(cfg={"lengthRange": user_range})
// after
lr = [v for v in (user_range or []) if isinstance(v, int) and not isinstance(v, bool) and v > 0]
config = build_parser_config(cfg={"lengthRange": lr or None})
Defensive patterns

Strategy: validation

Validate before calling

def validate_positive_length_range(lr) -> list[int] | None:
    if lr in (None, []):
        return None
    if any(v <= 0 for v in lr):
        raise ValueError("lengthRange values must be > 0")
    return lr

Type guard

def has_positive_values(v) -> bool:
    return isinstance(v, list) and all(
        isinstance(x, int) and not isinstance(x, bool) and x > 0 for x in v)

Try / catch

try:
    config = build_parser_config(cfg=cfg)
except ValueError as e:
    if "greater than zero" in str(e):
        cfg["lengthRange"] = None  # default chunk size
        config = build_parser_config(cfg=cfg)
    else:
        raise

Prevention

When it happens

Trigger: Calling build_parser_config with lengthRange=[0], lengthRange=[-5, 100], or lengthRange=[100, 0] — any element <= 0.

Common situations: UI sending 0 as a 'no limit' placeholder; negative numbers from subtractive range computations; config templates with unfilled 0 defaults; user input not clamped to >= 1.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

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

        Returns:
            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)

View on GitHub (pinned to 5e758547a8)