infiniflow/ragflow · error · ContractError
CodeExec contract mismatch at {path or 'value'}: expected ty
Error message
CodeExec contract mismatch at {path or 'value'}: expected type {etype}, got {infer_actual_type(value)} What it means
Error "CodeExec contract mismatch at {path or 'value'}: expected type {etype}, got {infer_actual_type(value)}" thrown in infiniflow/ragflow.
Source
Thrown at agent/tools/code_exec.py:159
if low.startswith("array<") and low.endswith(">"):
inner = etype[etype.find("<") + 1 : -1].strip()
if not inner:
raise ContractError(f"Unsupported expected type: {expected_type}")
return f"Array<{_normalize_expected_type(inner)}>"
return etype
def _validate_expected_type(expected_type: str, value, path: str = "") -> None:
etype = _normalize_expected_type(expected_type)
if not etype or etype.lower() == "any":
return
value = normalize_output_value(value)
if etype.startswith("Array<") and etype.endswith(">"):
inner_type = etype[6:-1].strip()
if not isinstance(value, list):
raise ContractError(f"CodeExec contract mismatch at {path or 'value'}: expected type {etype}, got {infer_actual_type(value)}")
for index, item in enumerate(value):
child_path = f"{path}[{index}]" if path else f"[{index}]"
_validate_expected_type(inner_type, item, child_path)
return
actual_type = infer_actual_type(value)
if etype == "String":
valid = isinstance(value, str)
elif etype == "Number":
valid = _is_number(value)
elif etype == "Boolean":
valid = isinstance(value, bool)
elif etype == "Object":
valid = isinstance(value, dict)
elif etype == "Null":
valid = value is None
else:
raise ContractError(f"Unsupported expected type: {expected_type}")View on GitHub (pinned to 554fb1133a)
Solutions
- Make the executed code return a value whose type matches the declared contract at the reported path.
- Adjust the contract type if the code's actual output shape is intended.
Example fix
# contract expects Array but code returned a dict result = list(data.values())
When it happens
Trigger: Thrown at agent/tools/code_exec.py:159 when the library encounters an invalid state.
Common situations: The runtime value returned by the executed code does not match the declared contract type at the given path; aligning the code output with the contract (or vice versa) prevents this error.
AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15).
Data as JSON: /api/errors/2eba27d8828b5996.
Report an issue: GitHub.