Failed to validate custom FormAction

Hi guys,

I want to add a validate function into my custom FormAction. The user is asking the bot for the foodmenu in a specific part of an organization. The entity/slot_name is called “gastro_loc”.

I added several training examples with the slot_values “mensa” and “canteen”.

Note: Only this two values appear in the examples, because the organization just has this two.

Now here is a part of my FormAction:

    def gastro_loc_db(self):
        # type: () -> List[Text]
        """
        database of supported gastro locations
        :return:
        """
        return ["mensa",
                "canteen"]

def validate_gastro_loc(self,
                     value: Text,
                     dispatcher: CollectingDispatcher,
                     tracker: Tracker,
                     domain: Dict[Text, Any]) -> Optional[Text]:
    """Validate cuisine value."""

    if value.lower() in self.gastro_loc_db():
        # validation succeeded
        return {'gastro_loc': value}
    else:
        self.deactivate()
        dispatcher.utter_template('utter_wrong_gastro_loc', tracker)
        # validation failed, set this slot to None, meaning the
        # user will be asked for the slot again
        return {'gastro_loc': None}

I also added the utter_wrong_gastro_loc in the domain.yml file.

Now I want to test the bot and I ask him about the food menu. I want the menu for the cafeteria, so the bot should know that cafeteria does not exist and print the utter_wrong_gastro_loc. But I just got following message:

2019-08-12 10:06:18 ERROR rasa_sdk.endpoint - Failed to extract slot gastro_loc with action gastronomy_form 127.0.0.1 - - [2019-08-12 10:06:18] “POST /webhook HTTP/1.1” 400 256 0.007018

So where is the mistake in my code? Do I need to add some examples with cafeteria value in my training examples? I just want to validate the users input for the location. If the users chooses any other location than “mensa” or “canteen” the bot should answer “please choose between mensa and canteen”

Thanks

        self.deactivate()
        dispatcher.utter_template('utter_wrong_gastro_loc', tracker)
        # validation failed, set this slot to None, meaning the
        # user will be asked for the slot again

I’m not sure why you need to deactivate the form right there. If you want the bot to ask for the slot again then why do you deactivate the form ?

ah sorry, I forgot to delete this line after I posted this question. This was just for testing purpose, have the same problem without this line too.

Oh, then it’s probably as you guessed. The training data only included ‘mensa’ and ‘canteen’ so the bot didn’t generalize well (basically it thinks that only ‘mensa’ and ‘canten’ should be recognized as ‘gastro_loc’). I had the same problem before with people names so i just put more diverse training data.

But thats exactly what I want. Only ‘mensa’ and ‘canteen’ are valid values for the gastro_loc. All other user inputs should be fail after the validate_gastro_loc function. So the user input cafeteria should also fail with the bot answer ‘please choose between mensa and canteen’, but this is not the case. I just get the error message from above

Yes, because the bot failed to recognized any entities at all:

If nothing is extracted from the user’s utterance for any of the required slots, an ActionExecutionRejection error will be raised, meaning the action execution was rejected and therefore Core will fall back onto a different policy to predict another action.

It doesn’t see any entities so it can not procede to validate anything. You can look into the code of the validate function of forms.py (just validate() and not the validate_{slot_names}) for more information.

now I understand the problem. Thank you very much for your help!