iflytek/astron-agent · error · CustomException
21602
21602
Error message
Code return type is not bool, please check the type!
What it means
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.
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.
Example fix
// before
def main(x) -> dict:
return {"ok": 1 if x else 0}
// after
def main(x) -> dict:
return {"ok": bool(x)} Defensive patterns
Strategy: type-guard
Validate before calling
for k, t in declared_schema.items():
if t == "boolean" and not isinstance(outputs.get(k), bool):
raise TypeError(f"output '{k}' must be bool, got {type(outputs[k]).__name__}") Type guard
def is_bool_output(v) -> bool:
return isinstance(v, bool) Try / catch
try:
result = code_node.async_execute(...)
except CustomException as e:
if e.err_code == CodeEnum.CODE_NODE_RESULT_TYPE_ERROR:
log.error("boolean output mismatch: wrap value in bool() before returning")
raise Prevention
- 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
When it happens
Trigger: Script returns 1/0, "true"/"false" strings, or None for an output variable typed "boolean" in the node's output schema.
Common situations: 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.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- CODE_NODE_RESULT_TYPE_ERROR
- WORKFLOW_VERSION_PUBLISH_FAILED
- 8008
- 8008
- WORKFLOW_PROTOCOL_NODE_INFO_CANNOT_EMPTY
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/66a518e4ed9498b2.
Report an issue: GitHub.
Appendix: source
Thrown at core/workflow/engine/nodes/code/code_node.py:249
"Code return type is not str, please check the type!",
)
case "integer":
if isinstance(code_result_dict[var_name], int) is False:
raise CustomException(
CodeEnum.CODE_NODE_RESULT_TYPE_ERROR,
"Code return type is not integer, please check the type!",
)
case "number":
if isinstance(code_result_dict[var_name], (int, float)) is False:
raise CustomException(
CodeEnum.CODE_NODE_RESULT_TYPE_ERROR,
"Code return type is not integer or float, please check the type!",
)
case "boolean":
if isinstance(code_result_dict[var_name], bool) is False:
raise CustomException(
CodeEnum.CODE_NODE_RESULT_TYPE_ERROR,
"Code return type is not bool, please check the type!",
)
case "array":
if isinstance(code_result_dict[var_name], list) is False:
raise CustomException(
CodeEnum.CODE_NODE_RESULT_TYPE_ERROR,
"Code return type is not array, please check the type!",
)
case "object":
if isinstance(code_result_dict[var_name], dict) is False:
raise CustomException(
CodeEnum.CODE_NODE_RESULT_TYPE_ERROR,
"Code return type is not object, please check the type!",
)
View on GitHub (pinned to 5e758547a8)