FormAction is not working -- Utterance is not getting repeated until the slot value is filled

Dear Team,

When using FormAction to fill the slot and to generate same utterance when the expected value in the slot is not filled-- Utterance is not getting generated repeatedly

Error Log DEBUG:rasa_core_sdk.forms:Trying to extract requested slot ‘gender’ … DEBUG:rasa_core_sdk.forms:Got mapping ‘{‘type’: ‘from_entity’, ‘entity’: ‘gender’, ‘intent’: [], ‘not_intent’: []}’ DEBUG:rasa_core_sdk.forms:Failed to extract requested slot ‘gender’ ERROR:main:Failed to validate slot genderwith action <bound method ProductSearchForm.name of <actions.ProductSearchForm object at 0x7fa4bbc37f60>>

Content of Action file

 def validate(self, dispatcher:CollectingDispatcher, tracker: Tracker,
             domain: Dict[Text, Any]) -> List[Dict]:

    "Validate extracted requested slot else raise an error"

    # extract slots that are not requested but set by corresponding entity
    slot_values = self.extract_other_slots(dispatcher, tracker, domain)

    #extract requested slot
    slot_to_fill = tracker.get_slot(REQUESTED_SLOT)


    if slot_to_fill:
        slot_values.update(self.extract_requested_slot(dispatcher, tracker, domain))

        if not slot_values:
            raise ActionExecutionRejection(self.name(),
                                           "Failed to validate slot {0}"
                                           "with action {1}"
                                           "".format(slot_to_fill, self.name))


    for slot, value in slot_values.items():
        print(slot)
        print(value)
        if slot_values[slot] == 'gender':
            if value.lower() not in self.gender_db():
                dispatcher.utter_template('utter_wrong_gender', tracker)

                slot_values[slot] = None


    return [SlotSet(slot, value) for slot, value in slot_values.items()]
1 Like

This is because ActionExecutionRejection is raised and as in exception name, it is rejecting to execute action. To overcome, you can overload validate func like this

    def validate(self, dispatcher, tracker, domain):
        try:
            return super().validate(dispatcher, tracker, domain)
        except ActionExecutionRejection as e:
            # could not extract entity
            dispatcher.utter_message(
                "Sorry, I could not parse the value correctly. \n"
                "Please double check your entry otherwise I will ask you this forever"
            )
            return []

then it should continue to ask until user put correct value that can be parsed. But this is not good solution because there is no way for user to get out of the conversation until user input expected value/format. So add more data and train so that “correct” data can be extracted to avoid this error. Also as per doc (Slot Filling) you want to add stories for unexpected user behavior.

2 Likes