Skip to main content

CustomScript


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

  • Data from previous workflow nodes is passed into the script.

📤 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):

{
"custom_result": {
"processed": true,
"score": 95,
"status": "approved"
}
}

⚙️ Parameters

NameTypeRequiredDefaultDescription
Script ContentCode editorEmptyPython/JavaScript code executed by this node.
Programming Language (language)DropdownPythonDefautl to Python.
Script Encryption (encryption)ToggleOptionalOffProtects script code with encryption.
Encryption Password (password)PasswordRequired if encryption enabledEmptyPassword required to view/edit encrypted scripts.

💡 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

  • 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

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

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.