Updated on 2025-07-02 GMT+08:00

Code Node

The Code node allows you to write Python code to process complex logic such as text and generate expected return values.

The Code node is an optional node. If it does not need to be configured, skip this section.

To configure the Code node, perform the following steps:

  1. Drag the Code node on the left to the canvas and click the node to open the node configuration page.
  2. Configure the Code node by referring to Table 1.
    Table 1 Code node configuration

    Configuration Type

    Parameter Name

    Description

    Parameter configuration

    Input params

    Configure the input parameters required for code running.

    • Param name: The value can contain only letters, digits, and underscores (_), and cannot start with a digit.
    • Type and Value: Type can be set to ref and literal.
      • ref: You can select the output parameters of the previous nodes contained in the workflow.
      • literal: The value can be customized.

    Output params

    Configure parameters that need to be output after the code is executed. The parameters must be the same as those returned by return.

    • Param name: The value can contain only letters, digits, and underscores (_), and cannot start with a digit.
    • Param type: output parameter type. The options are String, Integer, Number, Boolean, and more.
    • Description: description of the output parameter.
    • Required: whether the current output parameter is mandatory.

    Code

    -

    You can compile Python code snippets. Only the Python system library is supported, and dependency packages cannot be imported. The following is an example of code configuration:

    • Sample code for text stitching
      def main(args: dict) -> dict:
      # Define a variable named input1 in the input parameters.
          input1 = args.get('input1')
      # Define a variable named input2 in the input parameters.
          input2 = args.get('input2')
          res = {
      # Define a variable named res in the output parameters.
              "res": input1 + input2,
          }
          return res
    • Sample code for mathematical calculation
      def main(args: dict) -> dict:
      # Define a variable named input1 in the input parameters.
          input1 = args.get('input1')
          try:
              input1 = int(input1)
              return {
      # Define res in the output parameters.
                  'res': input1 * input1
                  }
          except Exception as e:
              return {
      # Define res in the output parameters.
      'res': "The input type is incorrect or the number exceeds the upper limit."
                  }
    NOTE:

    Do not change the function definition in the first line when writing code.

    Figure 1 Code node configuration example

  3. After completing the configuration, click OK.
  4. Connect the Code node to other nodes.