Skip to main content
Using an AI coding assistant? Connect Cursor, Claude, or Copilot to Snag Docs for context-aware help. Learn how.

Overview

To maintain consistency and security, all Stratus functions are validated before they are saved. This guide explains the required syntax, module restrictions, and best practices to help you create functions that pass validation.

Module Export & Handler Function

Single Handler Export

Your code must export exactly one handler function.
Exporting multiple handler definitions or not exporting a handler at all will cause validation to fail.

Proper Export Format

Always export your handler as a property of module.exports.
The exported handler must be a function. Assigning non-function values (e.g., a string) will trigger an error.

Handler Function Parameters & Behavior

Parameter Requirements

The handler function must accept exactly two parameters:
  • input – holds input data
  • output – provides methods for setting and building the function’s output

Using output.setResult

Inside your handler, you must call output.setResult to set the result object.

Calling output.buildOutput()

The handler must return the result of output.buildOutput(). Omitting this call is not allowed.
If the handler does not accept exactly two parameters, validation will fail with a message similar to: “The ‘handler’ function must accept exactly two parameters: ‘input’ and ‘output’.”

Module Import Requirements

Allowed Modules

You may include external modules via require(), but only approved packages are allowed:
  • axios
  • lodash
  • viem and its approved subpath viem/chains

Disallowed Modules

The following are not allowed:
  • Modules not on the approved list (e.g., Node’s fs)
  • Unapproved subpaths from approved packages
  • Dynamic requires (using variables for module names)

Extra Exports

Adding extra properties to module.exports (aside from the handler) is allowed and will not affect validation:

JavaScript Syntax

Valid JavaScript

Your code must be syntactically valid JavaScript. Common syntax errors include:
  • Missing closing braces
  • Unmatched parentheses
  • Invalid syntax

Common Validation Error Messages

You may encounter the following validation errors:

Examples

Valid Stratus Function with External Module

Valid Function Without External Modules

Common Mistakes

Summary

To ensure your Stratus function passes syntax validation:
  • Export one handler function using the correct module export syntax
  • Ensure the handler is asynchronous and accepts exactly two parameters: input and output
  • Call both output.setResult and output.buildOutput() within your handler
  • Import only approved modules using string literals (no dynamic requires)
  • Write valid JavaScript with correct syntax