Part 4: Introducing Rasa to Insurance Claim Chatbot

Building a Chatbot for Insurance Claims Processing

The point of this series is to review various approaches for building a Chatbot that is capable of interacting with a user to capture claim information. In this first few articles, we built the bot using hard-coded lookups and definitions, which didn't allow the user to use natural language. Instead, we had to rely on the user making exact choices with their input, and if they did not follow the instructions, they would have to repeat the same questions.

Insurance chatbot using AI image from mantralabsglobal.com

To help with the natural language issue, where the difference between answering a question requesting your name with "my name is Robert Dundas" and just "Robert Dundas" could result in failure of the program to complete, we are going to use a natural language processor called Rasa. Using Rasa, we will be able to use a model to help pair different words with their meanings.

Now we are getting into a bit of the heavy lifting for the Chatbot. We are going to introduce the Chatbot to Rasa, "...an open source machine learning framework for building contextual AI assistants and chatbots." The purpose here is to accept natural language in the Chat session and use the AI engine to make decisions as to what to present to the user next, until enough of a "story" is understood for the program to actually make a decision. For this Chatbot, we want the insurer to interact with the Chatbot to tell the story of the accident, and for the Chatbot AI to ask questions until all of the pertinent details are captured.

For this step, we need to install Rasa:

pip install rasa-x --extra-index-url https://pypi.rasa.com/simple

Next, we need to initialize a new Rasa project:

rasa init --no-prompt

You should get something like the following: Chatbot 4: Rasa Shell

This step will create a project in your directory and set up a first dialog for the Chatbot. You can run the "rasa shell" as directed to test the installation and the model.

Chatbot 4: Rasa Shell

Great! We now have our first working Chatbot and it installed in around 30 seconds!!! It makes the last three articles seem like a complete waste of time and effort. There are two main parts installed: 1) a natural language dictionary, which assigns phrases to categories and 2) a story, which carries the user from prompt to prompt. These two dictionaries are brought together in the file domain.yml.

Let's modify domain.yml to interact with the claimant. The chatbot should greet the user, ask how it can help and then ask for the user's full name.

So, our first change is to modify the greeting to ask how the chatbot can help you:

templates:
  utter_greet:
  - text: "Greetings. How can I help you?"

Then, we run the 'rasa train' command to get our new greeting into the model: Chatbot 4: Rasa Shell

Perfect! Our new greeting is getting displayed. Now, there are a LOT of approaches that we can take here, but let's stay simple. Let's assume that the user is going to use the word "claim" to start a new claim. We will build this out to test whether they want to check on the status of a claim or start a new claim, but for now, let's just write an "intent" for starting a new claim:

First, we want to create a new story in story.md:

## new claim path
* greet
  - utter_greet
* claim_new
  - utter_help_with_that

Next, we need to "register" that story in domain.yml as an "intent" (this is a user 'intention'):

intents:
  - greet
  - goodbye
  - affirm
  - deny
  - mood_great
  - mood_unhappy
  - claim_new

Next, we add the claim_new to the natural language markdown file. Basically, we are going to say that if it has the word "claim" in the user's intent, then we are going to assume that the user wishes to start a new claim.

## intent:claim_new
- claim

Now we want the Chatbot to respond with something indicating that it understood what the user wanted and will respond accordingly. This is done by defining a new action "utterance" and registering the new action in the domain.yml:

utter_help_with_that:
  - text: "OK. I can help you with that."

Lastly, we need to register that utterance with the domain actions:

actions:
- utter_greet
- utter_cheer_up
- utter_did_that_help
- utter_happy
- utter_goodbye
- utter_help_with_that

That should be it. Now we run the "rasa train" command to incorporate our changes into the model and run the shell to test our changes:

Chatbot 4: Rasa Shell

Great! Now, let's add the dialog to ask the user for their full name (as in the last article). Let's modify the action utterance so that it reads "OK. I can help you with that. Let's start with your full name so that we can look up your policy." For now, we are going to assume that the next response from the user will be their name so that we can look up their policy. Once we integrate this with our Python module, we can add a lookup function and respond with an appropriate found or not found message, but we are keeping it simple for now. So, once the user sends the name, we'll respond with the above response.

OK, so I am one day later and I have just now enabled Rasa to work with the simple dialogue that I wanted. Essentially, I wanted to capture the user's name, the date of the incident and the details. But, configuring Rasa to do this took a bit extra. In the end, I ran the shell in interactive mode and used the generated stories to get exactly what I wanted, as I couldn't configure the story to behave the way I wanted by my configuration. In the end, I came up with the following:

My nlu.md:

## intent:greet
- hi
- hello
- greetings

## intent:claim_new
- submit a new claim
- new claim
- had an accident
- was an incident

## intent:give_name
- my name is [Rob](name) [Dundas](name)
- [Rob](name) [Dundas](name)

## intent:give_policy
- my policy number is [12345](policy)
- my policy is [12345](policy)

## intent:incident_date
- it happened on [March](month) [24](day), [2019](year)
- on [06](month)/[31](day)/[2019](year)
- it happened last [Thursday](dayofweek)
- I hit a car on [Monday](dayofweek)

## intent:incident_details
- I hit the front gate
- ran into a pole

## intent:goodbye
- bye
- goodbye
- adios
- later

stories.md:

## Generated Story 6894901440031185296
* greet
    - utter_greet
* claim_new
    - utter_help_with_that
* give_name{"name": "Dundas"}
    - utter_policy_lookup
* incident_date{"year": "2019"}
    - rewind
* incident_date{"month": "May", "day": "25", "year": "2019"}
    - utter_incident_details
* incident_details
    - utter_goodbye

My domain.yml:


actions:
- utter_goodbye
- utter_greet
- utter_help_with_that
- utter_policy_lookup
- utter_incident_details
entities:
- name
- day
- date
intents:
- greet
- claim_new
- give_name
- give_policy
- incident_date
- incident_details

templates: utter_goodbye: - text: Thank you. That is all we need for now. We will contact you if there are more questions. Goodbye. utter_greet: - text: Greetings. How can I help you? utter_help_with_that: - text: OK. I can help you with that. Let's start with your full name so that we can look up your policy. utter_policy_lookup: - text: Thank you. First, I need to know when the accident occurred. utter_incident_details: - text: Describe what happened in the incident.

And finally, after quite a few "rasa train" attempts, I get the following:

Chatbot 4: Rasa Shell

The concept has been proven. In the next step, we need to connect the Chatbot session to some structured data and interact with it using information. For example, we want to actually look up the policy, check whether the policy was in effect during the time of the incident and then save the details as a new claim.