Portal Community

Input Data Shape

The input to execute(input) is a plain JavaScript object constructed from the caller's data:

CallerInput SourceExample Input
LLM Tool CallLLM-constructed JSON from the tool schema{ employeeId: "EMP-42", year: 2025 }
Flow Studio NodeNode's input data (mapped from workflow variables){ amount: 1500, currency: "EUR" }
Direct API callRequest body JSON{ text: "Hello world", targetLang: "fr" }

Accessing Input Properties

function execute(input) {
    // Always use optional chaining / defaults for safety
    const employeeId  = input.employeeId  ?? null;
    const year        = input.year        ?? new Date().getFullYear();
    const options     = input.options     ?? {};
    const includeHist = options.includeHistory ?? false;

    if (!employeeId) {
        return { error: "employeeId is required" };
    }

    // Nested input objects
    const address = input.address ?? {};
    const city    = address.city  ?? "Unknown";
    const country = address.country ?? "Unknown";

    // Arrays
    const items   = input.items ?? [];
    const firstItem = items[0] ?? null;

    return { processed: true, employeeId, year };
}

Output Types

// Object output (most common)
return { result: 42, message: "Success", items: [] };

// Array output
return [{ id: 1, name: "Item A" }, { id: 2, name: "Item B" }];

// Primitive output (string, number, boolean)
return "formatted result";
return 42.5;
return true;

// Null output (indicates no result / not found)
return null;

Defining Input Schema for LLM Tool Registration

When an AI Function is used as an MCP tool, its InputSchema JSON column provides the JSON Schema the LLM uses to construct valid tool call inputs:

// InputSchema column content (stored in Octopus_AIFunctions)
{
  "type": "object",
  "properties": {
    "employeeId": {
      "type":        "string",
      "description": "The employee's unique identifier"
    },
    "year": {
      "type":        "integer",
      "description": "The calendar year (defaults to current year)"
    }
  },
  "required": ["employeeId"]
}

// The function description serves as the tool description for the LLM.
// Write it as: "Returns X. Call when Y. Does not Z."

Output to Workflow Node

When used in a Flow Studio AI Function Node, the return value is mapped to the node's output variables, which flow into subsequent nodes:

// Function returns:
return {
    approved:      true,
    remainingDays: 7,
    message:       "Leave approved. 7 days remaining."
};

// In Flow Studio, map these to workflow variables:
// output.approved      → workflow.leaveApproved (bool)
// output.remainingDays → workflow.daysLeft (number)
// output.message       → workflow.approvalMessage (string)