Skip to main content
The transform operation provides declarative data transformations without writing JavaScript. Return literal values, parse/format CSV/Excel/JSON data, modify objects with pick/omit/defaults, filter and sort arrays, or merge multiple data sources.
The transform operation is edge-compatible - no eval or Function constructors. All expressions (${...}) are resolved by the runtime before the agent executes.

Quick Start

Return literal values:
Parse CSV to objects:
Format to CSV:
Filter and sort:

Configuration

Modes

Value Mode

Return a literal value. Expression interpolation (${...}) is resolved before the agent runs.
Value mode supports all types:

Input Mode

Pass through data with optional modifiers applied.

Pick - Include Only Specified Fields

Input: { id: 1, name: "Alice", email: "alice@example.com", password: "secret", adminNotes: "..." } Output: { id: 1, name: "Alice", email: "alice@example.com" }

Omit - Exclude Specified Fields

Input: { id: 1, name: "Alice", password: "secret", ssn: "123-45-6789" } Output: { id: 1, name: "Alice" }

Rename - Rename Fields

Input: { user_id: 1, display_name: "Alice", created_at: "2024-01-15" } Output: { id: 1, name: "Alice", createdAt: "2024-01-15" }

Defaults - Add Missing Fields

Input: { id: 1, name: "Alice" } Output: { id: 1, name: "Alice", status: "pending", role: "user", verified: false } Existing values are not overwritten: Input: { id: 1, name: "Alice", status: "active" } Output: { id: 1, name: "Alice", status: "active", role: "user", verified: false }

Combining Modifiers

Modifiers are applied in order: defaults → rename → pick → omit

Array Input

Modifiers apply to each item in arrays:
Input: [{ id: 1, name: "Alice", password: "x" }, { id: 2, name: "Bob", password: "y" }] Output: [{ id: 1, name: "Alice", status: "pending" }, { id: 2, name: "Bob", status: "pending" }]

Merge Mode

Combine multiple items into one.

Object Merge

Later objects override earlier ones (shallow merge):
Output: { id: 1, name: "Alice", theme: "dark", updatedAt: "2025-01-15T..." }

Array Concatenation

Arrays are flattened:
Output: [1, 2, 3, 4, 5, 6]

Parse & Format

Transform can parse and format data between different formats without custom code.

CSV Parsing

Parse CSV strings to arrays of objects:
Input:
Output:
CSV parsing uses papaparse with dynamicTyping: true, so numbers are automatically converted to numeric types.

CSV Formatting

Format arrays of objects to CSV strings:
Input:
Output (with columns: [id, name, email]):

TSV (Tab-Separated Values)

Same as CSV but with tab delimiters:

JSONL (Newline-Delimited JSON)

Parse/format newline-delimited JSON:
Input:
Output:

XLSX (Excel)

XLSX parsing/formatting uses the xlsx library (~500KB). It’s dynamically imported only when needed to keep the bundle lean. For simpler use cases, consider CSV instead.
Parse Excel files:
Format to Excel (returns base64 string):

Array Operations

Transform provides declarative array operations without writing loops.

Filter

Keep only items where a field is truthy:
Input:
Output:

Sort

Sort by a field:
Sorting handles numbers, strings, and dates correctly. Null/undefined values sort to the end.

Pagination

Use limit and offset for pagination:

Data Cleaning

Transform provides utilities for cleaning messy data.

Trim

Trim whitespace from all string fields:
Input: { name: " Alice ", email: " alice@example.com " } Output: { name: "Alice", email: "alice@example.com" }

Compact

Remove null and undefined values:
Input: { id: 1, name: "Alice", email: null, phone: undefined } Output: { id: 1, name: "Alice" }

Dedupe

Remove duplicates:

Coerce

Convert field types:
Supported types:
  • string - Convert to string
  • number - Parse as number (returns 0 for invalid)
  • boolean - Parse as boolean (“true”, “1”, “yes” → true)
  • date - Parse as Date object (returns null for invalid)

Complete ETL Example

Here’s a complete example showing parse → transform → format:

Mode Priority

When multiple modes are specified, they’re evaluated in this order:
  1. value - If defined (including null), use value mode
  2. merge - If defined, use merge mode
  3. input - If defined, use input mode
If none are specified, an error is thrown.

Why Transform vs Code?

Use transform when you need:
  • Return static/mock data
  • Parse/format CSV, TSV, XLSX, JSONL
  • Pick/omit/rename fields from objects
  • Merge multiple data sources
  • Filter/sort/paginate arrays
  • Clean data (trim, compact, dedupe)
  • Type coercion
Use code when you need:
  • Complex conditional logic
  • Custom calculations
  • Multiple dependent transformations
  • External library calls
Transform is:
  • Faster - No JavaScript parsing
  • Safer - No arbitrary code execution
  • Clearer - Declarative intent
  • Cacheable - Deterministic outputs

Error Handling

Missing Mode

If no mode is specified, an error is thrown:
Error: transform operation requires one of: config.value, config.input, or config.merge

Empty Merge Array

Error: transform merge mode requires a non-empty array

Invalid Parse Format

Error: transform: unsupported parse format 'pdf'

JSONL Parse Error

Error: transform: JSONL parse error at line 2: Invalid JSON

Performance

Transform is one of the fastest operations:
XLSX operations are slower due to the library size. For high-performance use cases, prefer CSV.
  • convert - Document format conversion (HTML↔Markdown, DOCX)
  • code - For complex JavaScript logic
  • http - Fetch data to transform
  • storage - Read/write files
  • data - Database operations