In this code pattern, we will create a chatbot to help insurance agents process claims. We will use Watson's natural language processing capabilities, to understand, classify, and retrieve information to reduce repetitive tasks for the insurance agent. In turn, this will free the agent to tackle more creative, and complex problems, and the majority of customers will receive answers to their questions faster, with the help of a Watson-based virtual assistant.
When you have completed this code pattern, you will understand how to:
- Process complex insurance documents with Watson Discovery to efficiently answer customer policy questions.
- Use Watson Knowledge Studio to create custom models and entities to understand and classify mechanic reviews more accurately.
- Create a web-based application which features a virtual assistant that can answer policy questions and make recommendations based on which mechanics are highly reviewed, and covered by the policy.
- Insurance policy documents are uploaded to Watson Discovery, and then annotated using Watson's Smart Document Understanding tool.
- Mechanic review documents are uploaded to Watson Knowledge Studio, and then annotated to create custom entities and relationships.
- User chats via web-application UI to talk to Watson Assistant.
- Watson Assistant answers policy questions using Watson Discovery's querying capabilities.
- The chatbot recommends a mechanic based on the type of damage that is done to the vehicle, and on the sentiment of the customer reviews.
For a fully functional virtual insurance assistant, please complete the following tutorials first:
- Tutorial: Process, understand, and answer policy questions with smart document understanding
- Tutorial: Build a recommendation engine with Watson Natural Language Understanding
The resulting trained Discovery collection will be used for policy inquiries. The deployed model from Knowledge Studio and the Natural Language Understanding service will be used to understand claim descriptions.
- Clone the repo
- Gather credentials for the mechanic recommender
- Gather credentials for policy inquiries
- Create the Watson Assistant skill
- Deploy the application
- Use the app
git clone https://github.com/IBM/virtual-insurance-assistant
Note: A WKS+NLU model is required for this section. If you have not yet done the tutorial and need a quicker way to generate your model read this.
When you completed the Tutorial: Build a recommendation engine with Watson Natural Language Understanding, you deployed a machine learning model to a Watson Natural Language Understanding service to allow it to analyze mechanic reviews. We've used the same process to create a mechanic ranking by repair type (based on sentiment analysis).
Now, we'll configure the virtual insurance assistant to use the same model and service. This will allow it to understand an insurance claim and recommend the best mechanics for the type of repair needed.
Collect the API key
and URL
by navigating to your Natural Language Understanding instance in the IBM Cloud console.
Then, navigate to your Watson Knowledge Studio instance, select your workspace, click "Machine Learning Model", and then select "Versions" Copy the Model ID of your latest deployed version.
These will be used later in Deploy the application. For example, in a local .env
file:
# NLU for mechanic recommender
NATURAL_LANGUAGE_UNDERSTANDING_APIKEY=<add_nlu_apikey>
NATURAL_LANGUAGE_UNDERSTANDING_URL=<add_nlu_url>
NATURAL_LANGUAGE_UNDERSTANDING_MODEL_ID=<add_nlu_wks_model>
When you completed the Tutorial: Process, understand, and answer policy questions with smart document understanding, you trained Watson Discovery to understand a collection of insurance policy documents. We will use this Discovery service to allow the virtual insurance assistant to answer policy questions.
Note: If you have an
Advanced Plan
instance of Discovery and need a quicker way to reproduce the results of the tutorial read this.
There are two ways to integrate Discovery with the virtual insurance assistant. The preferred way is to use a "search skill". If you will use a search skill you can SKIP AHEAD to the next section Create the Watson Assistant skill.
If you are NOT using the search skill, our Node.js server will take the context returned from Watson Assistant and use the SDK to query Watson Discovery directly. This is handy if you are using a Discovery Lite plan, or if you have other reasons to manipulate the results in code. This method, however, will not work in the Watson Assistant preview or WebChat UI.
To enable policy inquires without the search skill, use the following instructions to gather credentials and configuration for the server's runtime environment.
- Take the API key and URL from your
cloud.ibm.com
Discovery service, as shown below:
- Next, click
Launch Watson Discovery
and then click on theapi
tab in the top-right corner of the screen within Watson Discovery as shown below:
- Go ahead and grab the
collection ID
andenvironment ID
from that tab.
These will be used later in Deploy the application. For example, in a local .env
file:
# Watson Discovery (if not using the search skill)
DISCOVERY_APIKEY=<add_discovery_apikey>
DISCOVERY_URL=<add_discovery_url>
DISCOVERY_ENVIRONMENT_ID=<add_discovery_environment_id>
DISCOVERY_COLLECTION_ID=<add_discovery_collection_id>
- Click here to find Watson Assistant in the IBM Cloud catalog.
Select a location
.Select a pricing plan
. SelectTrial
.- Set your
Service name
or use the generated one. - Click
Create
.
- Click on
Launch Watson Assistant
. - Click the
Assistants
icon in the left sidebar and then clickCreate assistant
. - Give your assistant a unique name then click
Create assistant
.
Import the virtual insurance assistant skill from a JSON file in your cloned repo. From your Assistant panel:
- Click on
Add dialog skill
. - Click the
Upload skill
tab. - Click
Drag and drop file here or click to select a file
, go to your cloned repo dir, andOpen
the JSON file indata/assistant/skill-virtual-insurance-assistant.json
. - Click the
Upload
button.
The newly created dialog skill should now be shown in your Assistant panel:
An Assistant search skill is a mechanism that allows you to directly query a Watson Discovery collection from your Assistant dialog. A search skill is triggered when the dialog reaches a node that has a search skill enabled. The user query is then passed to the Watson Discovery collection via the search skill, and the results are returned to the dialog for display to the user.
Click here for more information about the Watson Assistant search skill.
Adding a search skill is optional. Our Node.js server can instead take the context returned from Watson Assistant and use the SDK to query Watson Discovery directly, but using a search skill is preferred because it allows full use of the Assistant preview and WebChat UI.
From your Assistant panel:
- Click on
Add search skill
. - Give your search skill a unique name, then click
Continue
. - From the search skill panel, select the Discovery service instance and collection you created previously.
- Click
Next
to continue. - From the
Configure result content
panel, selecttext
as the field to use for theBody
of the response. - Under
Adjust result quantity
set the quantity to 1. - Click
Create
to complete the configuration. - From your Assistant panel, click on the three dots in the upper right-hand corner and select
Assistant settings
. - Select the
Search Skill
tab and ensure that is inEnabled
.
Now, when the dialog skill node invokes the search skill, the search skill will query the Discovery collection and display the text from the policy document to the user.
Normally, you can test the dialog skill be selecting the Try it
button located at the top right side of the dialog skill panel, but when integrated with a search skill, a different method of testing must be used.
- Under
Integrations
, clickIntegrate web chat
. - Give your web chat a name and click the
Create
button. - Use the
Web chat
panel to customize your web chat integration. - Click
Close
.
From the Assistant panel, you can test the dialog with the search skill by using the Preview
button. Note that the input "Does my insurance cover glass repairs?" will trigger our search skill.
You will need your Assistant credentials to set in the runtime environment of the application.
From your Assistant panel:
- Click on the three dots in the upper right-hand corner and select
Assistant settings
. - Select
API details
in the sidebar. - Copy the following values to use in the application deployment step:
- Assistant ID
- Assistant URL
- API key
- These will be used later in Deploy the application. For example, in a local
.env
file:
# Watson Assistant
ASSISTANT_ID=<add_assistant_id>
ASSISTANT_URL=<add_assistant_url>
ASSISTANT_APIKEY=<add_assistant_apikey>
Note: Since you integrated Assistant with Discovery via a search skill, you won't have to configure Discovery credentials when you deploy the application.
Click on one of the options below for instructions on deploying the Node.js server.
![]() |
![]() |
![]() |
![]() |
Browse to the app URL (for local deployment use http://localhost:8080).
Below, you can see the web-application in action, querying Watson in natural language:
- Does my insurance cover glass repairs?
- Does my coverage include medical expenses?
- Does my insurance cover damage to my vehicle
- Does my insurance coverage apply for injury to me?
- Does my insurance cover the cost of my personal belongings damaged in an accident?
- Does my coverage apply to legal costs?
- What happens if I get in an accident with an uninsured motorist?
-
No Watson Assistant. Please configure the runtime environment and restart the server.
The chatbot will say this if you run it without configuring an Assistant APIKEY, URL and ID. Follow the deployment instructions to provide the .env settings or runtime environment.
-
Sorry, currently I do not have a response. Discovery is not configured.
The chatbot will say this if you try a policy inquiry, but the search skill was not created. It is trying to call the Discovery service via the SDK, but finds the DISCOVERY_ environment variables were not set. Follow the deployment instructions to provide the .env settings or runtime environment (or add a search skill).
-
BadRequest - "dialog skill" is trying to invoke missing "search skill" for the given agent
This error indicates that your assistant does not have search skill.
-
NLU service not configured. Unable to determine repair type. Is NLU configured?
This error indicates that your assistant is trying to use NLU to determine the type of repair needed, but either NLU is not configured or it could not recognize a known repair type. Follow the deployment instructions to provide the .env settings or runtime environment for NLU. If you did not configure NLU the server output will say "NLU service not configured".
-
Unable to determine repair type. Is NLU configured?
See above. This is the same error message, but NLU is configured. This happens if either the NATURAL_LANGUAGE_UNDERSTANDING_MODEL_ID is not configured or not trained properly. It can also happen if you describe an accident that does not include a repair type that it is trained to recognize.
This code pattern is licensed under the Apache License, Version 2. Separate third-party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 and the Apache License, Version 2.