Select spec version:

Conditional Validation in CLI-based Tracking Plan Management

Private Beta
Define flexible, context-aware validation rules for your Tracking Plan events and custom data types.

The Conditional Validation feature is in Private Beta as part of RudderStack’s Early Access Program, where we work with early users and customers to test new features and get feedback before making them generally available.

Reach out to Customer Success if you are interested in enabling this feature for your workspace.

RudderStack’s Conditional Validation feature lets you define dynamic validation rules that adapt based on specific conditions or contexts. This powerful capability addresses a common challenge in data collection — maintaining strict data quality standards while accommodating legitimate variations in your event data structure.

Overview

In real-world applications, the structure and requirements of your event data often need to change based on context. For example:

  • An ecommerce application that needs different product attributes for clothing versus electronics
  • A global application that needs to handle address formats that vary by country
  • A multi-tier service that needs to track different user properties based on subscription level

With the conditional validation feature, you can define different sets of property requirements based on a discriminating value. For example:

  • Different address formats based on the country
  • Varying product attributes based on the category
  • Dynamic event properties based on the page type

Without conditional validation, you would need to either:

  • Enforce all possible properties as optional, risking missing critical data
  • Create separate events for each variation, leading to event proliferation
  • Implement complex custom validation logic, increasing maintenance burden and complexity

Conditional validation solves these problems by letting you define context-aware validation rules directly in your Tracking Plan.

See the demo video below for more information:

Key features

  • Discriminator-based validation: Define different property requirements based on specific field values — RudderStack supports string, boolean, and integer discriminator types currently
  • Flexible matching: Support for exact match, multiple values, and array-based matching
  • Default cases: Define fallback requirements when no specific case matches
  • Reusable custom type variants: Create reusable custom types with variants that you can reference across your Tracking Plans

When to use conditional validation

Use conditional validation when you need to:

  • Handle regional variations: Different requirements based on country, region, or locale
  • Support multiple categories: Varying attributes for different product types or user categories
  • Context-specific validation: Different requirements based on user context or application state
  • Flexible event tracking: Adapt event properties based on where or how the event occurs

Variants

Conditional validation in RudderStack involves using two kinds of variants:

1. Event rule variants

Event rule variants let you define different property requirements for the same event based on a discriminating property. For example, a Page Viewed event might require different properties when viewed on a product page versus a search results page.

See Event Rule Variants for more information.

2. Custom type variants

Custom type variants enable you to create reusable object definitions with varying property requirements. For example, an address object might have different required fields depending on the country.

See Custom Type Variants for more information.

Dashboard visibility

After conditional validation is enabled for your workspace, the RudderStack dashboard is read-only for variants. You can view event and custom type variants in the dashboard, but you cannot create, edit, or delete variants there. Manage variants only through YAML and Rudder CLI.

Limitations and behavior

Keep the following in mind before you roll out conditional validation to a production workspace:

  • One variant per event rule or custom type. Each event rule and each custom type can define a single variant, so one event has one discriminator. Rudder CLI rejects a second entry in variants.
  • Object custom types only. Custom type variants work only on custom types of type object. Event rule variants work on any event rule.
  • The discriminator must be a required property. The discriminator must be listed in the properties of the event rule or custom type that defines the variant, and it must have required: true.
  • A missing discriminator skips the variant. Each case and the default case apply only when the event contains the discriminator. If the event does not contain it, RudderStack applies no case and no default, and the variant adds no checks. If the rule disallows additional properties, the case-specific properties that the event carries are then reported as additional properties, which can be confusing to debug. Mark the discriminator as required to avoid this.
  • Conflicting property rules are not flagged. RudderStack does not check whether the rules for a property inside a case contradict the rules for the same property outside the variant. Such a configuration is accepted, and an event violates the Tracking Plan when either rule fails. Review properties that appear both in the base properties and in a case.
  • Metrics are per event, not per case. RudderStack does not collect event or violation metrics at the discriminator case level.
  • The dashboard is read-only. See Dashboard visibility.

Turn off conditional validation

Turning off the feature for your workspace does not remove variants that you have already deployed. To revert, remove the variants from your YAML files and apply the change while the feature is still enabled. Then ask Customer Success to turn the feature off.

Get started

  1. Contact the RudderStack team to enable conditional validation for your workspace.
  2. Choose between event rule variants or custom type variants based on your needs.
  3. Review the Conditional Validation YAML Reference guide for syntax and structure.
  4. Define your variants using the appropriate YAML configuration.
  5. Validate your configuration using the Rudder CLI.
  6. Deploy your changes using standard Git workflows.

See also

Questions? Let's figure it out together.

Join the RudderStack Slack community to connect with other users, customers, and the RudderStack team — or reach out for direct support.