How to handle profanity inputs in Dialogflow ES

I got this question from a student:

I need your help in one of the logic. How to handle profanity inputs in the dialogflow es in the best way. Can you suggest some best approaches.

Here is one way to do it.

Declare an entity with a list of profane words. I will use some fairly mild words for this example.

Create an intent to handle the profane input.

The key is to use the wildcard entity to create training phrases to handle any word/phrase appearing before and after the profane term.

The training phrase below handles random input before the profane word

Handle any word or phrase after the profane term:

Handle profane word alone:

Handle random phrase before and after the profane word:

Add a suitable response message:

Now test it:

This will usually handle all the profane words that you have already listed in the entity, but it will miss the ones which you did not add to the list.

Occasionally, you might also run into false positives where the user inputs a single profane word as part of a genuine intent.

About this website

BotFlo1 was created by Aravind Mohanoor as a website which provided training and tools for non-programmers who were2 building Dialogflow chatbots.

This website has now expanded into other topics in Natural Language Processing, including the recent Large Language Models (GPT etc.) with a special focus on helping non-programmers identify and use the right tool for their specific NLP task.

1 BotFlo was previously called MiningBusinessData. That is why you see that name in many videos

2 And still are building Dialogflow chatbots. Dialogflow ES first evolved into Dialogflow CX, and Dialogflow CX itself evolved to add Generative AI features in mid-2023