Code Execution Node
vellum.workflows.nodes.CodeExecutionNode
Used to execute arbitrary Python code within your workflow. Supports custom package dependencies and any Python or TypeScript runtimes.
Important: Your code file must contain a main()
function with parameters that match the names of the node’s inputs. Without this function, you’ll get a NameError: name 'main' is not defined
error.
Attributes
filepath
Path to the Python script file to execute
code_inputs
The inputs for the custom script. Supports:
- Strings
- Numbers (float)
- Arrays
- Chat History (List[ChatMessage])
- Search Results (List[SearchResult])
- JSON objects (Dict[str, Any])
- Function Calls
- Errors
- Secrets
runtime
The runtime to use for the custom script
packages
The packages to use for the custom script
request_options
The request options to use for the custom script
Outputs
result
The result returned by the executed code, type depends on the node’s generic type parameter
log
The execution logs from the code run