For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
BlogLog InRequest Demo
HomeProductDevelopersSelf-HostingChangelog
HomeProductDevelopersSelf-HostingChangelog
  • Getting Started
    • Overview
  • Workflows SDK
    • Introduction
    • Installation
    • Core Concepts
    • Defining Control Flow
    • Configuration
    • Custom Docker Images
      • Displayable Nodes
        • Agent Node
        • Inline Prompt Node
        • Inline Subworkflow Node
        • Prompt Deployment Node
        • Search Node
        • Subworkflow Deployment Node
        • API Node
        • Code Execution Node
        • Templating Node
        • Guardrail Node
        • Map Node
        • Conditional Node
        • Merge Node
        • Error Node
        • Final Output Node
      • Datasets
      • CLI
  • Client SDK
    • Introduction
    • Authentication
    • API Versioning
LogoLogo
BlogLog InRequest Demo
Workflows SDKAPI ReferenceDisplayable Nodes

Code Execution Node

1from vellum.workflows.nodes import CodeExecutionNode
2from vellum import ChatMessage, CodeExecutionPackage
3from vellum.workflows.state import BaseState
4from typing import List, Dict
5
6class MyCodeExecutionNode(CodeExecutionNode[BaseState, Dict[str, Any]]):
7 filepath = "./scripts/process_data.py"
8 code_inputs = {
9 "text": "Process this text",
10 "chat_history": [
11 ChatMessage(role="user", content="Hello"),
12 ChatMessage(role="assistant", content="Hi there!")
13 ],
14 "config": {
15 "max_length": 100,
16 "temperature": 0.7
17 }
18 }
19 runtime = "PYTHON_3_11_6"
20 packages = [
21 CodeExecutionPackage(name="pandas", version="2.0.0"),
22 CodeExecutionPackage(name="numpy", version="1.24.0")
23 ]
1MyCodeExecutionNode.Outputs(
2 result={
3 "processed_text": "PROCESS THIS TEXT",
4 "history_length": 2,
5 "config_used": {
6 "max_length": 100,
7 "temperature": 0.7
8 }
9 },
10 log="INFO: Starting processing...\nINFO: Processing complete"
11)
Was this page helpful?
Previous

Templating Node

Next
Built with

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
strRequired

Path to the Python script file to execute

code_inputs
EntityInputsInterfaceRequired

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
CodeExecutionRuntimeDefaults to PYTHON_3_12

The runtime to use for the custom script

packages
Optional[Sequence[CodeExecutionPackage]]

The packages to use for the custom script

request_options
Optional[RequestOptions]

The request options to use for the custom script

Outputs

result
_OutputType

The result returned by the executed code, type depends on the node’s generic type parameter

log
str

The execution logs from the code run