09 Dialogflow CX Exception Handling

Lesson: DF Chooser Bot Demo

DF Chooser Bot Demo

[00:00] So in this chapter I am going to talk about exception handling and this is something which is a topic which was sort of raised by someone who has gone through the course and they are going through the course rather and asked me about exception handling in Dialogflow CX. Now I want to distinguish two different concepts before we get started. When I think of exception handling I am thinking of a user who wants to continue in the topic, in the same topic but they provide a response which is not something that your bot is able to actually understand which is why it is sort of like an exception or an error and you want to have a way to handle it.

The other way to think about this is what if the user changes the topic and they are intentionally changing the topic and that is not something that would come under the title of exception handling that would be an entirely different chapter all by itself.

[01:01] So here we are going to look only at exception handling. I have this CX based bot I have built which allows the user to choose between the three editions ES, CX and actions builder and it is a very simple bot. You can go to this article on my site and test it out. So you just start by typing the word help and the bot is going to ask do you need some help choosing this and you say yes and it is going to ask what channel are you using for your bot.

Notice that it does not have these suggestions prompts so it is just going to take the free form input in the step. I am going to say website bot and then it asks do you have the budget to hire a programmer and let us say I say no and it says if you prefer not to hire a programmer the best choice is ES because it is the most non-programmer friendly edition of Dialogflow. Now let us start over and I am going to say the same thing website bot. Let us say I say yes this time then it asks do you need to use slot filling in your bot.

[02:02] So I do not know what slot filling is. So I say what is slot filling. Notice that it is coming back with sorry I did not get that please use yes or no. So this is an example of an exception that is the user said something which the bot did not expect and what the bot is doing is it is just simply re-prompting them to provide an answer. So because it is going to say yes or no I am going to just assume that I am not using slot filling and I am just say no.

Then it asks will your bot answer follow up questions and once again I do not know what is that. So what is that and it is again prompting sorry I did not quite get that please answer with yes or no. I am going to say no again. Then it asks how many intents will you have in your bot let us just say I say a lot and notice that it is now re-prompting but this time it is a bit of a different type of re-prompt because it is asking hey please enter an integer because what you typed in before was not an integer.

[03:07] So this time I am going to say some number like let us say 20. So it then asks do you anticipate that your bot conversation will become more complex over time and the user says possibly. Then again it says sorry I did not quite get that please answer with just yes or no and I am going to say yes and it says I suggest using Dialogflow CX in that case.

So this is an example of a bot which is actually able to handle some exceptions. Now it is not going to be perfect in the sense that it is probably not going to handle every possible exception that you can throw at it that is not how I built it. But you still get the idea of what is going on here. In fact I would say that this is one of the nicest features in Dialogflow CX which is that when the user goes off track and that is what I mean here the exception handling is what I am referring to it is because Dialogflow CX has this concept of a state machine it remains in that same state and it is not going to go off to a new intent and things like that which you know it used to be the case with dialog flow ES where managing the state of the bot was a lot trickier and it ES allowed you to have fewer options when it comes to exception handling while CX is a lot more robust when it comes to this particular feature or you know this particular use case.


And the other thing I will point out is that I have a you can actually download a copy of this bot in this chapter and I would actually encourage you to download it you know it is a blob object that is the format in which they allow you to download the agent in Dialogflow CX and I would like you to take a look at that blob as we go forward with the next few lessons where I will actually show you how I built it inside of the CX console.

[05:11] So I just want to make sure that you have that ready because we have already covered most of the stuff that I will be explaining in the next few lessons that is I am not going to go into a lot of detail about how these things actually work I am just going to go fairly quickly and expect that you will be able to catch on with all the lessons in case you came to this chapter first instead of watching the previous chapters I would recommend that you go back and rewatch those chapters or watch them for the first time because I am going to move fairly quickly over the next set of videos.

Lesson: Does a flowchart help when creating a Dialogflow CX bot?

Does a flowchart help when creating a Dialogflow CX bot?

[00:00] When I first started working with Dialogflow ES, I actually came up with a system for designing a flowchart using a mind mapping software which will make it easy for people to you know first map out the conversation flow and then translate it easily into Dialogflow ES intents and the interesting thing about this and by the way I have this course on my website, this is a free course, you can just go and take a look at it. One of the interesting things that I have noticed is that this flowchart format that I have developed is actually quite useful even for Dialogflow CX.

Now I use the Mindomo software, Mindomo is a mind mapping software for creating these mind maps and I actually have some, I actually explain why I do that in this lesson that I call the flow charting tool I recommend, you can go and take a look at that but the thing is in the case of CX also I found that number one designing the flowchart is helpful and number two using Mindomo is actually will help you speed up the bot building process.

[01:14] The only thing if you can say that there’s a disadvantage is that this will be helpful for the initial design but once you have your bot you know built out inside CX and then you make some changes in CX you may find that it may not be easy to translate them over into this Mindomo map format because CX in a way is much more powerful and it supports a lot more features than the format that the Mindomo map supports.

Okay with that said I think that it’s still useful to design this flowchart and use it as a starting point and I think that it will still save you a lot of time. So in this case for the Dialogflow chooser bot what I’m going to do is I’m going to start with what channel will you use for deployment and notice that you know at this stage it’s very conversation look like, the chart itself looks very much like a conversation right when the user says something and the bot says what channel you use and if the user were to say one of these three things it’s going to say use actions builder by the way that’s the only case where it actually recommends actions builder when somebody is building an Actions on Google app and they mention that that’s what they’re building and if they say anything else it’s covered by this other wildcard you know entity which is just going to capture whatever else that they might say which is different from these from these words and then it just goes on to asking about can you hire a programmer to create custom integrations the user might say yes and they might say no if they say no it’s just going to say use es but if


they say yes then it’s going to ask will you be using slot filling in your bot and if they say yes at that point it’s going to say use dialogue for CX and if they say no it’s going to ask does your bot have to answer follow-up questions and so on and you can see that it’s come to this all the way to the bottom of this tree and notice that I don’t actually draw the exception handling inside this flowchart because this is supposed to be a rough sketch of what we are going to build the main reason that I’m making this video lesson is to show you that you know if you have this so you might be thinking right like wait what’s the what’s the whole point like you already have the dialogue for CX which is all visual and it has this visual state machine and you’re supposed to be able to infer all these things just by looking at the state machine and you might even say that the state machine approach is more powerful than what you can represent in a chart like this all those things are true


the only thing is this gives me a high level overview picture and it gives me an at-a-glance view that you don’t get when you go to Dialogflow CX console so I’m going to go over to the Dialogflow CX console right now and by the way this is what it looks like in dialogue flow cx so you can already see the problem the problem is the views that are available in dialogue flow cx are not um how do I say that it’s it’s sort of like at a level where you haven’t really drilled down into all the details that you really need to make complete sense of the conversation flow because by looking at this chart I’m guessing that you’ll not be able to really say what is going on right and even if you have to go and click on one of these pages like await help notice that it has these three routes user says yes user says no users they start over


but you don’t have the transition routes right so then you have to click on the yes again like you have to click on user says yes and even here you know funnily enough they don’t put the transition right over here or somewhere where it’s easy to see it without having to scroll unfortunately they do expect you to scroll all the way down to the bottom of this this view now that’s fine right it’s it’s sort of like systematic and it’s it’s a linear sort of an arrangement I think that is great but it’s not great when you’re looking at it from the viewpoint of how do I present all this information at a glance and then to make matters slightly worse you then have to click on the edit intent to see what training phrases are actually inside this intent like just by okay by looking at the name of the intent you can infer what training phrases are probably going to be there in this intent which is again you know that’s a good reason to have good naming for your


intents because you can absorb more information at a glance but if you’re if it’s not very obvious or maybe if you have a lot of training phrases you know this name of the intent is not going to be sufficient you might have to actually go and click on this edit intent and have to see all the training phrases inside to get a good picture of the bot’s you know behavior as well as to get a good picture of the what your bot is doing right so for all these reasons because the drill down view is not you know fine-grained enough I’m not sure how what’s the right word for it but I can say that this visual state diagram requires a lot of clicks to understand the overall conversation flow when you compare it with the Mindomo flow chart that I have over here so that’s why I encourage people to still use this flow chart it’s not really a mandatory thing but I think


that if you use it it will be very helpful.

Lesson: Bot Design Part 1

Bot Design Part 1

[00:00] So now that you have seen the Mindomo flowchart, what I’m going to do is I’m just going to quickly go through these pages that you have in this in my CX bot and quickly tell you what’s going on. So you have the start flow and of course you have the Default Welcome Intent and notice that it’s going to come back with the prompt for the with the suggestion chips and it’s going to ask you need help choosing between ESCX and actions builder and suppose the user and it’s going to transition over to this page called await underscore help and also I want you to notice that if the user said something which is other than the word help which is you can you know first of all remember that in the Dialogflow messenger integration for CX we don’t have this concept of setting a welcome intent which can automatically trigger a welcome prompt for the user.

So the user has to start by typing something to be able to start this conversation. Now in my mind I think the reason they are doing that is because they don’t want people to incur unnecessary charges.

[01:06] I’m not sure what I think that’s probably the reason but I don’t want to guess what’s going on all I can say is that that feature is available in dialog for ES but it’s not available in CX. Okay, so what I’m doing is no matter what the user says so in the no match default intent which is going to fire if they said anything other than the word help in fact if you go into this Default Welcome Intent you notice that the only training phrase I have is the word help so if they said help it goes and matches this route if they say anything else at all it’s going to match the sys.no match default route right and that is it’s going to trigger this event you can you can also put it that way.

In that case I’m just going to ask the same question again no matter what the user says they’re going to get that same question and once again it’s going to transition over to this page called await.help. So let’s go into await.help and here the user might say yes okay and in that case it’s actually going to go into this page called get channel that is which channel are they going to deploy the bot into if the user says no then it’s going to say okay I’m here if you need me and it’s just going to give this option to start over in the as a suggestion chip and if the user were to click on it it’s going to start the conversation over and how does that happen let’s see what is in this user says start over and if you go and look at the intent you expect to see the phrase start over and that’s exactly what you have and let’s go back so if the user were to say start


over we don’t have to re-prompt them and ask them what whether they need help or not we’ll just go to the first question which is what channel are you using for your bot and then we are going to go again to this page called get channel okay so quickly recapping user says yes you’re going to go to this get channel page user says no you’re going to not do a page transition you’re going to stay on the same page and then just give them the option to start over and if they click on that start over button it’s as if they type the phrase start over and you’re also going to go to the get channel page in that situation right all right so now let’s go to get channel and if they say any of the phrases that means Actions on Google app this is all this list of phrases that i have you can add some more if you want then what should happen is that it’s going to say if you’re building an Actions on Google app it is recommended by google to use the actions


builder and once again it’s going to provide this option to start over and as you would expect in that case it has to transition to this page called await dot help because remember that await help is the one which has the start over route okay now in the get channel the if the user says channel Actions on Google we already saw that it’s going to recommend actions builder and go to this help page but if they were to say something else if no matter what else they say like if in the case that i in the example i showed i said website bot it’s just going to ask the next question and the next question is do you have the budget to hire a programmer to build a custom integration and then it’s going to go to this get hire programmer page

Lesson: Bot Design Part 2

Bot Design Part 2

[00:00] So now let’s move on to the next few pages. If they were to say, let’s go actually to look at the get channel. And remember that if they said, if there was a no match, then what it does is it goes to the get higher programmer page and it asks, do you have the budget to hire a programmer to build a custom integration? So now let’s go and look at get higher programmer. And the user could say yes. And if they say yes, that means they have the budget to hire a programmer.

It’s going to follow up with another question. Do you need to use slot filling in your bot? And it also will go to this page called get users slot filling. If the user were to say no, that means they don’t have a budget to hire a programmer. It will just recommend yes. And once again, allow the user to start the conversation over and go to the await.help page. And if the user said something which the bot did not understand, it is going to say, sorry, I didn’t quite get that.

[01:02] Please use yes or no. So this is the exception handling that we are talking about. And notice that in this case, we don’t do any page transition. We are still in the to the large extent in CX is going to boil down to using the no match event and making sure that you don’t do a page transition. Now, you might want to think through whether you will always do this.

If that is always the best approach, there might be some situations where you may have to change your tactic a little bit. But for the most part, you will find that not changing the page, not doing a new transition is going to be sufficient for you to do exception handling in Dialogflow CX. Now, just to be a little more detailed in this and just to take a closer look at what is going on.

[02:05] So this is an answer to the question whether you have the budget to hire a programmer. And if the user were to say something which the bot doesn’t understand, which is that, let’s say they say something like, I am a programmer myself. So you have to think about that response because it’s going to say, sorry, I didn’t quite get that. Please use yes or no. And again, in a sense, they have answered the question.

They have told you that they don’t have to hire a programmer because they themselves are a programmer and you may want to have a different way to handle it and all that. But it’s just something for you to think about. And if they were to give you another response, which once again indicates that that’s not an answer that you are actually expecting, you have to think about whether it’s okay for you to stay in this loop.

[03:02] So there is this, you will have this problem where if you only have one no match default and the user is not able to get the right answer even after the second prompt, then you might get stuck in a sort of a loop. Again, this is a very, I’m going to say this is a question which has a lot of trade-offs. And when you start, you probably don’t want to worry too much about it and just have a single no match default event. But maybe if you see that users are getting stuck in some place in your conversation, at that point, you might have to go back and take a closer look and add another no match default, or maybe find some other way to handle it.

As you can see, some of this is not like, you can’t have hard and fast rules about designing these exceptions. You have to have it do some kind of a catch all when you begin, and then you have to slowly refine it and improve it so that you’re handling most of the user input.

[04:05] So that’s sort of the iterative approach to doing these things. So get higher programmer. And then the next question is get users slot filling, because the last question was, does the conversation use slot filling? And if the user says yes, it’s just going to say Dialogflow CX is best suited for slot filling bots. If the user says no, it’s going to say, will your bot answer follow-up questions?

And we have another sys no match default here also, where it’s again going to say, sorry, I didn’t quite get that. Please use yes or no. I just want to add one more thing, which is something that you might want to do. If the user still doesn’t get an answer, provide a response here, which I honestly find that that would be almost unlikely that they’re not going to be able to say yes or no. But in the worst case, if you think that that could happen, you could provide two suggestion chips with the words yes and no, just to make it extra clear to the user and have them click on one of those suggestion chips.

[05:09] So that’s one more thing that you can do. And that way you can sort of get away with just having this single no match default event handle, right? And then it’s going to go for get follow-up questions. When user says yes, it’s going to say if your bot uses follow-up intents, you can usually build a robust version of it using Dialogflow CX.

User says no. Oh, sorry. When the user says yes, let’s go back to this. Make sure that you go and transition to the await.help. When the user says no, it’s going to ask how many intents will you have in your bot? So the question was, will you use follow-up intents? And the user said no, and then it’s going to ask how many intents will you have in your bot? And it’s going to go to the get num intents page at that point in the conversation.

[06:03] And also notice that we have this is no match default event handler here also, which is doing the same thing effectively. Sorry, I didn’t quite get that. Please answer with yes or no.

Lesson: Bot Design Part 3

Bot Design Part 3

[00:00] So with the get follow-up questions, it’s going to say if the user says yes, then you can, the agent will just answer with use dialogue for CX and allow the user to start over. If the user says no, it’s going to ask them this question, how many intents will you have in your bot? The interesting thing about this question is that it actually expects a number, okay? So you can see that the structure of this page looks quite different from the other ones we have seen before, and I’m going to go over this very shortly.

So the first thing is that you’re going to collect a parameter in this intent. So the intent is named getNumIntents, and your goal in this page is to make sure that you get a number from the user, okay? So for that reason, what I’m doing is I’m going to select the type of the entity, and in this case, it’s just going to be sys.number-integer, and notice that I’ve made it a required parameter, okay?

[01:03] Remember that unlike in CX, I don’t have a problem using slot filling in ES because there are some very robust ways to handle it, okay? So what I mean by that is if the user says, remember when this bot was prompting for this number of intents, and I said a lot, it wasn’t actually going to the next step, instead it went into this no match one event.

This is what actually fired at the point. It says, please enter an integer, and it says approximate because you don’t have to know exactly how many, but you have to at least type, you have to at least input an integer. Let’s just say for some reason the user still isn’t typing in an integer, then you can go to the next no match two event, which is again, by the way, this is the highlight of Dialogflow CX because we don’t have this option in ES where it used to do a sort of a very blind type of re-prompting, right?

[02:01] So in this case, what the agent says is, unfortunately, I didn’t get that, and then we are also sort of imagining that the user was not very sure of what’s going on. So it’s going to say, if you’re not sure, it is best to start with Dialogflow ES. And the thing is, you notice that it actually transitions to await.help. So in other words, it’s actually exiting this page, okay? It’s exiting this page, and it’s actually gone to the next page.

And actually, it’s also, just to be clear, it’s showing this custom payload, which allows the user to start over if they want to, okay? So that’s the state of this bot. Then what if the user provided an integer? So it’s going to go into one of these routes at that point. And here, it’s going to be a condition-based route, not an intent-based route. It’s going to be a condition-based route. Whatever value was collected in this, by this numIntents parameter is going to define the next step, and you can see the condition is $session.params.numIntents, which is the value which was collected by this parameter.

[03:15] You can have operands. So in this case, it’s going to be greater than or equal to 100, and that just represents a large number. For me, it represents a large number of intents, and it’s going to say Dialogflow ES is better suited for large bots at the moment, okay?

And then you have this custom payload to start over if you want, okay? And then the page is again going to transition to await.help. And what if they chose a number which is less than 100, like I did? So it’s going to say, do you anticipate that your bot conversation will become more complex over time? So what it’s doing here is that it’s saying, okay, you don’t seem to have a lot of intents, but do you think that over time, your bot is going to get more complex, right? And then it’s going to go to this page called Get More Complex, and let’s take a quick look at what that page has.

[04:07] And if the user could say yes, and if they say yes, they say it says, I suggest using Dialogflow CX. But if the user says no, then it just says, okay, you can just use ES because you are saying that your bot is not going to have slot filling, it won’t have follow-up intents, you don’t expect it to have a lot of intents in the future also. So yeah, ES might be perfectly fine for a bot like that, okay?

That’s really what it’s saying. And if the user says no, yeah, sorry, I already went over this. And if the user says something which it didn’t quite understand, it’s going to once again reprompt with, sorry, I didn’t quite get that, please answer with just yes or no, okay? And it won’t do any transition as you might expect. Now, I just wanted to quickly show you one important thing over here. So remember that we collected a num intents parameter in the, let’s go back here, in the get num intents page, we collected this parameter called num intents, right?

[05:09] And let’s say that the user provided some information and we were able to go through this whole flow, we got to the end of it, the bot made a recommendation, the user wanted to start over. Now, the problem is since we are starting the conversation over, we still have the session parameter called num intents in the session, it’s still active, the num intents parameter is still active.

And what we want to do is we want to set that to null. So if the user were to say start over, it’s actually going to set this num intents to null so that if we were to go to that next, if we were to go to that page again, that is if the user were to go step by step and all the way to the num intents step, the old num intents is not going to override that value. So another way to put it is, let’s say you did not clear that value.

[06:04] What will actually happen is when it reaches this page, you see that this is this required parameter, but it’s still active in the session. So Dialogflow CX is going to think, hey, wait a minute, I already have this information. So I don’t have to collect it from the user now. And it just goes to one of these routes based on what the user entered the last time. The same condition route is going to fire this time also. And of course, that’s probably going to be very confusing.

If not for the user, definitely it will be confusing for you. So that’s the idea. If the user were to, if this route were to fire, you have to make sure that you reset this parameter and you have to do the same to all the session parameters that you are collecting. If you have a start over flow in your bot, the start over route has to clear all the parameters from the previous run of the conversation. So that brings this entire design of this agent that sort of like wraps up all I have over here.

[07:08] And if you notice, you can see that this is, I mean, just taking a quick look at it, this doesn’t look very complicated. And I think that one of the big features in Dialogflow CX is that you are able to design what is actually a fairly complex conversation flow in a very visual manner. And by using the state machines and the state transitions, you are able to have a lot of precise control over the conversation.

It’s a good trade-off. It’s a good trade-off in terms of allowing the user to veer off track slightly and also being able to specify pretty much everything that the user might say without having to put in too much effort, which is you needed to do that in ES because if you wanted to really cover everything the user said in Dialogflow ES, that was a much harder task.

[08:03] So that’s where CX comes into the picture. So like I said, this bot, you’ll be able to download this bot’s blog file and just add it into your Dialogflow CX as a project. And it’s possible I may have missed a detail or two while I went over this bot. You can just go and take a look at it and you can go and click on this test agent and interact with your bot and all that. And you can find out how this bot was built.

Again, remember that I’m not going to claim that this is going to handle every possible scenario, but I think that it will do a pretty decent job of like 80% of the cases. And if you think that there’s some way you can improve it, you can also go and make those refinements if you are interested. So that’s how I will handle exceptions in Dialogflow CX.

About this website

I created this website to provide training and tools for non-programmers who are building Dialogflow chatbots.

I have now changed my focus to Vertex AI Search, which I think is a natural evolution from chatbots.


BotFlo was previously called MiningBusinessData. That is why you see that watermark in many of my previous videos.

Leave a Reply