# How to quit form loop using intent

**URL:** <https://forum.rasa.com/t/how-to-quit-form-loop-using-intent/52771>\
**Category:** Rasa Open Source\
**Created:** [April 22, 2022, 9:35am UTC](https://forum.rasa.com/t/how-to-quit-form-loop-using-intent/52771 "2022-04-22T09:35:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![anshu03654](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@anshu03654](https://forum.rasa.com/u/anshu03654)\
**Post date:** [April 22, 2022, 9:35am UTC](https://forum.rasa.com/t/how-to-quit-form-loop-using-intent/52771/1 "2022-04-22T09:35:36Z")

</div>

How to quit a form loop whenever a specific intent is detected in RASA 3.1? Like while using a form if the user doesn’t want to go further and say ‘stop’ or ‘end’ then the form should exit and all the filled slots should become empty. Here is how I have defined my slots…

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/f/a/fabc253e0be6d22afd18f86ea2cb5b6aa03faac5.png)This is how my form is defined ![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/8/0/80293fb93db565d8cf85b6219e7f3465074e5656.png)This is my slot validation action ![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/d/f/dfdd406fafed5101806cbc2a7bf957e640e5b642.png)any help would be great @anca

---

<div class="post-metadata">

**Author:** ![anca](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/anca/32/14540_2.png) [@anca](https://forum.rasa.com/u/anca)\
**Post date:** [April 22, 2022, 10:57am UTC](https://forum.rasa.com/t/how-to-quit-form-loop-using-intent/52771/2 "2022-04-22T10:57:13Z")

</div>

@anshu03654 Have you tried looking into using `action_deactivate_loop` in a story that handles this unhappy path? You can find out more in the [docs](https://rasa.com/docs/rasa/forms/#writing-stories--rules-for-unhappy-form-paths).

---

<div class="post-metadata">

**Author:** ![anshu03654](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@anshu03654](https://forum.rasa.com/u/anshu03654)\
**Post date:** [April 22, 2022, 12:04pm UTC](https://forum.rasa.com/t/how-to-quit-form-loop-using-intent/52771/3 "2022-04-22T12:04:26Z")

</div>

@anca I am using rule to fill up the forms. These are the rules for form activation and submission.

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/d/1/d14850009a4aedb10d87f9de4a262f3b9a8fa445.png)and this is the rule for unhappy path  
 ![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/f/9/f9ccc32de31bee4141d01fc2970d192eaee255d7.png)  
But still its not working

---

<div class="post-metadata">

**Author:** ![v\_kostis](https://avatars.discourse-cdn.com/v4/letter/v/ce73a5/32.png) [@v\_kostis](https://forum.rasa.com/u/v_kostis)\
**Post date:** [April 22, 2022, 6:40pm UTC](https://forum.rasa.com/t/how-to-quit-form-loop-using-intent/52771/4 "2022-04-22T18:40:01Z")

</div>

@anshu03654 I have the same problem. I wish I could help. action\_deactivate\_loop did not work for me, and to be honest your code seems solid… I’m marking this thread as Watching and I hope that someone provides a solution, since I have seen similar questions all the time and in most of which action\_deactivate\_loop _appears_ to be the solution.

---

<div class="post-metadata">

**Author:** ![anshu03654](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@anshu03654](https://forum.rasa.com/u/anshu03654)\
**Post date:** [April 23, 2022, 11:56am UTC](https://forum.rasa.com/t/how-to-quit-form-loop-using-intent/52771/5 "2022-04-23T11:56:12Z")

</div>

@v_kostis if you get any solution plese tell me…

---

<div class="post-metadata">

**Author:** ![v\_kostis](https://avatars.discourse-cdn.com/v4/letter/v/ce73a5/32.png) [@v\_kostis](https://forum.rasa.com/u/v_kostis)\
**Post date:** [April 23, 2022, 1:17pm UTC](https://forum.rasa.com/t/how-to-quit-form-loop-using-intent/52771/6 "2022-04-23T13:17:23Z")

</div>

@anshu03654 I was testing a couple of things and I’m quoting below the code that seems to work. As you can see, there are some differences in the submit form. Moreover, I do not use the initial action utter\_fill\_details in the “Activate Form”, since the form itself is responsible to ask for the required fields (I’m guessing utter\_ask\_email\_id in your occasion). Don’t know it if it plays some part, but you know, just pointing this out.

```auto
# Form to fill in the required slot (tracking_number)
- rule: Activate find_tracking_number_form
  steps:
  - intent: deliver_package
  - action: find_tracking_number_form
  - active_loop: find_tracking_number_form

- rule: Submit form
  condition:
  - active_loop: find_tracking_number_form
  steps:
  - action: find_tracking_number_form
  - active_loop: null

- rule: Stop tracking form
  condition:
  - active_loop: find_tracking_number_form
  steps:
    - intent: stop
    - action: action_deactivate_loop
    - active_loop: null
    - slot_was_set:
      - requested_slot: null
    - action: utter_initial_menu

```

If that’s not working, could you consider that there is something wrong with the validation of email\_id? I have used a similar action for email purposes. I present it below, with some minor changes to match your wording. I’m not questionning your code nor the use of fullmatch, it’s just that I recently used the below code.

```auto
class ValidateEmailForm(FormValidationAction):
	def name(self) -> Text:
		return "validate_email_form"

	def validate_email_id(self, slot_value: Any, dispatcher: CollectingDispatcher,tracker: Tracker, domain: DomainDict,) -> Dict[Text, Any]:
		email_id = next(tracker.get_latest_entity_values("email_id"), None)
		pattern = re.compile(r'([A-Za-z0-9]+[.-_])*[A-Za-z0-9]+@[A-Za-z0-9-]+(\.[A-Z|a-z]{2,})+')
		if(not pattern.match(email_id)):
			dispatcher.utter_message(text="Please enter a valid email id")
			return {"email_id": None}
		return {"email_id": email_id}

```

Could you try this and revert?

---

<div class="post-metadata">

**Author:** ![stephens](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/stephens/32/1632_2.png) [@stephens](https://forum.rasa.com/u/stephens)\
**Post date:** [April 23, 2022, 8:18pm UTC](https://forum.rasa.com/t/how-to-quit-form-loop-using-intent/52771/7 "2022-04-23T20:18:40Z")

</div>

The [financial-demo](https://github.com/RasaHQ/financial-demo/tree/main/data/stories) bot has good examples of how to handle this.

---

<div class="post-metadata">

**Author:** ![anshu03654](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@anshu03654](https://forum.rasa.com/u/anshu03654)\
**Post date:** [April 25, 2022, 7:51am UTC](https://forum.rasa.com/t/how-to-quit-form-loop-using-intent/52771/8 "2022-04-25T07:51:37Z")

</div>

@stephens I was using text mapping to fill up the slots that’s why it was not stopping even after identifying the intent.

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/3X/2/f/2fdc0e4a03a51271fc1a9fecbbfbda59fd646855.png)Is there a way to do this while mapping from text as subject and message of a mail can’t be mapped using intents or entities.

---

<div class="post-metadata">

**Author:** ![raoulvm](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/raoulvm/32/16472_2.png) [@raoulvm](https://forum.rasa.com/u/raoulvm)\
**Post date:** [May 5, 2022, 6:51am UTC](https://forum.rasa.com/t/how-to-quit-form-loop-using-intent/52771/9 "2022-05-05T06:51:28Z")

</div>

Hi @anshu03654 ,

I saw you’ve implemented a custom validation rule for email\_id, which by default returns a value for that slot - either `None` or the email\_id you’ve validated.

In that case Rasa stops processing intents. If you want to be able to react to the stop intent, you have to make your validation function `return {}` in case the last utterance has a recognized intent of “stop”:

```python
last_intent = tracker.latest_message.get("intent", {}).get("name")
if last_intent=="stop":
  return {}

```

If the form validation _does not_ return a slot, Rasa’s standard processing kicks in.
