infiniflow/ragflow · error · ValueError
Invalid input mode.
Error message
Invalid input mode.
What it means
ValueError from LoopItem.end(): when resolving the comparison value for a termination condition, input_mode must be exactly 'variable' or 'constant' (defaulting to 'constant' when absent). Any other string raises immediately.
Source
Thrown at agent/component/loopitem.py:142
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", "")
else:
raise ValueError("Invalid input mode.")
conditions.append(self.evaluate_condition(var, operator, value))
should_end = all(conditions) if logical_operator == "and" else any(conditions) if logical_operator == "or" else None
if should_end is None:
raise ValueError("Invalid logical operator,should be 'and' or 'or'.")
if should_end:
self._idx = -1
return True
return False
def next(self):
if self._idx == -1:
self._idx = 0
else:
self._idx += 1
if self._idx >= len(self._items):
self._idx = -1View on GitHub (pinned to 554fb1133a)
Solutions
- Set input_mode to exactly 'variable' or 'constant' (lowercase) on every termination-condition row.
- Omit input_mode entirely if the value is a constant — the default is 'constant'.
- Fix the JSON via the UI dropdown rather than free-text editing.
Example fix
// before
{"variable": "x", "operator": ">", "value": "5", "input_mode": "Value"}
// after
{"variable": "x", "operator": ">", "value": "5", "input_mode": "constant"} Defensive patterns
Strategy: validation
Validate before calling
for item in loop_param.loop_termination_condition:
mode = item.get('input_mode', 'constant')
assert mode in {'variable', 'constant'}, f'bad input_mode: {mode!r}' Type guard
def is_valid_input_mode(mode) -> bool:
return mode in ('variable', 'constant', None) Try / catch
try:
loop_item.end()
except ValueError as e:
if 'Invalid input mode' in str(e):
# set input_mode to 'constant' or 'variable' and re-save
... Prevention
- Use exactly lowercase 'variable' or 'constant' (or omit for constant default).
- Avoid copying input_mode values between different components' schemas.
- Prefer the UI dropdown over hand-editing JSON.
When it happens
Trigger: A loop_termination_condition item whose input_mode is misspelled ('vars', 'Constant ', 'ref') or set to a mode the Loop component does not support. Note: unlike Loop's own variable handling, there is no fallback branch here.
Common situations: Hand-written canvas JSON using a mode name from a different component; copy-paste between Loop loop_variables (which tolerate missing modes) and termination conditions (which do not); whitespace/case typos.
Related errors
- Loop Variable is not complete.
- Invalid operator: {operator}
- Loop condition is incomplete.
- Invalid logical operator,should be 'and' or 'or'.
- [Switch] 'To' can not be empty!
AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15).
Data as JSON: /api/errors/99ca78ea59040ad0.
Report an issue: GitHub.