{"record":{"id":"2eba27d8828b5996","repo":"infiniflow/ragflow","slug":"codeexec-contract-mismatch-at-path-or-value-e","errorCode":null,"errorMessage":"CodeExec contract mismatch at {path or 'value'}: expected type {etype}, got {infer_actual_type(value)}","messagePattern":"CodeExec contract mismatch at (.+?): expected type (.+?), got (.+?)","errorType":"validation","errorClass":"ContractError","httpStatus":null,"severity":"error","filePath":"agent/tools/code_exec.py","lineNumber":159,"sourceCode":"    if low.startswith(\"array<\") and low.endswith(\">\"):\n        inner = etype[etype.find(\"<\") + 1 : -1].strip()\n        if not inner:\n            raise ContractError(f\"Unsupported expected type: {expected_type}\")\n        return f\"Array<{_normalize_expected_type(inner)}>\"\n    return etype\n\n\ndef _validate_expected_type(expected_type: str, value, path: str = \"\") -> None:\n    etype = _normalize_expected_type(expected_type)\n    if not etype or etype.lower() == \"any\":\n        return\n\n    value = normalize_output_value(value)\n\n    if etype.startswith(\"Array<\") and etype.endswith(\">\"):\n        inner_type = etype[6:-1].strip()\n        if not isinstance(value, list):\n            raise ContractError(f\"CodeExec contract mismatch at {path or 'value'}: expected type {etype}, got {infer_actual_type(value)}\")\n        for index, item in enumerate(value):\n            child_path = f\"{path}[{index}]\" if path else f\"[{index}]\"\n            _validate_expected_type(inner_type, item, child_path)\n        return\n\n    actual_type = infer_actual_type(value)\n    if etype == \"String\":\n        valid = isinstance(value, str)\n    elif etype == \"Number\":\n        valid = _is_number(value)\n    elif etype == \"Boolean\":\n        valid = isinstance(value, bool)\n    elif etype == \"Object\":\n        valid = isinstance(value, dict)\n    elif etype == \"Null\":\n        valid = value is None\n    else:\n        raise ContractError(f\"Unsupported expected type: {expected_type}\")","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/agent/tools/code_exec.py#L141-L177","documentation":"Error \"CodeExec contract mismatch at {path or 'value'}: expected type {etype}, got {infer_actual_type(value)}\" thrown in infiniflow/ragflow.","triggerScenarios":"Thrown at agent/tools/code_exec.py:159 when the library encounters an invalid state.","commonSituations":"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.","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."],"exampleFix":"# contract expects Array but code returned a dict\nresult = list(data.values())","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"}