Validation Rules In Alexa Dialog Model

Introduction

 
In this article, I am going to explain about all of the validation rules available and the slot types with which they can be used.
 

Different validation rules

 
Following are the different validation rules,
  • Compare to the values and synonyms defined for a custom slot type.
  • Compare to a fixed set of values.
  • Compare to a specific value (greater than or less than).
  • Compare dates or times to a specified time span.

Compare to the values and synonyms defined for a custom slot type

 
This rule lets you accept only values that are explicitly defined for a custom slot type. The rule checks both value and synonyms. You can use this validation only with slots that use a custom slot type.
 
 Validation  Description  Type
Accept only Slot type's values and synonyms Accept values that are defined in the list of custom slot type values and synonyms. If the user provides a value that does not match any of these defined values, the value fails the validation and Alexa can use your prompts to ask the user for a new value.  hasEntityResolutionMatch
 

Compare to a fixed set of values

 
These rules let you either accept or reject a set of values. You can use these rules with the following slot types,
  • AMAZON.FOUR_DIGIT_NUMBER
  • AMAZON.NUMBER
  • AMAZON.Ordinal
  • AMAZON.PhoneNumber
  • All built-in List Types
  • Any custom slot type
 Validation  Description  Type  Parameters
Accept only a set of values Accept values that match a fixed set of values you specify. If the user provides a value that does not match any items on this list, the value fails the validation.  isInSet A list of values that should be accepted.
Reject only a set of values  Reject values that match a fixed set of values you specify. If the user provides a value that matches any items on this list, the value fails the validation.  isNotInSet  A list of values that should be rejected. 
 
The list of values in the set to accept or reject must be compatible with the slot type,
 
AMAZON.FOUR_DIGIT_NUMBER
 
Provide a list of four-digit numbers.
 
AMAZON.NUMBER
 
Provide a list of numbers.
 
AMAZON.Ordinal
 
Provide a list of numbers that correspond to the ordinal values to accept. For example, to accept or reject the words "first," "second," and "third," you would provide the numbers 1, 2, and 3.
 
AMAZON.PhoneNumber
 
Provide a list of phone numbers. Include just the digits of the numbers, no dashes or other formatting. For example: "2065551234".
 
All built-in List Type and custom slot type provides a list of string slot values.
 

Compare to a specific value (greater than or less than)

 
These rules let you accept user-provided slot values that are greater or lesser than a value you specify. You can use these rules with the following slot types,
  • AMAZON.DATE
  • AMAZON.FOUR_DIGIT_NUMBER
  • AMAZON.NUMBER
  • AMAZON.TIME slots.
 Validation  Description  Type  Parameters
Accept greater than a value  Accept values that are greater than a specified value. If the user's value is less than or equal to the criteria, the value fails the validation.  isGreaterThan The value to compare to the slot value.
Accept greater than or equal to a value  Accept values that are greater than or equal to a specified value. If the user's value is less than the criteria, the value fails the validation.   isGreaterThanOrEqualTo The value to compare to the slot value. 
 Accept less than a value Accept values that are less than a specified value. If the user's value is greater than or equal to the specified value, the value fails the validation.  isLessThan  The value to compare to the slot value. 
Accept less than or equal to a value  Accept values that are less than or equal to a specified value. If the user's value is greater than the specified value, the value fails the validation.  isLessThanOrEqualTo  The value to compare to the slot value. 
 
The value to compare with the user's slot value must be compatible with the slot type.
 
AMAZON.DATE
 
Specify a date in ISO-8601 calendar date format. The value must be an absolute date with the year, month, and day provided: 2020-09-28.
 
AMAZON.FOUR_DIGIT_NUMBER
 
Specify a four-digit number.
 
AMAZON.NUMBER
 
Specify a number.
 
AMAZON.TIME
 
Specify a time in ISO-8601 time format. The time must include hours and minutes, for example: 14:15 (two fifteen PM).
 
When you use these validation rules for date and time comparisons (AMAZON.DATE and AMAZON.TIMEslot types), note the following,
  • "greater than" means after the date or time
  • "less than" means before the date or time 
For example, if you use isGreaterThan with an AMAZON.DATE slot and set the value to 2020-01-01, the slot accepts any date after January 1, 2020. Both December 31, 2019 and January 1, 202 would fail validation. Use isGreaterThanOrEqualTo to include January 1 as a valid date.
 

Compare dates or times to a specified time span

 
These rules let you either accept or reject a date or time that falls within a particular time span. You can use these rules with AMAZON.DATE and AMAZON.TIME slots.
 
Validation  Description  Type  Parameters 
Accept within a duration  Accept date or time values that fall within a specified time span. If the user's value is before or after the specified time span, the value fails validation.  isInDuration  The start and end of the time span. For details, see below. 
Reject within a duration  Reject date or time values that fall within a specified time span. If the user's value is within the specified time span, the value fails validation.  isNotInDuration  The start and end of the time span. For details, see below. 
 
You can use relative and absolute dates and times to specify the start and end of the time span
 
AMAZON.DATE
 
Provide the start and end as either,
  • Specific dates in ISO-8601 calendar date format.
  • Durations in days in ISO-8601 duration format (PnD). For example, P10D for 10 days. Note that the validation does not support durations that include other units such as months or years.
AMAZON.TIME
 
Provide the start and end as either,
  • Specific times in ISO-8601 time format.
  • Durations in hours and/or minutes in ISO-8601 duration format (PTnHnM). For example, PT10H for ten hours, or PT5H30M for five hours and thirty minutes.
The start and end of the time span are relative to when the user makes the request to your skill, based on the user's configured time zone. If the user's device is not configured with a time zone, the validation assumes GMT. The start time must come before the end time.
 

Summary

 
In this article, I explained all of the validation rules available in detail and the slot types with which they can be used. For each validation a proper example has been provided.