{"record":{"id":"66a518e4ed9498b2","repo":"iflytek/astron-agent","slug":"21602-code-return-type-is-not-bool-please-check-the-type","errorCode":"21602","errorMessage":"Code return type is not bool, please check the type!","messagePattern":"Code return type is not bool, please check the type!","errorType":"error_code","errorClass":"CustomException","httpStatus":null,"severity":"error","filePath":"core/workflow/engine/nodes/code/code_node.py","lineNumber":249,"sourceCode":"                            \"Code return type is not str, please check the type!\",\n                        )\n                case \"integer\":\n                    if isinstance(code_result_dict[var_name], int) is False:\n                        raise CustomException(\n                            CodeEnum.CODE_NODE_RESULT_TYPE_ERROR,\n                            \"Code return type is not integer, please check the type!\",\n                        )\n\n                case \"number\":\n                    if isinstance(code_result_dict[var_name], (int, float)) is False:\n                        raise CustomException(\n                            CodeEnum.CODE_NODE_RESULT_TYPE_ERROR,\n                            \"Code return type is not integer or float, please check the type!\",\n                        )\n\n                case \"boolean\":\n                    if isinstance(code_result_dict[var_name], bool) is False:\n                        raise CustomException(\n                            CodeEnum.CODE_NODE_RESULT_TYPE_ERROR,\n                            \"Code return type is not bool, please check the type!\",\n                        )\n\n                case \"array\":\n                    if isinstance(code_result_dict[var_name], list) is False:\n                        raise CustomException(\n                            CodeEnum.CODE_NODE_RESULT_TYPE_ERROR,\n                            \"Code return type is not array, please check the type!\",\n                        )\n\n                case \"object\":\n                    if isinstance(code_result_dict[var_name], dict) is False:\n                        raise CustomException(\n                            CodeEnum.CODE_NODE_RESULT_TYPE_ERROR,\n                            \"Code return type is not object, please check the type!\",\n                        )\n","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/workflow/engine/nodes/code/code_node.py#L231-L267","documentation":"The boolean case of the output schema validator in _check_and_set_variable_pool: a variable declared as \"boolean\" must be an actual bool instance. Returning 1/0, \"true\", or None raises CODE_NODE_RESULT_TYPE_ERROR (numeric code 21602). Python's isinstance check here does not accept ints even though bool subclasses int — the validator requires an exact bool.","triggerScenarios":"Script returns 1/0, \"true\"/\"false\" strings, or None for an output variable typed \"boolean\" in the node's output schema.","commonSituations":"Flags computed from comparisons that were then converted to int; truthy strings from LLM or HTTP responses passed through; None from a missing branch; users coming from languages where 0/1 are idiomatic booleans.","solutions":["Wrap the value with bool(): `return {\"enabled\": bool(value)}`.","Parse string flags explicitly: `value == \"true\"` or `value.lower() in {\"1\",\"true\",\"yes\"}`.","Ensure all return paths of main() set the boolean variable.","If the value is truly 0/1 numeric, change the schema type to integer instead.","Debug-run the node printing type(value) to see what the sandbox returns."],"exampleFix":"// before\ndef main(x) -> dict:\n    return {\"ok\": 1 if x else 0}\n\n// after\ndef main(x) -> dict:\n    return {\"ok\": bool(x)}","handlingStrategy":"type-guard","validationCode":"for k, t in declared_schema.items():\n    if t == \"boolean\" and not isinstance(outputs.get(k), bool):\n        raise TypeError(f\"output '{k}' must be bool, got {type(outputs[k]).__name__}\")","typeGuard":"def is_bool_output(v) -> bool:\n    return isinstance(v, bool)","tryCatchPattern":"try:\n    result = code_node.async_execute(...)\nexcept CustomException as e:\n    if e.err_code == CodeEnum.CODE_NODE_RESULT_TYPE_ERROR:\n        log.error(\"boolean output mismatch: wrap value in bool() before returning\")\n        raise","preventionTips":["Wrap flag values with bool() before returning","Parse 'true'/'false' strings with explicit comparison instead of passing through","Don't use 1/0 for boolean-declared outputs","Return False (not None) on indeterminate paths"],"tags":["type-error","code-node","validation","workflow"],"backgroundTag":"type-mismatch","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}