The REPL (Read-Eval-Print Loop) node allows you to run custom code snippets as part of your AI workflow. This is powerful for data transformations, calculations, or custom logic not covered by standard nodes.
Overview
Use the REPL node when you need to:
- Transform or format data between nodes
- Perform mathematical calculations
- Parse or manipulate strings
- Implement custom business logic
- Process API responses into structured formats
Configuration
Basic Settings
- Title: A descriptive name for the node (e.g., “Calculate Total”, “Format Response”).
- Description: Document what your code does for future reference.
Runtime Environment
The REPL node runs in a secure, sandboxed environment. Below are the supported functions, libraries, and specific limitations.
Core Requirements
- Mandatory Main Function: Your code must include a
def main(): function.
- Guarded Iteration:
for and while loops are supported but monitored to prevent infinite execution.
Built-in Functions
You can use standard Python built-ins for data manipulation:
- Collection Helpers:
list, dict, tuple, set, enumerate, reversed
- Math & Logic:
max, min, sum, abs, all, any
- Utilities:
type
Supported Libraries
The following standard libraries are pre-installed and safe to import:
- Data & Formats:
json, xml, base64, pandas
- Networking:
requests
- Time & Dates:
datetime, time
- Utilities:
re (Regex), hashlib, hmac, secrets, typing
- Database:
sqlalchemy, sqlalchemy.orm, psycopg2
Security Restrictions
To ensure platform stability, the following are blocked:
- File System: No file I/O operations (e.g.,
open()).
- System Access: No OS/system functions or arbitrary imports outside the allowlist.
The code editor where you write your Python script. Your code has access to:
- Workflow variables: Use
{{variable_name}} syntax to access variables from previous nodes.
- Built-in functions: Standard Python libraries for data processing.
- Input variable selector: Map specific variables from previous nodes to use in your code.
- Output: The node passes the result of your code execution to downstream nodes via the Output handle.
Example: Parse a JSON response and extract specific fields:import json
data = json.loads({{api_response}})
result = data.get('items', [])[:5] # Get first 5 items
Code execution has resource limits and timeouts. Avoid infinite loops and memory-intensive operations.