Custom Script
Custom Script node for Builder — write and execute custom JavaScript or Python code inline within a workflow to implement bespoke logic, transformations, or integrations not covered by built-in nodes.
Purpose
Section titled “Purpose”The CustomScript node allows you to execute custom code inside ThreoAI workflows.
It supports Python, enabling complex data processing, calculations, integrations, and business logic beyond standard nodes.
📥 Inputs
Section titled “📥 Inputs”- Data from previous workflow nodes is passed into the script.
📤 Outputs
Section titled “📤 Outputs”- Script output is passed to the next workflow node.
- Must be wrapped inside a unique JSON object name (e.g.,
{"custom_result": {...}}).
Output Format (example):
json { "custom_result": { "processed": true, "score": 95, "status": "approved" } }
⚙️ Parameters
Section titled “⚙️ Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| Script Content | Code editor | ✅ | Empty | Python/JavaScript code executed by this node. |
Programming Language (language) | Dropdown | ✅ | Python | Defautl to Python. |
Script Encryption (encryption) | Toggle | Optional | Off | Protects script code with encryption. |
Encryption Password (password) | Password | Required if encryption enabled | Empty | Password required to view/edit encrypted scripts. |
💡 Example Usage
Section titled “💡 Example Usage”- Loyalty Points Calculator (Python): Apply custom rules combining purchase data, customer tiers, and seasonal bonuses.
- Invoice Validation: Flag incomplete or suspicious invoice data before payment processing.
- Sales Analytics: Calculate growth rates, quotas, and rankings across multiple data sources.
📘 Best Practices
Section titled “📘 Best Practices”- Start with simple scripts and test often.
- Apply error handling (
try/except) to avoid workflow failures. - Always return results wrapped in a unique JSON object name.
⚡ Python Execution Contract
Section titled “⚡ Python Execution Contract”Each Python script must define an execute function as the entry point:
def execute(input_json, meta): # input_json: data received from the previous node # meta: metadata provided by the workflow engine
# Example: echo input with added field result = { "custom_result": { "original": input_json, "processed": True } }
return result```text### Rules
- `input_json`: Contains data passed from the previous node.- `meta`: Contains workflow context and metadata.- Output must be wrapped in a **unique JSON object name** (e.g., `"custom_result"`) to avoid collisions with other nodes.- The return value must be JSON-serializable.