# Mute 'utter\_ask' in forms for validation questions

**URL:** <https://forum.rasa.com/t/mute-utter-ask-in-forms-for-validation-questions/9157>\
**Category:** Rasa Open Source\
**Created:** [April 30, 2019, 9:04am UTC](https://forum.rasa.com/t/mute-utter-ask-in-forms-for-validation-questions/9157 "2019-04-30T09:04:30Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zylatis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/zylatis/32/2468_2.png) [@Zylatis](https://forum.rasa.com/u/Zylatis)\
**Post date:** [April 30, 2019, 9:04am UTC](https://forum.rasa.com/t/mute-utter-ask-in-forms-for-validation-questions/9157/1 "2019-04-30T09:04:31Z")

</div>

Hey,

I have a form which asks for a bunch of things that each need different clarification. for example if the form asks for a suburb an postcode it needs to check if they are a valid match before proceeding.

Currently in validate() i can do this check, set those slots to None again so the form knows to fill them, and issue the appropriate utterance. However, this will result in the form asking the original question again, on top of the situation-specific validation i already sent.

For example, in the validate() function I have python code which checks against a database and if not matches are found, it utters a message listing the top 3 matches. As it stands, Rasa will then ask again for ‘please enter address’ after this, which i would like to avoid.

I have played with UserUtteranceReverted() and so on but nothing seems to work, the FormAction will always replay that question no matter what.

I understand maybe i should do this in stories, but I feel like this would be quite complicated, as i would need stories showing how the form was interrupted, then have some custom actions maybe to do the parsing, and maybe a checkpoint to make sure it is looped over until complete.

I guess I could also just define a custom action that is called from within the form and which calls itself and sets/unsets slots until the condition is satisfied, but that seems a little wonky.

Suggestions appreciated!

---

<div class="post-metadata">

**Author:** ![srikar\_1996](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@srikar\_1996](https://forum.rasa.com/u/srikar_1996)\
**Post date:** [April 30, 2019, 12:08pm UTC](https://forum.rasa.com/t/mute-utter-ask-in-forms-for-validation-questions/9157/2 "2019-04-30T12:08:12Z")

</div>

Do you mean something like when the third slot value in the sequence of slots is wrong, then the validate() is asking for all the slot values again? It should not ask the original question again, since that slot is already validated.

---

<div class="post-metadata">

**Author:** ![Zylatis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/zylatis/32/2468_2.png) [@Zylatis](https://forum.rasa.com/u/Zylatis)\
**Post date:** [April 30, 2019, 12:23pm UTC](https://forum.rasa.com/t/mute-utter-ask-in-forms-for-validation-questions/9157/3 "2019-04-30T12:23:23Z")

</div>

Ah no not like that. What i’m talking about goes on here

> <https://github.com/RasaHQ/rasa_core_sdk/blob/e81674d80cdee56f149578af1e4b11cf3b5dfdfc/rasa_core_sdk/forms.py#L371>

which will always utter\_ask\_slot regardless of context, i.e. if it is the first time the user has been asked this, or if the form is asking again because of clarification. One would expect these to be different, and so reasonably should be different paths in the stories which i’m still working on.

To your point about the example, the same thing i’m talking about would happen with just a single slot. I want it such that if you give it an input that fails validation, that the utter\_failed message gives useful information, and isn’t immediately followed by utter\_ask\_slot, which is what the FormAction will always do you if you set the slot to None. It kinda makes sense that the validation step doesn’t allow crazy branching to happen under the hood otherwise Core would get confused, but it’d be neat for my current task =)

---

<div class="post-metadata">

**Author:** ![srikar\_1996](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@srikar\_1996](https://forum.rasa.com/u/srikar_1996)\
**Post date:** [April 30, 2019, 1:09pm UTC](https://forum.rasa.com/t/mute-utter-ask-in-forms-for-validation-questions/9157/4 "2019-04-30T13:09:33Z")

</div>

Oh I see. I get it now. I have a simpler case where I have 3-4 required slots and I validate each slot. You can specify different utterances in required and validate method.

A simple example is a date slot. The first time the bot says **please specify the date** and if the user selects a wrong date, then in the validate I ask **please choose an alternative date**. But this is a simple scenario which still sticks to the same story. I’m not sure branching is possible with forms but yes, it will be very useful if we could do that.

Some sort of branching should be possible by specifiying conditions in required slots, although not very complicated.

---

<div class="post-metadata">

**Author:** ![Zylatis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/zylatis/32/2468_2.png) [@Zylatis](https://forum.rasa.com/u/Zylatis)\
**Post date:** [April 30, 2019, 10:49pm UTC](https://forum.rasa.com/t/mute-utter-ask-in-forms-for-validation-questions/9157/5 "2019-04-30T22:49:08Z")

</div>

Oh i see, you mean you have a ‘is\_validated’ flag/slot? Nice idea. I had thought about using that but to enable story branching, perhaps I was over-complicating things! I think the trick is still to return a custom message after the utter\_ask, not before.

EDIT: A possible way around this is to have a slot that stashes the message i want to send and have the utter\_validate print that out

---

<div class="post-metadata">

**Author:** ![srikar\_1996](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@srikar\_1996](https://forum.rasa.com/u/srikar_1996)\
**Post date:** [May 1, 2019, 9:01am UTC](https://forum.rasa.com/t/mute-utter-ask-in-forms-for-validation-questions/9157/6 "2019-05-01T09:01:52Z")

</div>

> [@Zylatis](#):
>
> EDIT: A possible way around this is to have a slot that stashes the message i want to send and have the utter\_validate print that out

Yes, this is what I was talking about.

```auto
def validate(self, dispatcher, tracker, domain):

        slot_values = self.extract_other_slots(dispatcher, tracker, domain)
        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():
            if slot == 'DATE':
                    # put your validations here
                    dispatcher.utter_message('Sorry, please select a different date.')
                    slot_values[slot] = None

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

def request_next_slot():

```

---

<div class="post-metadata">

**Author:** ![Zylatis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/zylatis/32/2468_2.png) [@Zylatis](https://forum.rasa.com/u/Zylatis)\
**Post date:** [May 1, 2019, 11:03pm UTC](https://forum.rasa.com/t/mute-utter-ask-in-forms-for-validation-questions/9157/7 "2019-05-01T23:03:41Z")

</div>

Ah okay but this comes back to the original problem (unless you also redefined request next slot, the body of which is cut off in your post)

In your case, if Date is what i want to fill then it will utter your ‘sorry’ message but then also utter ask\_date afterwards because date is None, right?

What I have done which seems to work for now is have an is\_address\_valid slot and a stashed\_address slot. So when i do the validation, if the validation fails i set the valid slot to None so it goes into a loop there and at each step in the loop i put the suggested valid addresses in stashed\_address so that i can give single utterance that is dynamic (basically a way to save information from python into the next loop of the form).

Probably I am overcomplicating things but i was wary of storing things in any other way because i expect multiple users each with their own trackers so i don’t want to store anywhere else i think

---

<div class="post-metadata">

**Author:** ![srikar\_1996](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@srikar\_1996](https://forum.rasa.com/u/srikar_1996)\
**Post date:** [May 2, 2019, 4:20am UTC](https://forum.rasa.com/t/mute-utter-ask-in-forms-for-validation-questions/9157/8 "2019-05-02T04:20:30Z")

</div>

> [@Zylatis](#):
>
> In your case, if Date is what i want to fill then it will utter your ‘sorry’ message but then also utter ask\_date afterwards because date is None, right?

Hey, so it doesn not repeat the next slot again. Only the first time, it utters the statement in **request\_next\_slot**. If it fails, it will utter the sorry message and not the one in req\_next\_msg. Even though the slot is set to null, it won’t take the message from **next\_slot**

---

<div class="post-metadata">

**Author:** ![Zylatis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/zylatis/32/2468_2.png) [@Zylatis](https://forum.rasa.com/u/Zylatis)\
**Post date:** [May 2, 2019, 5:52am UTC](https://forum.rasa.com/t/mute-utter-ask-in-forms-for-validation-questions/9157/9 "2019-05-02T05:52:13Z")

</div>

Okay but what if your validation fails a second time?

---

<div class="post-metadata">

**Author:** ![srikar\_1996](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@srikar\_1996](https://forum.rasa.com/u/srikar_1996)\
**Post date:** [May 2, 2019, 6:03am UTC](https://forum.rasa.com/t/mute-utter-ask-in-forms-for-validation-questions/9157/10 "2019-05-02T06:03:19Z")

</div>

It keeps repeating the statement in **validate()** until the right slot value is entered.

---

<div class="post-metadata">

**Author:** ![Zylatis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/zylatis/32/2468_2.png) [@Zylatis](https://forum.rasa.com/u/Zylatis)\
**Post date:** [May 2, 2019, 6:06am UTC](https://forum.rasa.com/t/mute-utter-ask-in-forms-for-validation-questions/9157/11 "2019-05-02T06:06:06Z")

</div>

Interesting, mine always re-asks the ‘ask\_slot’ before getting to validate, I will investigate. To clarify: did you mean to include the code snippet of def request\_next-slot() at the bottom?

---

<div class="post-metadata">

**Author:** ![srikar\_1996](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@srikar\_1996](https://forum.rasa.com/u/srikar_1996)\
**Post date:** [May 2, 2019, 6:35am UTC](https://forum.rasa.com/t/mute-utter-ask-in-forms-for-validation-questions/9157/12 "2019-05-02T06:35:32Z")

</div>

It will ask the **validate\_slot** first and then only the **next\_slot**. Yes, **request\_next-slot()** should be there.

---

<div class="post-metadata">

**Author:** ![Zylatis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/zylatis/32/2468_2.png) [@Zylatis](https://forum.rasa.com/u/Zylatis)\
**Post date:** [May 2, 2019, 7:27am UTC](https://forum.rasa.com/t/mute-utter-ask-in-forms-for-validation-questions/9157/13 "2019-05-02T07:27:58Z")

</div>

Ah okay so you overrode that function, that is why, right?

---

<div class="post-metadata">

**Author:** ![srikar\_1996](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@srikar\_1996](https://forum.rasa.com/u/srikar_1996)\
**Post date:** [May 2, 2019, 7:50am UTC](https://forum.rasa.com/t/mute-utter-ask-in-forms-for-validation-questions/9157/14 "2019-05-02T07:50:37Z")

</div>

I did override the **request\_next\_slot()** method but that was to include buttons in my messages. The validate method, I’m using as it is.

While I was working, I referred to this: [forms](https://medium.com/rasa-blog/building-contextual-assistants-with-rasa-forms-7c034c9a8677)

---

<div class="post-metadata">

**Author:** ![Zylatis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/zylatis/32/2468_2.png) [@Zylatis](https://forum.rasa.com/u/Zylatis)\
**Post date:** [May 3, 2019, 12:50pm UTC](https://forum.rasa.com/t/mute-utter-ask-in-forms-for-validation-questions/9157/15 "2019-05-03T12:50:28Z")

</div>

Me to, but if you download the formbot and run it you will find if you give the num\_people a -1, so the validation fails, you will get

```auto
number of people should be a positive integer, please try again
how many people?

```

so it does indeed re-ask, does yours not?

---

<div class="post-metadata">

**Author:** ![srikar\_1996](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@srikar\_1996](https://forum.rasa.com/u/srikar_1996)\
**Post date:** [May 3, 2019, 1:17pm UTC](https://forum.rasa.com/t/mute-utter-ask-in-forms-for-validation-questions/9157/16 "2019-05-03T13:17:22Z")

</div>

Yes, it does re-ask me. But the validation is being asked first right. Isn’t that what you wanted?

> [@Zylatis](#):
>
> Interesting, mine always re-asks the ‘ask\_slot’ before getting to validate,

You said yours is going into next\_slot() before the validation right?

---

<div class="post-metadata">

**Author:** ![Zylatis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/zylatis/32/2468_2.png) [@Zylatis](https://forum.rasa.com/u/Zylatis)\
**Post date:** [May 3, 2019, 2:16pm UTC](https://forum.rasa.com/t/mute-utter-ask-in-forms-for-validation-questions/9157/17 "2019-05-03T14:16:46Z")

</div>

No i meant it is asking the validate question and then re-asking the original question, i am trying to avoid this

---

<div class="post-metadata">

**Author:** ![srikar\_1996](https://avatars.discourse-cdn.com/v4/letter/s/e274bd/32.png) [@srikar\_1996](https://forum.rasa.com/u/srikar_1996)\
**Post date:** [May 4, 2019, 7:24am UTC](https://forum.rasa.com/t/mute-utter-ask-in-forms-for-validation-questions/9157/18 "2019-05-04T07:24:24Z")

</div>

So I was thinking, maybe you can have a slot (not a required slot, something like True/False) which is set the first time you enter **validate()** and then override the **next\_slot()** to check for this slot and if True then do not utter the message in **next\_slot()**.

---

<div class="post-metadata">

**Author:** ![Zylatis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/zylatis/32/2468_2.png) [@Zylatis](https://forum.rasa.com/u/Zylatis)\
**Post date:** [May 4, 2019, 11:17am UTC](https://forum.rasa.com/t/mute-utter-ask-in-forms-for-validation-questions/9157/19 "2019-05-04T11:17:28Z")

</div>

Yep, that’s what i’ve got going at the moment 🙂 It’s a solid workaround but does make things a little clunky, as i have several forms that need it, adds to slot proliferation.

Thanks for the good discussion! 🙂

---

<div class="post-metadata">

**Author:** ![kothiyayogesh](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/kothiyayogesh/32/324_2.png) [@kothiyayogesh](https://forum.rasa.com/u/kothiyayogesh)\
**Post date:** [January 7, 2020, 10:45am UTC](https://forum.rasa.com/t/mute-utter-ask-in-forms-for-validation-questions/9157/20 "2020-01-07T10:45:38Z")

</div>

Can you please share example code?

[Next page](https://forum.rasa.com/t/mute-utter-ask-in-forms-for-validation-questions/9157.md?page=2)
