Skip to end of metadata
Go to start of metadata

Custom Model Parser Service

This service is currently available to a limited set of clients.

The Custom Model Parser service lets you check the validity of decision trees written in our Bonsai Language. You should use this service to identify and resolve any Bonsai syntax or feature errors before using the Custom Model Service to upload trees for use in campaigns.

This page walks you through the validation process. For background information on the purpose of custom models, see Custom Models. 

On This Page

Step 1. Base64-encode your Bonsai decision tree

Once you have written your decision tree in our Bonsai Language, base64-encode it.

Step 2. Create a JSON file containing your encoded tree

Create a JSON file as shown below. The main object must contain a custom-model-parser object with the encoded tree as a string in the model_text field.

Step 3. POST the file to the Custom Model Parser Service

Make a POST call to the Custom Model Parser Service as shown below.

Step 4. Check the response 

Tree is valid

If your Bonsai decision tree is valid, the custom-model-parser object in the response will contain the following fields:


Your decision tree, in our internal Lisp storage format.


The size of your decision tree, in bytes, in our internal Lisp storage format.

Size Limit: The Lisp version of your tree must be smaller than 3 MB, or 3,145,728 bytes. If it is larger than that, you will not be able to add your tree using the Custom Model Service.

Tree is not valid

If your Bonsai decision tree is not valid, the error field in the response will identify the issue. An error can result from either invalid Bonsai syntax or invalid usage of Bonsai features. See Error Messages below for more details.

Error Messages

Syntax Errors

  • Illegal character found:

  • Second root node found:

  • Numeric operator used with non-numeric type:

  • Incorrect number of elements in a list (like having 3 elements in a range expression):

Feature Errors

There are two types of features: Features we validate against the DB, and features whose values must be certain numeric values. Validating against the DB, the error message seen for an invalid value is:

Validating numeric values, the error message seen for an invalid value is:

Features, descriptions, numeric restrictions are as follows:

  • country: Country string
  • region: Region string
  • city: City string
  • supply_type: Supply type
  • domain: URL string
  • browser: Browser string
  • carrier: Carrier string
  • os_family: OS family string
  • placement: Valid placement id
  • size: Size string
  • placement_group: Valid placement group id
  • publisher: Valid publisher id
  • mobile_app: Valid mobile app id
  • cookie_age: Cookie age in minutes
  • user_hour: User hour must be between 0 and 23
  • user_day: User day must be between 0 and 6
  • advertiser_life_freq: Advertiser life frequency must be a positive integer
  • advertiser_day_freq: Advertiser day frequency must be a positive integer
  • advertiser_recency: Advertiser recency must be positive integer or -1
  • device_type: Device type string

  • estimated_iab_viewthrough_rate: IAB viewthrough rate must be a number between 0 and 1

Related Topics

  • No labels