Skip to main content

Eval Step

The Eval step executes custom JavaScript code within your flow. Use it for complex logic, custom calculations, advanced data manipulation, or anything that can’t be accomplished with other step types. Full JavaScript ES6+ support with access to common libraries.
Use Sparingly: Eval is powerful but adds complexity. Use built-in steps (Map, Rules, Functions) when possible. Reserve Eval for truly custom logic that can’t be accomplished otherwise.

How It Works

Eval executes JavaScript code and returns the result:

When to Use Eval

Examples: Use Eval: Calculate compound interest with variable rates, fees, and payment schedules
Use Rules instead: Simple percentage calculation
Use Eval: Implement custom recommendation algorithm
Use Agent instead: Interpret user needs and recommend
Use Eval: Parse and validate complex data formats
Use Map instead: Extract fields from JSON

Configuration

Code

code
string
required
JavaScript code to executeMust return a value using return statementAvailable variables:
  • input - Input data from previous step or trigger
  • context - Full flow context including all previous steps
  • trigger - Original trigger data
  • secrets - Access to secrets (read-only)
Example:

Input Data

input
any
Data passed to the Eval stepCan reference previous steps:
Accessible in code as input object

Timeout

timeout
number
default:"5000"
Maximum execution time in millisecondsRecommendations:
  • Simple logic: 1000ms (1 second)
  • Moderate complexity: 5000ms (5 seconds, default)
  • Heavy processing: 30000ms (30 seconds)
Long timeouts can slow flows. Optimize code for performance.

Available Libraries

Eval has access to common JavaScript libraries:
Utility library for arrays, objects, and moreImport:
Common uses:
Date and time manipulationImport:
Common uses:
Advanced mathematical operationsImport:
Common uses:
Cryptographic functionsImport:
Common uses:
All standard ES6+ features availableIncludes:
  • Array methods (map, filter, reduce, find, etc.)
  • Object methods (keys, values, entries, assign, etc.)
  • String methods (split, replace, match, etc.)
  • Math object (round, floor, ceil, random, etc.)
  • JSON parse/stringify
  • RegExp for pattern matching
  • Promises and async/await
  • Template literals
  • Destructuring
  • Spread operator

Common Patterns

Calculations beyond simple operators
Complex array manipulation beyond Map
Custom validation logic
Complex string manipulation
Complex date logic
Complex business logic with many conditions
Complex data reshaping beyond Map
Proprietary scoring logic

Real-World Examples

Example 1: Mortgage Qualification Calculator


Example 2: Recommendation Engine


Example 3: Fraud Detection Scoring


Best Practices

Use Judiciously

Only use Eval when built-in steps (Map, Rules, Functions, Condition) can’t accomplish the task. Eval adds complexity.

Always Return a Value

Code must include a return statement. The returned value becomes the step output.

Handle Errors

Use try-catch blocks for operations that might fail. Return error information for debugging.

Keep It Fast

Optimize for performance. Long-running code slows flows. Set appropriate timeouts.

Test Thoroughly

Test with real data and edge cases. Use Test Mode to verify before production.

Document Complex Logic

Add comments explaining what the code does and why. Future you will thank present you.

Avoid External API Calls

Use HTTP Request step for API calls, not fetch/axios in Eval. Eval is for computation, not I/O.

Validate Inputs

Check that input has expected structure before processing. Return meaningful errors if not.

Troubleshooting

Causes:
  • Syntax error in JavaScript
  • Runtime error (undefined variable, null reference)
  • Exceeded timeout
  • Missing return statement
Solutions:
  • Check execution logs for error message
  • Test code separately in JavaScript console
  • Add try-catch blocks
  • Verify all variables exist before using
  • Add return statement
Causes:
  • Wrong variable name
  • Input not passed correctly
  • Variable undefined
Solutions:
  • Use input to access passed data
  • Use context for full flow context
  • Check input configuration
  • Add null checks: const value = input?.field || 'default'
Causes:
  • Library not included in Eval environment
  • Wrong import syntax
Solutions:
  • Check available libraries list
  • Use correct require syntax: const _ = require('lodash')
  • For unavailable libraries, implement logic directly or use different step
Causes:
  • Code takes too long to execute
  • Infinite loop
  • Processing large datasets
Solutions:
  • Optimize algorithm
  • Increase timeout setting
  • Process data in smaller chunks
  • Use Map step for large array processing instead
Causes:
  • Logic error in code
  • Wrong data types
  • Missing edge case handling
Solutions:
  • Add console.log statements (appear in logs)
  • Test with various inputs
  • Verify data types match expectations
  • Handle null/undefined cases

Security Considerations

Eval cannot make external HTTP requests. Use HTTP Request step for API calls.Blocked:
  • fetch()
  • XMLHttpRequest
  • axios
  • node-fetch
Can read secrets but not write them
Always validate input data, especially user-provided data
Code runs in isolated environment
  • Cannot access file system
  • Cannot execute system commands
  • Cannot import arbitrary modules
  • Timeout enforced automatically

Next Steps

Map Step

Simpler data transformations

Rules Step

Declarative business logic

Functions Step

Pre-built utility functions

Condition Step

Route based on Eval output