infiniflow/ragflow · error · Exception

Invalid operator: {operator}

Error message

Invalid operator: {operator}

What it means

Generic Exception from LoopItem.evaluate_condition: after walking all supported operator branches (comparisons, contains, is/is not, empty/not empty, with None handling), an unrecognized operator string falls through to this raise. It signals canvas data containing an operator outside the evaluated set.

Source

Thrown at agent/component/loopitem.py:122

                return value in var
            elif operator == "not contains":
                return value not in var

            elif operator == "is":
                return var == value
            elif operator == "is not":
                return var != value

            elif operator == "empty":
                return len(var) == 0
            elif operator == "not empty":
                return len(var) > 0
        elif var is None:
            if operator == "empty":
                return True
            return False

        raise Exception(f"Invalid operator: {operator}")

    def end(self):
        if self._idx == -1:
            return True
        parent = self.get_parent()
        logical_operator = parent._param.logical_operator if hasattr(parent._param, "logical_operator") else "and"
        conditions = []
        for item in parent._param.loop_termination_condition:
            if not item.get("variable") or not item.get("operator"):
                raise ValueError("Loop condition is incomplete.")
            var = self._canvas.get_variable_value(item["variable"])
            operator = item["operator"]
            input_mode = item.get("input_mode", "constant")

            if input_mode == "variable":
                value = self._canvas.get_variable_value(item.get("value", ""))
            elif input_mode == "constant":
                value = item.get("value", "")

View on GitHub (pinned to 554fb1133a)

Solutions

  1. Open the loop termination condition and pick the operator from the dropdown instead of typing it.
  2. If editing JSON directly, use exactly the operators the component implements (e.g. '=', '≠', '>', '<', '≥', '≤', 'contains', 'empty').
  3. Re-create the condition row from scratch rather than patching the operator string.

Example fix

// before
{"variable": "x", "operator": ">=", "value": 5}

// after
{"variable": "x", "operator": "≥", "value": 5}
Defensive patterns

Strategy: validation

Validate before calling

VALID_OPS = {'=', '≠', '>', '<', '≥', '≤', 'contains', 'not contains', 'is', 'is not', 'empty', 'not empty'}
for item in parent._param.loop_termination_condition:
    assert item['operator'] in VALID_OPS, item['operator']

Type guard

def is_valid_loop_operator(op: str) -> bool:
    return op in {'=', '≠', '>', '<', '≥', '≤', 'contains', 'not contains', 'is', 'is not', 'empty', 'not empty'}

Try / catch

try:
    loop_item.end()
except Exception as e:
    if 'Invalid operator' in str(e):
        # pick operator from UI dropdown and re-save
        ...

Prevention

When it happens

Trigger: A loop_termination_condition entry whose 'operator' field is a typo or unsupported value (e.g. '>=' instead of '≥', 'includes', empty string combined with a non-None var). The check at loopitem.py:132 only requires operator to be truthy, not valid, so bad values reach evaluate_condition.

Common situations: Hand-editing canvas JSON and entering a JS-style operator; version drift where a template was authored against a different operator vocabulary; frontend saved a localized operator label.

Related errors


AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15). Data as JSON: /api/errors/7469ae4f4062a57c. Report an issue: GitHub.