Skip to content

Validation Checks

Checks validate field values in taxonomy and payload definitions.

Add checks to field definitions:

opentp.yaml
spec:
events:
taxonomy:
area:
type: string
checks:
max-length: 50
pattern: "^[a-z_]+$"
not-empty: true

Checks can also be applied in event payload schemas:

events/auth/login.yaml
payload:
schema:
user_id:
type: string
checks:
min-length: 1
max-length: 100

Maximum string length.

checks:
max-length: 50
ValueParamsResult
hello50Valid
hello... (60 chars)50Invalid

Minimum string length.

checks:
min-length: 3
ValueParamsResult
hello3Valid
hi3Invalid

Match a regular expression.

checks:
pattern: "^[a-z_]+$"
ValuePatternResult
hello_world^[a-z_]+$Valid
Hello World^[a-z_]+$Invalid

Value must not be empty.

checks:
not-empty: true
ValueResult
helloValid
Invalid
Invalid (whitespace only)

Value must start with a prefix.

checks:
starts-with: "app_"
ValueParamsResult
app_loginapp_Valid
loginapp_Invalid

Value must end with a suffix.

checks:
ends-with: "_event"
ValueParamsResult
login_event_eventValid
login_eventInvalid

Value must contain a substring.

checks:
contains: "_"
ValueParamsResult
hello_world_Valid
helloworld_Invalid

Validate against an external API.

checks:
webhook:
url: https://api.company.com/validate
headers:
Authorization: "Bearer ${API_KEY}"
timeout: 5000
retries: 2
ParamTypeRequiredDescription
urlstringYesValidation endpoint URL
headersobjectNoHTTP headers
timeoutnumberNoTimeout in ms (default: 5000)
retriesnumberNoRetry attempts (default: 0)

Use ${VAR_NAME} to reference environment variables:

webhook:
url: ${VALIDATOR_URL}/check
headers:
Authorization: "Bearer ${API_KEY}"

The webhook should return JSON:

// Valid
{ "valid": true }
// Invalid
{ "valid": false, "error": "Company ID not found" }

Multiple checks are evaluated in order:

checks:
not-empty: true
min-length: 3
max-length: 50
pattern: "^[a-z_]+$"

All checks must pass for the value to be valid.

Create custom validation checks in JavaScript:

my-rules/company-id/index.js
module.exports = {
name: 'company-id',
validate: (value, params, context) => {
if (!value.startsWith('COMP-')) {
return {
valid: false,
error: 'Must start with COMP-'
};
}
if (value.length !== 12) {
return {
valid: false,
error: 'Must be exactly 12 characters'
};
}
return { valid: true };
}
};

Use in your tracking plan:

taxonomy:
company:
type: string
checks:
company-id: true

Load with CLI:

Terminal window
opentp validate --external-rules ./my-rules

Custom checks receive a context object:

validate: (value, params, context) => {
// context.fieldName - field name
// context.fieldPath - full path (e.g., "taxonomy.area")
// context.eventKey - current event key (e.g., "auth::login_click")
// context.specField - field definition from opentp.yaml (optional)
}