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.
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.
-
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
. -
Step #1 prompts rasa to activate
action_ask_answer
again, so the action server receives a request to run it. -
Inside
action_ask_answer
, I extract the second to latest event to see ifutter_too_short
ever happened using a try/except block:try: template = tracker.events[-2]["metadata"]["template_name"] except: template = None
-
I only repeat the message when
template
is notutter_too_short
:if template != "utter_too_short": dispatcher.utter_message(template="utter_ask_answer")
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