How do I deactivate a form during validation?

Hi @ChrisRahme ,

To deactivate a form, you can simply return this from a validate_{slot} method:

return { "requested_slot": None}

That will deactivate the Form.

The dictionary of slots returned from a validate_<slot_name> will be converted into SlotSet events by the caller before it is sent back to Rasa. Note that it is not needed to also return an ActiveLoop(None) event. Just setting the requested_slot to None is sufficient.

If you do nothing else, the bot will just go and listen, which might confuse the user.

We implemented something similar in the financial-demo starter pack, but went a little further, to support this logic:

  • Keep track of the number of repeated validation failures, using a special slot
  • After a certain number of failures:
    • explain the slot to the user
    • reset the counter
    • ask if they want to continue with the form
      • If the user answers yes, keep going
      • If the user answers no, deactivate the form
        • When the form is deactivated, a rule calls a custom action that confirms that the form was stopped

This way, the bot is always trying to help the user, and provides a nice option to exit a form.

This logic was abstracted away in a CustomFormValidationAction. If you want to use this logic in your bot, you can do so with minimal effort by:

7 Likes