0
votes

I want to be able to specify a custom list of valid options for a slot that LEX will either attempt to approximate towards or, in the event that no valid option can be approximated, reject the invalid response.

At first I attempted to do this through custom slot types. And though their examples may lead you to believe these are enumerations, they are not. A user still has the capacity to input whatever value they like.

Their documentation has this to say: https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/migrating-to-the-improved-built-in-and-custom-slot-types#literal

A custom slot type is not the equivalent of an enumeration. Values outside the list may still be returned if recognized by the spoken language understanding system. Although input to a custom slot type is weighted towards the values in the list, it is not constrained to just the items on the list. Your code still needs to include validation and error checking when using slot values.

I am aware that I can validate their submission through a lambda after they have completed their full submission, but by then it's too late. A user has submitted their full intent message. I'm unable to capture it midway and correct them.

Am I missing some way to input slot options or a configuration option for custom slot types? Is there any way to enforce a custom list of options for a slot? (Similar to utterances for intents, or the built in slot types, which will ask the same question again if there is no match.)

Thanks!

1

1 Answers

1
votes

I'm unable to capture it midway and correct them.

You can capture the error in lambda without fulfilling the intent and starting over. Here's how I validate input with Python.

If you detect a validation error in lambda, you can elicit the same slot and pass your error message. This allows you to set complex validation rules and have your bot return specific responses to the user.

   def validate(input):
       if input not in ['foo', 'bar']:
           return elicit_slot("Your response must be foo or bar")



   def elicit_slot(error_message):
        return {
            'dialogAction': {
                'type': 'ElicitSlot',
                'intentName': current_intent,
                'slots': current_slots,
                'slotToElicit': slot_with_validation_error,
                'message': {'contentType': 'PlainText', 'content': error_message }
        }
    }