Define reusable object types with context-specific property requirements using custom type variants.
Available Plans
free
starter
growth
enterprise
7 minute read
This guide shows you how to define and use custom type variants in your Data Catalog.
Overview
Custom type variants let you define different property requirements for reusable object types based on a discriminating property value. This feature is particularly useful when an object type needs different validation rules depending on the context in which it is used.
Custom type variants work similarly to Event Rule Variants but are defined at the custom type level rather than the event level. This makes them reusable across multiple events and Tracking Plans.
Define custom type variants
Using your preferred text editor, add variants to your custom types in the Custom Types YAML file:
Basic structure
Custom type variants are defined within custom type definitions. See Variants YAML Reference for the detailed variant specification.
The following snippet is a simplified example to demonstrate the structure. See the Examples section below for real-world use cases with complete implementations.
version:rudder/v0.1kind:custom-typesmetadata:name:mycustomtypesspec:types:- id:custom_objectname:"Custom Object"type:objectdescription:"Object with context-specific requirements"# Common properties for all variantsproperties:- $ref:"#/properties/common_props/property_1"required:true# Discriminator property must be required- $ref:"#/properties/common_props/property_2"required:false# Common property that may be required by variants- $ref:"#/properties/common_props/property_3"required:false# Property used in default casevariants:- type:discriminatordiscriminator:"#/properties/common_props/property_1"# Must match the property defined abovecases:- id:case_adisplay_name:"Case A"match:- "value1"- "value2"description:"Description of Case A"properties:- $ref:"#/properties/common_props/property_2"required:true- id:case_bdisplay_name:"Case B"match:- "value3"description:"Description of Case B"properties:- $ref:"#/properties/common_props/property_2"required:true# Default case for unmatched valuesdefault:- $ref:"#/properties/common_props/property_3"required:true
Each variant definition requires:
The discriminator type (type: discriminator)
The discriminating property name (discriminator)
One or more cases with:
A unique identifier (id)
A display name (display_name)
Match values (match)
Description (description) explaining when this case applies
Property requirements (properties) specific to this case
Optional default case (default) for when no cases match
The discriminator property must be:
Defined in the custom type’s properties section
Marked as required
Have a type matching your match values (string, boolean, or number)
Supported discriminator types
You can use the following discriminator types in your custom type variants:
Type
Description
Example values
String
Match against text values
"US", "UK", "Japan"
Boolean
Match true/false conditions
true, false
Number
Match against numeric thresholds
500, 1000, 2000
Note that for each type:
You can specify multiple match values in an array
Values are matched exactly (no range or pattern matching)
String matches are case-sensitive
Examples
The following examples show variant definitions for different use cases:
Use Case: Different address requirements based on country/region
This example shows how to validate different properties based on the country code, with specific requirements for each region:
version:rudder/v0.1kind:custom-typesmetadata:name:address_typesspec:types:- id:address_objectname:"Address Object"type:objectdescription:"Address with region-specific requirements"properties:- $ref:"#/properties/address_props/country"required:true- $ref:"#/properties/address_props/street_address"required:true- $ref:"#/properties/address_props/city"required:true- $ref:"#/properties/address_props/postal_code"- $ref:"#/properties/address_props/state_province"- $ref:"#/properties/address_props/prefecture"- $ref:"#/properties/address_props/district"variants:- type:discriminatordiscriminator:"#/properties/address_props/country"cases:- id:us_addressdisplay_name:"US Address"match:- "US"- "USA"- "United States"description:"US address format with state and ZIP"properties:- $ref:"#/properties/address_props/state_province"required:true- $ref:"#/properties/address_props/postal_code"required:true- id:uk_addressdisplay_name:"UK Address"match:- "UK"- "GB"- "United Kingdom"description:"UK address format with postcode"properties:- $ref:"#/properties/address_props/postal_code"required:true- id:japan_addressdisplay_name:"Japan Address"match:- "JP"- "Japan"description:"Japanese address format with prefecture"properties:- $ref:"#/properties/address_props/prefecture"required:true- $ref:"#/properties/address_props/district"required:falsedefault:- $ref:"#/properties/address_props/postal_code"required:false
Key takeaways
Uses string-based country code discrimination
Handles multiple country codes per case (for example, US, USA, United States)
Shows region-specific address requirements
Includes optional fields like district for specific regions
Use Case: Different product attributes based on category
This example shows how to validate different properties based on the product category:
Once defined, you can use custom types with variants in your properties:
version:rudder/v0.1kind:propertiesmetadata:name:integration_propertiesspec:properties:- id:customer_profilename:"customer_profile"type:"#/custom-types/user_profile_types/user_profile_object"description:"Customer profile information"- id:purchased_productname:"purchased_product"type:"#/custom-types/product_types/product_object"description:"Product that was purchased"- id:shipping_addressname:"shipping_address"type:"#/custom-types/address_types/address_object"description:"Where to ship the order"
You can then reference these properties in your Tracking Plan:
version:rudder/0.1kind:tpmetadata:name:integrated_tracking_planspec:id:integrated_plandisplay_name:"Integrated Plan with Custom Types"description:"Tracking plan demonstrating custom type usage"rules:- type:event_ruleid:purchase_completed_ruleevent:$ref:"#/events/ecommerce_events/purchase_completed"allow_unplanned:falseproperties:- $ref:"#/properties/integration_properties/customer_profile"required:true- $ref:"#/properties/integration_properties/purchased_product"required:true- $ref:"#/properties/integration_properties/shipping_address"required:true
This site uses cookies to improve your experience while you navigate through the website. Out of
these
cookies, the cookies that are categorized as necessary are stored on your browser as they are as
essential
for the working of basic functionalities of the website. We also use third-party cookies that
help
us
analyze and understand how you use this website. These cookies will be stored in your browser
only
with
your
consent. You also have the option to opt-out of these cookies. But opting out of some of these
cookies
may
have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This
category only includes cookies that ensures basic functionalities and security
features of the website. These cookies do not store any personal information.
This site uses cookies to improve your experience. If you want to
learn more about cookies and why we use them, visit our cookie
policy. We'll assume you're ok with this, but you can opt-out if you wish Cookie Settings.