> ## Documentation Index
> Fetch the complete documentation index at: https://docs.siftstack.com/llms.txt
> Use this file to discover all available pages before exploring further.

# User-Defined Function reference

> Settings, options, and behaviors for User-Defined Functions in Sift.

export const MintTable = ({columns = [], rows = [], columnWidths = []}) => {
  const pushTextWithLineBreaks = (parts, text, keyBase) => {
    const segments = String(text).split(/\\n|\n/);
    segments.forEach((segment, idx) => {
      if (segment) {
        parts.push(<span key={`${keyBase}-text-${idx}`}>{segment}</span>);
      }
      if (idx < segments.length - 1) {
        parts.push(<br key={`${keyBase}-br-${idx}`} />);
      }
    });
  };
  const parseMarkdown = text => {
    if (text === null || text === undefined) return "";
    const str = String(text);
    const parts = [];
    let lastIndex = 0;
    const pattern = /(`[^`]+`|\*\*[^*]+\*\*|\*[^*]+\*|\[([^\]]+)\]\(([^)]+)\))/g;
    let match;
    while (true) {
      match = pattern.exec(str);
      if (match === null) {
        break;
      }
      if (match.index > lastIndex) {
        pushTextWithLineBreaks(parts, str.substring(lastIndex, match.index), `before-${lastIndex}`);
      }
      const fullMatch = match[0];
      if (fullMatch.startsWith("`") && fullMatch.endsWith("`")) {
        parts.push(<code key={match.index}>{fullMatch.slice(1, -1)}</code>);
      } else if (fullMatch.startsWith("**") && fullMatch.endsWith("**")) {
        parts.push(<strong key={match.index}>{fullMatch.slice(2, -2)}</strong>);
      } else if (fullMatch.startsWith("*") && fullMatch.endsWith("*")) {
        parts.push(<em key={match.index}>{fullMatch.slice(1, -1)}</em>);
      } else if (fullMatch.startsWith("[")) {
        const linkText = match[2];
        const linkUrl = match[3];
        parts.push(<a key={match.index} href={linkUrl} className="text-black-600 dark:text-black-400">
            {linkText}
          </a>);
      }
      lastIndex = pattern.lastIndex;
    }
    if (lastIndex < str.length) {
      pushTextWithLineBreaks(parts, str.substring(lastIndex), `tail-${lastIndex}`);
    }
    if (parts.length > 0) {
      return parts;
    }
    const plainParts = [];
    pushTextWithLineBreaks(plainParts, str, "plain");
    return plainParts.length ? plainParts : str;
  };
  const safeColumns = Array.isArray(columns) ? columns : [];
  const safeRows = Array.isArray(rows) ? rows : [];
  const safeColumnWidths = Array.isArray(columnWidths) ? columnWidths : [];
  const hasColumnWidths = safeColumnWidths.some(w => w !== null && w !== undefined && w !== "");
  const toCssWidth = width => typeof width === "number" ? `${width}px` : String(width);
  const getColumnStyle = idx => {
    const rawWidth = safeColumnWidths[idx];
    if (rawWidth === null || rawWidth === undefined || rawWidth === "") {
      return undefined;
    }
    const width = toCssWidth(rawWidth);
    return {
      width,
      minWidth: width
    };
  };
  const containerStyle = hasColumnWidths ? undefined : {
    overflowX: "auto"
  };
  const tableStyle = hasColumnWidths ? {
    tableLayout: "fixed",
    width: "100%"
  } : {
    width: "max-content",
    minWidth: "100%"
  };
  if (!Array.isArray(columns) || !Array.isArray(rows) || !Array.isArray(columnWidths)) {
    console.warn("MintTable received invalid props:", {
      columns,
      rows,
      columnWidths
    });
  }
  if (!safeColumns.length && !safeRows.length) {
    return null;
  }
  return <div className="mint-table-container" style={containerStyle}>
      <table style={tableStyle}>
        {hasColumnWidths && <colgroup>
            {safeColumns.map((_, idx) => {
    const style = getColumnStyle(idx);
    return <col key={idx} style={style} />;
  })}
          </colgroup>}
        <thead>
          <tr>
            {safeColumns.map((col, idx) => <th key={idx} className="text-left" style={getColumnStyle(idx)}>
                <b>{parseMarkdown(col)}</b>
              </th>)}
          </tr>
        </thead>
        <tbody>
          {safeRows.map((row, rIdx) => {
    const safeRow = Array.isArray(row) ? row : [];
    return <tr key={rIdx}>
                {safeRow.map((cell, cIdx) => <td key={cIdx} style={getColumnStyle(cIdx)}>
                    {parseMarkdown(cell)}
                  </td>)}
              </tr>;
  })}
        </tbody>
      </table>
    </div>;
};

User-Defined Functions are reusable CEL expressions that can be called by name inside the expressions of Calculated Channels, Rules, and other User-Defined Functions.

They allow teams to define shared logic in one place and reference it across multiple expressions, ensuring consistency and reducing duplication.
When a User-Defined Function is updated, the change applies everywhere it is referenced without requiring updates to individual expressions.

## Settings

The following table describes each setting available when creating or editing a User-Defined Function.

<MintTable
  columns={['Setting', 'Description', 'Required']}
  columnWidths={['25%', '60%', '15%']}
  rows={[
['User-Defined Function name', 'The name of the User-Defined Function. Must start with a letter, contain only letters, numbers, and underscores, and be between 1 and 253 characters long. No spaces allowed.', 'Yes'],
['Description', 'A brief description of what the function does.', 'No'],
['Input Channels', 'One or more inputs used in the expression. Each input is assigned a shorthand variable (`$1`, `$2`, and so on) based on definition order. Each input must have a [data type](/documentation/reference/user-defined-functions-settings#input-data-types) assigned.', 'Yes'],
['Expression', 'The CEL expression that defines the function logic using the defined input variables. For supported syntax, see [Expression syntax](/documentation/reference/expression-syntax).', 'Yes'],
]}
/>

## Input data types

Each input in a User-Defined Function must be assigned one of the following data types.

<MintTable
  columns={['Data type', 'Description']}
  columnWidths={['25%', '75%']}
  rows={[
['Number', 'A numeric value received from a Channel at the time the function is called.'],
['String', 'A string value received from a Channel at the time the function is called.'],
['Boolean', 'A boolean value received from a Channel at the time the function is called.'],
['Constant Number', 'A fixed numeric value defined in the function that does not change between evaluations.'],
['Constant String', 'A fixed string value defined in the function that does not change between evaluations.'],
['Constant Boolean', 'A fixed boolean value defined in the function that does not change between evaluations.'],
]}
/>

## Lifecycle actions

The following table describes the actions available for managing a User-Defined Function after it has been created.

<MintTable
  columns={['Action', 'Description']}
  columnWidths={['20%', '80%']}
  rows={[
['Preview', 'Evaluate the function using a selected Run and mapped Channels to observe its behavior with real data before using it in expressions.'],
['Edit', 'Update the function expression, input Channels, or description. Each saved change creates a new version. The function name and input Channels can only be edited if the function has not yet been referenced by a Calculated Channel, Rule, or other User-Defined Function.'],
['Archive', 'Remove the function from use in new expressions without deleting it. Archived functions remain accessible but cannot be referenced in new Calculated Channels, Rules, or User-Defined Functions.'],
['Unarchive', 'Restore a previously archived function, making it available again for use in new expressions. Anyone in the organization can perform this action.'],
]}
/>

## Behavior

The following table describes known constraints and behaviors to be aware of when working with User-Defined Functions.

<MintTable
  columns={['Limitation', 'Description']}
  columnWidths={['25%', '75%']}
  rows={[
['Version control', 'Each time a User-Defined Function is edited and saved, Sift creates a new version while preserving the existing behavior of anything already referencing the function.'],
['Nesting', 'User-Defined Functions can be referenced inside other User-Defined Functions with no nesting limit.'],
['Updating logic centrally', 'When a User-Defined Function is updated, the change applies everywhere it is referenced without requiring updates to individual expressions.'],
['Scope', 'User-Defined Functions are available across the entire organization. All members can view and reference them in expressions.'],
]}
/>
