Swallow
  • YOUR FIRST MODEL
    • Setting up your first project
    • Manual setup of a new product
    • Excel Model Upload
    • Create your team
    • Essential concepts
      • Syntax
      • Steps
      • Collections
      • Try Model
      • Spotlight
  • PROCESS
    • Team Management
    • Governance & Collaboration
  • BUILD
    • Building with AI
    • Step builder
      • Understanding step types
      • Ordering step blocks
      • Placeholder mode
      • Up/Downloading models
      • Sharing your model
      • Running tests
    • Inputs
    • Enriching Raw Data
      • Transform Data
      • Enrich via API
      • Data Set
      • Collection
      • Custom Code
    • Setting Up Decisions
      • Exclusions
      • Excesses
      • Endorsements
      • Refer
    • Making Calculations
      • Factors
      • Calculation
    • Outputs
  • TEST
    • Creating New Tests
    • Running Tests
    • Editing Tests
    • Reading & Interpreting Tests
    • Impact Testing
  • DATA
    • Working with real-time data
    • Data Views
    • Data Quotas
    • Troubleshooting
    • API Webhooks
    • Data Downloads
  • ADMIN & SETTINGS
    • Project Management
    • Account Management
  • INTEGRATIONS
    • Introduction
    • Payments
      • Stripe
      • GoCardless
      • Adyen
    • Alerting
      • Slack
      • Zapier
    • Data
      • AWS S3
      • Google Sheets
    • Admin
      • Socotra
      • Guidewire
      • Hubspot
      • Salesforce
  • Developer API
    • Introduction
    • Authentication
    • Errors codes
    • Endpoints
      • /quotes
      • /projects
      • /tests
      • /process
Powered by GitBook
On this page
  • 1. Input your custom code
  • 2. Format custom code output
  1. BUILD
  2. Enriching Raw Data

Custom Code

Using your own javascript custom code to enrich or reformat data inputs.

PreviousCollectionNextSetting Up Decisions

Last updated 1 year ago

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.

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.

1. Input your custom code

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.

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.

Try the code by clicking on the try button:

2. Format custom code output

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.

You format the output the same way as you would in the step. You will have access to the output object from the customCode.

transform
The Custom Code step
Inputting custom code