# Custom Code

By adding a 'Custom Code' step into the step builder, you can input your own custom code to enrich or reformat inputs in any way to choose to.

<figure><img src="https://1110149073-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu89vYHjuY9Vj4vhZX5IZ%2Fuploads%2FerJhdAZS23he99yrCiiH%2FScreenshot%202024-04-29%20at%2017.27.13.png?alt=media&#x26;token=b0aa3d1b-fbfc-4693-aa6f-fa6a531ac491" alt="" width="375"><figcaption><p>The Custom Code step</p></figcaption></figure>

{% hint style="info" %}
**How might you use the 'Custom Code' step?**

To transform data, or for complex rules or calculations. It provides flexibility to achieve results that the existing steps aren't capable of.&#x20;
{% endhint %}

## 1. Input your custom code

<figure><img src="https://1110149073-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu89vYHjuY9Vj4vhZX5IZ%2Fuploads%2F5n550W2RlJkT2cjLChzO%2FScreenshot%202024-04-29%20at%2017.21.43.png?alt=media&#x26;token=ad4012d7-4d28-43ed-bc6e-d4bb013d80ec" alt=""><figcaption><p>Inputting custom code</p></figcaption></figure>

The step will always have access to the output of all previous steps that can be invoked by using the `{{input}}` syntax.  You can use any native javascript to return an object that can be mapped to outputs.&#x20;

Lodash (\_) and MathJS libraries are also included within the code context to use as you like.

```
const age_limit= _.min([{{age}}, {{years_experience}}]);
return {
    age_limit,
}
```

An Object must always be returned so that the format step has something to map against. The step will throw an error if an object isn't returned.&#x20;

Try the code by clicking on the try button:

<figure><img src="https://1110149073-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu89vYHjuY9Vj4vhZX5IZ%2Fuploads%2Fp29qMl0HVWwDVEpv5aF8%2FScreenshot%202024-05-14%20at%2020.12.41.png?alt=media&#x26;token=a2b9f079-20d0-4ed6-8279-afda37893b28" alt=""><figcaption></figcaption></figure>

## 2. Format custom code output

You format the output the same way as you would in the [transform](https://swallow-1.gitbook.io/swallow/build/enriching-raw-data/transform-data) step. You will have access to the output object from the customCode.

The step will auto-generate the output formats that it thinks you want. You can amend this outputs using the edit button after hovering over the new output.
