Form deactivation when something went wrong

Hi all,

I’d like to handle the case something went wrong when filling out a form.

In my case I have two requested slots and during the validation of the first one I make and API call to a backend service to retrieve some information.

How can I deactivate my form and block the system to ask for the subsequent requested slot if the API call went wrong?

I’ve read about self.deactivate but I’m not sure how to use it during validation


Hi @GabrieleRomeo!

You can’t do it form the validation function, you need to override the request_next_slot() method. See below.

From the docs:

In case the slot is filled with something that you are certain can’t be handled and you want to deactivate the form directly, you can overwrite the request_next_slot() method to do so. The example below checks the value of the cuisine slot directly, but you could use any logic you’d like to trigger deactivation:

    def request_next_slot(
    dispatcher: "CollectingDispatcher",
    tracker: "Tracker",
    domain: Dict[Text, Any],
) -> Optional[List[EventType]]:
    """Request the next slot and utter template if needed,
        else return None"""
    for slot in self.required_slots(tracker):
        if self._should_request_slot(tracker, slot):

            ## Condition of validated slot that triggers deactivation
            if slot == "cuisine" and tracker.get_slot("cuisine") == "caribbean":
                dispatcher.utter_message(text="Sorry, I can't help you with that")
                return self.deactivate()

            ## For all other slots, continue as usual
            logger.debug(f"Request next slot '{slot}'")
                template=f"utter_ask_{slot}", **tracker.slots
            return [SlotSet(REQUESTED_SLOT, slot)]
    return None

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.

Hi @saurabh-m523

thanks for your reply.

I’ve tried to follow the instructions from the docs and I’ve overwrote the request_next_slot method but now if all the requested slots are not filled out from the user input at the beginning the chatbot does not ask them anymore :roll_eyes:

It seems that the utter_message method is not being triggered

                template=f"utter_ask_{slot}", **tracker.slots

In my domain.yml I’ve correctly set all the utter_ask_* responses

If I remove the request_next_slot method it works correctly

my fault,

the problem was related to a wrong import of REQUESTED_SLOT :sweat_smile:

Now it works as expected, cool!


1 Like

Glad I could help. :innocent: