🎉 Seed RoundWe've raised 2.5M from Swift, YC, & Chapter One. Read more

Learning - 2023-11-16

Automating Data Processing for Insurance Fee Disclosure

by Pablo Rios

A chariot of data analysis

A chariot of data analysis

Large Language Models (LLMs) can interpret, process, and act on data in ways that closely mimic tasks performed by humans. These powerful capabilities allow organizations to save countless hours, significantly increasing efficiency and reducing employee workloads.

To demonstrate this, we'll walk you through how Metal's data processing abilities can extract precise information from insurance policy fee disclosures. We'll then show you how to create a simple workflow to automate this process using multiple function calling capabilities from OpenAI. Let’s dive in!

Case study: Automating Insurance Data Processing

In our example, we’ll use the fee disclosure document for a car insurance policy. From this document, we’ll extract:

  • Geographical Coverage
  • Commission to the Insurance Intermediary
  • Renewal period

Setting Up Your Data Source: Specifying Metadata

First, go to your Metal dashboard to create a new data source and define the metadata fields for extraction. After you define your data source and upload a file, Metal will then process your document, showing the extracted fields in the data source UI.

Extracted Metadata

Extracted Metadata

Integrating Parallel Function Calling with OpenAI

Having extracted the relevant data using Metal, the next step is to automate further processing through OpenAI's parallel function calling capability. This process involves creating functions that interact with our extracted data to perform specific tasks. In our example, we’ll pull user data, calculate fee commissions, and determine the policy renewal period.

Here's an example script showing how this can be done:

from openai import OpenAI
import json
client = OpenAI()
# Dummy functions for our insurance use case
def pull_users_from_database(country):
"""Pull users from the database based on country"""
# [Your database interaction code goes here]
return json.dumps({"country": country, "users": "dummy_user_data"})
def calculate_commission(commission_statement):
"""Calculate the sum of commission fees"""
# [Your commission calculation code goes here]
return json.dumps({"commission_statement": commission_statement, "total_commission": "dummy_commission"})
def calculate_renewal_period(duration_statement):
"""Provide the count in days for the time left for renewal"""
# [Your renewal period calculation code goes here]
return json.dumps({"duration_statement": duration_statement, "days_left": "dummy_days_left"})
# Fetch the extracted meta data from the get_data_entity() from Metal Python SDK
metal_response = metal.get_data_entity("data_entity_id")
def run_workflow():
# Extract required information from the metal_response
geographical_coverage = next(item for item in metal_response["data"]["extractedMetadata"] if item["_name"] == "geographical_coverage")["value"]
commission_statement = next(item for item in metal_response["data"]["extractedMetadata"] if item["_name"] == "commission")["value"]
duration_statement = next(item for item in metal_response["data"]["extractedMetadata"] if item["_name"] == "duration_of_policy")["value"]
# Define the workflow with the model
messages = [{"role": "user", "content": "Extract and process insurance data"}]
tools = [
{"type": "function", "function": {"name": "pull_users_from_database", "description": "Pull user data", "parameters": {"type": "object", "properties": {"country": {"type": "string"}}, "required": ["country"]}},
{"type": "function", "function": {"name": "calculate_commission", "description": "Calculate commission fees", "parameters": {"type": "object", "properties": {"commission_statement": {"type": "string"}}, "required": ["commission_statement"]}},
{"type": "function", "function": {"name": "calculate_renewal_period", "description": "Calculate renewal period", "parameters": {"type": "object", "properties": {"duration_statement": {"type": "string"}}, "required": ["duration_statement"]}},
# Call the OpenAI model
response = client.chat.completions.create(
# Process the response and function calls
response_message = response.choices[0].message
tool_calls = response_message.tool_calls
# Check if the model wanted to call a function
if tool_calls:
available_functions = {
"pull_users_from_database": pull_users_from_database,
"calculate_commission": calculate_commission,
"calculate_renewal_period": calculate_renewal_period,
messages.append(response_message) # Extend conversation with assistant's reply
# Process each function call and response
for tool_call in tool_calls:
function_name = tool_call.function.name
function_to_call = available_functions[function_name]
# Use the extracted data as arguments for the function
if function_name == "pull_users_from_database":
function_args = {"country": geographical_coverage}
elif function_name == "calculate_commission":
function_args = {"commission_statement": commission_statement}
elif function_name == "calculate_renewal_period":
function_args = {"duration_statement": duration_statement}
function_response = function_to_call(**function_args)
"tool_call_id": tool_call.id,
"role": "tool",
"name": function_name,
"content": function_response,
}) # Extend conversation with function response
# Get a new response from the model with the function response
second_response = client.chat.completions.create(
return second_response

In this script, our three dummy functions simulate how we can pull data from Metal and use it to do three things: find users by location, calculate commission fees, and figure out insurance renewal periods. The run_workflow() function orchestrates these operations using OpenAI's parallel function calling feature, providing an efficient way to automate these tasks based on the extracted data.

Wrapping Up

Integrating LLMs like OpenAI into business operations, especially when combined with tools like Metal, can significantly streamline workflows and increase productivity. This approach not only reduces manual effort but also opens doors to more advanced, AI-driven business solutions. 

At Metal, we know these workflows are only the beginning and we’d love to help build your own. Interested in learning more or trying these methods yourself? Contact our team and let's start your journey today 🤘