{"record":{"id":"bb9d0916f7f951b6","repo":"infiniflow/ragflow","slug":"codeexec-unsupported-top-level-result-type-type","errorCode":null,"errorMessage":"CodeExec unsupported top-level result type: {type(value).__name__}. Allowed top-level values are String, Number, Boolean, Object, Array, or Null.","messagePattern":"CodeExec unsupported top-level result type: (.+?)\\. Allowed top-level values are String, Number, Boolean, Object, Array, or Null\\.","errorType":"validation","errorClass":"ContractError","httpStatus":null,"severity":"error","filePath":"agent/tools/code_exec.py","lineNumber":125,"sourceCode":"def render_canonical_content(value) -> str:\n    value = normalize_output_value(value)\n    if value is None:\n        return \"\"\n    if isinstance(value, str):\n        return value\n    if isinstance(value, (dict, list)):\n        return json.dumps(value, ensure_ascii=False, indent=2, sort_keys=True)\n    return str(value)\n\n\ndef _is_number(value) -> bool:\n    return isinstance(value, (int, float)) and not isinstance(value, bool)\n\n\ndef _validate_top_level_value_domain(value) -> None:\n    allowed = value is None or isinstance(value, (bool, str, dict, list)) or _is_number(value)\n    if not allowed:\n        raise ContractError(f\"CodeExec unsupported top-level result type: {type(value).__name__}. Allowed top-level values are String, Number, Boolean, Object, Array, or Null.\")\n\n\ndef _normalize_expected_type(expected_type: str) -> str:\n    etype = expected_type.strip()\n    low = etype.lower()\n    simple_types = {\n        \"string\": \"String\",\n        \"number\": \"Number\",\n        \"boolean\": \"Boolean\",\n        \"object\": \"Object\",\n        \"null\": \"Null\",\n        \"any\": \"Any\",\n    }\n    if low in simple_types:\n        return simple_types[low]\n    if low.startswith(\"array<\") and low.endswith(\">\"):\n        inner = etype[etype.find(\"<\") + 1 : -1].strip()\n        if not inner:","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/agent/tools/code_exec.py#L107-L143","documentation":"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.","triggerScenarios":"Thrown at agent/tools/code_exec.py:125 when the library encounters an invalid state.","commonSituations":"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.","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."],"exampleFix":"import json\nresult = json.dumps(data)  # instead of returning a raw custom object","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}