infiniflow/ragflow · error · ContractError
CodeExec unsupported top-level result type: {type(value).__n
Error message
CodeExec unsupported top-level result type: {type(value).__name__}. Allowed top-level values are String, Number, Boolean, Object, Array, or Null. What it means
Error "CodeExec unsupported top-level result type: {type(value).__name__}. Allowed top-level values are String, Number, Boolean, Object, Array, or Null." thrown in infiniflow/ragflow.
Source
Thrown at agent/tools/code_exec.py:125
def render_canonical_content(value) -> str:
value = normalize_output_value(value)
if value is None:
return ""
if isinstance(value, str):
return value
if isinstance(value, (dict, list)):
return json.dumps(value, ensure_ascii=False, indent=2, sort_keys=True)
return str(value)
def _is_number(value) -> bool:
return isinstance(value, (int, float)) and not isinstance(value, bool)
def _validate_top_level_value_domain(value) -> None:
allowed = value is None or isinstance(value, (bool, str, dict, list)) or _is_number(value)
if not allowed:
raise ContractError(f"CodeExec unsupported top-level result type: {type(value).__name__}. Allowed top-level values are String, Number, Boolean, Object, Array, or Null.")
def _normalize_expected_type(expected_type: str) -> str:
etype = expected_type.strip()
low = etype.lower()
simple_types = {
"string": "String",
"number": "Number",
"boolean": "Boolean",
"object": "Object",
"null": "Null",
"any": "Any",
}
if low in simple_types:
return simple_types[low]
if low.startswith("array<") and low.endswith(">"):
inner = etype[etype.find("<") + 1 : -1].strip()
if not inner:View on GitHub (pinned to 554fb1133a)
Solutions
- Return a JSON-compatible top-level value (String, Number, Boolean, Object, Array, or Null) from the executed code.
- Serialize custom objects with json.dumps before returning.
Example fix
import json result = json.dumps(data) # instead of returning a raw custom object
When it happens
Trigger: Thrown at agent/tools/code_exec.py:125 when the library encounters an invalid state.
Common situations: Executed code returns a non-JSON-serializable object such as a set, bytes, or custom class; converting the result to a JSON type before returning prevents this error.
AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15).
Data as JSON: /api/errors/bb9d0916f7f951b6.
Report an issue: GitHub.