Add custom logic with Javascript or Python

How does the Code Step work?

The Code Step in AirOps Studio currently supports Javascript and Python, which provides you with the flexibility needed to perform advanced requests.

The code in a Code Step is wrapped inside a function, and you must use a return statement to output results from the step.


How to Reference an Input

Unlike Liquid, Javascript variables exclude {{ or }} . For example:

  • {{linkedin_url}} would be linkedin_url

How to Reference an Output

Javascript syntax is similar to Liquid, but excludes brackets:

  • {{step_1.output}} would be step_1.output

  • {{}} would be

Use a Return Statement

You must include a return statement in a Code Step to determine the output of the step

Javascript Example

Let's walk through an example that references both a text input as well as an LLM output. We'll use a basic application that requests a string input, and returns a match of words that rhyme with it.

Our Code Step will simply be responsible for combining the input prompt with the LLM output, so we have just a single result that includes the question and answer:


How to Reference an Input

Similar to Javascript, Python only requires direct reference to the variable name. So the same example from above holds true:

  • {{linkedin_url}} would be linkedin_url

How to Reference an Output

Python syntax must include brackets around the variable name:

  • {{step_1.output}} would be step_1["output"]

  • {{step_1.output.key}} would be step_1["output"]["key"]

Use a Return Statement

You must include a return statement in a Code Step to determine the output of the step.

Supported Python Packages

As of 2/13/2024:


Adding Additional Python Packages

While we're always looking to add to our natively supported packages, our Code Step does offer a workaround for working with additional packages.

When writing your Code Step, append the following code to your block:

import os
import sys
import subprocess

# pip install custom package to /tmp/ and add to path'pip install flask -t /tmp/ --no-cache-dir'.split(), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
sys.path.insert(1, '/tmp/')
import flask

return 'import ok'

Note: Any external libraries called with this method will get installed every time the Code Step runs, potentially adding noticeable seconds of execution time.

Python Example

Let's walk through the same example from above, but in Python:

AI Helpers

Both Python and Javascript support using our AI Helper to generate code. This can be useful if you're struggling to find the exact syntax in either language to achieve your goal.

Similar to the prompt for an LLM, we recommend being as clear and thorough in your description as possible.

Once our AI Helpers have generated the code, you can keep or reject the generated text. If you decide you want to add or remove the code later on, you can use the same "Generate with AI" button to modify your prompt and code.


There are two main limits to be aware of regarding our Code Step:

  1. They have a maximum runtime of 15 minutes

  2. The maximum payload size is 6MB

Last updated