Skip to content

Code Execution Node

The Code Execution Node is a node that allows users to execute program code defined by themselves. It runs in a secure sandboxed environment.

code execution node

  • Language
    • Supports Python and JavaScript.
  • Input Variables
    • You can use outputs from other nodes as variables.
  • Code
    • Accepts arguments with the same names as input variables and allows you to write code freely. The return value is output from the node.

Here we introduce an example of calculating the character count of an input query using the Code Execution Node and outputting a message. By applying this, you can ensure that LLM-generated text stays within a specified character limit.

After creating a new workflow, select the Code Execution Node and copy and paste the following content:

  • Language
    • Python
  • Input Variables
    • text: query(start)
def main(text: str):
return {"character_count": len(text)}

calc length

Add an LLM Node after the Code Execution Node and copy and paste the following content into the prompt:

Output the character count of the input text as: The input text has 〇〇 characters.
{{#code-1.response#}}

Now, click the debug button to run the workflow. Let’s use “Hello, World!” as the input text. The final output will be “The input text has 13 characters.”

result

  • Python
    • pandas
    • numpy
    • openpyxl
    • matplotlib
    • seaborn
    • scikit-learn
    • regex
    • reportlab
    • pypdf
    • pymupdf
    • Pillow
  • JavaScript
    • pptxgenjs
    • papaparse
    • date-fns
  • External API calls (HTTP requests, etc.)
  • Library installation

Last updated: