Utter a different message when repeating a question in a form

Hi all!

In a form, how would you go about uttering a different message if the answer to a requested slot did not validate? In some cases, if the user answers something wrong, I’d like to provide more information so that they have an easier time answering the message (or give more context). It could also be useful the other way around: give a bit more context initially but if we need to repeat the question, write a shorter utterance.

For example:

Cheers, Nicolas

How about calling dispatcher.utter_message from inside the validation function?

Thanks for your answer @saurabh-m523! That would indeed work for some cases but only as a separate message before repeating the question. That works well but doesn’t give me the flexibility I need in some cases unfortunately.

1 Like

Well I couldn’t think of anything other than overriding the request_next_slot method if you want to modify the way the slots are being asked. Look into it, maybe that could help.

1 Like

Good idea, I’ll have a shot at it

I had the same problem today and this is how I solved it:

My use-case is for when users provide an answer that needs to be of a certain length.

:warning: Pre step: Handle your utter_ask_<slot_name> in the action server instead. In other words, convert it into an action_ask_<slot_name>. Let’s call it action_ask_answer for this example.

  1. My validate function goes as normal. If the response is less than 5 words long, it fills the slot with “None”. This also dispatchers an utterance, let’s call it utter_too_short.

  2. Step #1 prompts rasa to activate action_ask_answer again, so the action server receives a request to run it.

  3. Inside action_ask_answer, I extract the second to latest event to see if utter_too_short ever happened using a try/except block:

         template = tracker.events[-2]["metadata"]["template_name"]
         template = None
  4. I only repeat the message when template is not utter_too_short:

     if template != "utter_too_short":

This also works great when you are validating for other things that may require the repeated message. For example, when my users answer in a non-English language, I want to be able to say utter_not_english followed by utter_ask_answer