A chatbot is what we have been working with and we have already built different chatbots as well as the voice bots in our previous blogs, but there we may have faced one problem and that is a major concern while building a chatbot or voice bot and that is know as fallback.

So while interacting with the chatbot or the voice bot if you say anything wrong or the text is out of the context. So, in that case, either it will reply with the wrong message or the output message is not up to the mark. Also, if the reply is wrong it won’t ask you to correct it instead it will move to the next step as per the story.

So, here we need a policy that can handle such a situation, and also instead of avoiding the problem and replying with the wrong messages, it will ask you to rephrase the input message and to follow the story from the same state.

Firstly, build a voice bot to apply the fallback policy from this post or check this video to build the chatbot.


In this blog you will learn:

  1. Different fallback policies
  2. Fallback policy
  3. Two-StageFallbackPolicy
  4. Its practical implementation with default as well as the custom fallback policies

Different Fallback Policies

There are two types of Fallback policies in rasa that handles the situation of breaking the flow of the conversation,

  1. FallbackPolicy
  2. TwoStageFallbackPolicy

What is Fallback Policy?

Policies that are used to handle the fallback cases by adding either the FallbackPolicy or the TwoStageFallbackPolicy with respect to the confidence value of the nlu and the core and to avoid the situation of breaking the flow of the conversation.

The FallbackPolicy has one fallback action, which will be executed if the confidence of intent recognition is below the nlu_threshold or if none of the dialogue policies predict action with confidence above the core_threshold.

Adding the fallback policy to your rasa project is very easy and very interesting, you simply have to add the following lines to your config.yml, inside the policies:

- name: "FallbackPolicy"
- nlu_threshold: 0.4
- core_threshold: 0.3
- fallback_action_name: "action_default_fallback"

In the above fallback policy you can accordingly adjust the values of nlu_threshold and core_threshold as per your project requirement for fallback cases. Here action_default_fallback is the default fallback action in rasa core which sends the utter_default response to the user.

So in this fallback situation to get the response you have to mention utter_default in the domain.yml to get the response eg: “Sorry, Didn’t understand. Please say again”. Also with this response, it will be reverted back to the state of the conversation before the user message that caused the fallback so that it will not influence future actions.

This process will executes the fallback action and goes back to the previous state of the dialogue.

Also, add the template in the domain.yml file as,

- text: “Sorry, Didn’t understand. Please say again”

Similarly, you can create your own custom fallback action like this to work with your projects. In that case simply update the policy as mention above with the fallback name.

- name: "FallbackPolicy"
- nlu_threshold: 0.4
- core_threshold: 0.3
- fallback_action_name: "my_fallback_action"

So, replace the fallback name with the custom fallback that you have created in your project.

The most import thing to keep in mind while creating a custom fallback action you have to return the UserUtteranceReverted in the action file, to avoid the inaccurate next predictions of the bot, as it is very likely that the fallback action is not present in your stories.

## fallback story
* bot_challange
- action_default_fallback

Everytime you will face the fallback case it will be triggered with an intent name let’s say it is bot_challange, then you should add this story:

After these updations in the project, now train the model and test your bot. It should accept the wrong intents and trigger the fallback actions.

How to handle fallback actions in rasa chatbot

Two-Stage Fallback Policy

Similarly, as you have done for the FallbackPolicy we can can do it with the TwoStageFallbackPolicy as well. All the steps will be same as done before but there will will be a difference in the functionality and how we add the policies in the config file.

Firstly, let’s understand what does TwoStageFallbackPolicy is and when it is used.

TwoStageFallbackPolicy is another type of a fallback policy that is used for handling the fallback cases to avoid the situation of breaking the flow of the conversation and to handle the wrong or unknown intents. The TwoStageFallbackPolicy handles low NLU confidence in multiple stages by trying to disambiguate the user input but the low core confidence in handled in the same way as we did it in FallbackPolicy.

To make it work rest all the process will be same as for the Fallback just need to change the policy in the config file as below,

- name: TwoStageFallbackPolicy
- nlu_threshold: 0.3
- core_threshold: 0.3
- fallback_core_action_name: "action_default_fallback"
- fallback_nlu_action_name: "action_default_fallback"
- deny_suggestion_intent_name: "out_of_scope"

Here, also you can adjust the threshold of nlu and core accordingly and with respect to the threshold values we can set the default or the custom fallback action for both core and nlu manually. If the intent didn’t matched the you can give the suggession as out_of_scope to enter the input again. This out_of_scope must be added in the domain file in the intent section to make it work.

In TwoStageFallbackPolicy, we have different default fallback actions,

  • action_default_ask_affirmation
  • action_default_ask_rephrase

Now, When you will train the model and run it. You will get an intelligent chatbot or voice bot that you are expecting it to be.

To watch the practical implementation of this check this video:

Time to wrap up now. Hope you liked our content on How to use fallback actions in Rasa chatbot. See you in our next blog, thanks for reading our blog and do leave a comment below to help us improve the content to serve you all of our experience with you. Stay tuned with us for more Rasa Chatbot contents.

Also check out our other playlist Rasa Chatbot, Internet of things, Docker, Python Programming, etc.
Become a member of our social family on youtube here.

Till then stay tuned and happy learning 🤗

Ashish Saini
Ashish Saini

I am a software developer for Python/Machine Learning. Also, I’m Rasa Hero at Rasa. Also, I’m a youtuber where I regulary uploads the videos to help this generation learn about the technology just like they are playing games.

Leave a Reply