iflytek/astron-agent · error · CustomException
CODE_NODE_RESULT_TYPE_ERROR
CODE_NODE_RESULT_TYPE_ERROR
Error message
Code return type is not str, please check the type!
What it means
After the sandboxed code runs, _check_and_set_variable_pool validates each declared output variable against the node's output schema. When an output variable is declared with type "string" but the returned dict holds a non-str value (int, list, None, etc.), it raises CODE_NODE_RESULT_TYPE_ERROR. This catches contract drift between what the code node's output schema promises and what the script actually returns.
Solutions
- Open the code node and coerce the offending variable to str before returning: `return {"result": str(value)}`.
- Or change the output variable type in the node schema to match the actual runtime type (e.g. integer).
- Add explicit checks in the script for None/error paths so the variable is always a string.
- Re-run the code node in debug mode to inspect the raw returned dict and confirm each declared type.
- Note: bool is a subclass of int but not of str — ensure string outputs aren't accidentally booleans.
Example fix
// before
def main() -> dict:
return {"name": 123}
// after
def main() -> dict:
return {"name": str(123)} Defensive patterns
Strategy: type-guard
Validate before calling
outputs = {"name": value}
for k, t in declared_schema.items():
if t == "string" and not isinstance(outputs.get(k), str):
raise TypeError(f"output '{k}' must be str, got {type(outputs[k]).__name__}") Type guard
def is_str_output(v) -> bool:
return isinstance(v, str) Try / catch
try:
result = code_node.async_execute(...)
except CustomException as e:
if e.err_code == CodeEnum.CODE_NODE_RESULT_TYPE_ERROR:
log.error("code node output schema mismatch: coerce output to declared type")
raise Prevention
- Coerce every return value to its declared type before returning from main()
- Keep the node's output schema and the script's return statement in sync after edits
- Handle None/error branches explicitly so declared variables are always set
- Debug-run the node and print types of returned values
When it happens
Trigger: The code's main() returns a dict whose value for an output variable declared as "string" is not a Python str — e.g. returns 42 for a field typed string, or None when a branch fails to set the value.
Common situations: User edits the output schema to string but forgets to str() the value in code; JSON-parsed numbers passed through as-is; None returned on an error path; language coercion differences inside the sandbox (e.g. numbers for IDs like zip codes).
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
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/fc6ac8f455d527b1.
Report an issue: GitHub.
Appendix: source
Thrown at core/workflow/engine/nodes/code/code_node.py:229
outputs = {}
for var_name in self.output_identifier:
var_type = variable_pool.get_output_schema(
node_id=self.node_id, key_name=var_name
).get("type")
# If variable not in result, use existing value from variable pool
if var_name not in code_result_dict:
final_result = variable_pool.get_variable(
node_id=self.node_id, key_name=var_name, span=span
)
outputs.update({var_name: final_result})
continue
# Type validation based on expected output schema
match var_type:
case "string":
if isinstance(code_result_dict[var_name], str) is False:
raise CustomException(
CodeEnum.CODE_NODE_RESULT_TYPE_ERROR,
"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":View on GitHub (pinned to 5e758547a8)