Building an AI-powered fraud monitoring agent in 3 hours

Henry LeGard
Henry LeGard
CEO @ Verisoul

Feb 14, 2024

This is a guest post from Henry LeGard, CEO of Verisoul. Verisoul is an AI platform aimed at helping businesses grow faster by preventing fake accounts like duplicates, bots, spammers, and fraudsters.

Over 90% of VC-backed companies plan to allocate engineering resources towards building AI features and products this year. But developing custom AI solutions in-house can be difficult and time consuming. Developers can spend days building systems that lack sufficient data context, struggle to access real-time inputs, or risk privacy violations by sending data to external AI providers.

At Verisoul, we encounter these AI challenges firsthand, all the time.

Our AI models make predictions about whether an account is real, unique, and trusted; sometimes, customers ask why we flagged certain accounts as fake. Fielding these inquiries required our team to dig through various databases to find complete context—and could take upwards of 10 minutes per question.

To accelerate responses, I used Retool’s AI components to build a custom AI fraud monitoring agent (which we call a Fraud Analyst). We can now address common customer inquiries in seconds. It only took a day to build with the help of the Retool Docs and ChatGPT. Specifically, I used:

  • Retool AI Chat to enable a natural language interface for fielding customer questions.
  • Retool Vectors which is a managed vector database that allowed us to provide the AI chat tons of context about Verisoul’s fake user detection methodologies, field definitions, and documentation.
  • Retool data integrations so we could pull real-time data from the Verisoul database and APIs to enable dynamic investigations.
  • Retool JavaScript Transformers to build a privacy-preserving integration with OpenAI, stripping and obfuscating PII before sending data to them.
  • Retool Workflowsto build Slack monitoring and create feedback loops that continuously expand the Analyst’s capabilities.

In this article, I’ll explain exactly how I came away with an effective AI chatbot in just a few hours.

How Verisoul's AI fraud monitoring agent works

The Verisoul AI Fraud Analyst provides simple, real-time answers to customer questions about accounts and their risk profiles. When a question enters the Retool AI-powered chat interface, several steps occur programmatically behind the scenes:

  • Get real-time data: First, the system calls Verisoul’s API endpoints to pull current data about the account and its sessions. This includes fraud scores, flags, and other analytics.
  • Obfuscate PII: To preserve privacy, custom JavaScript transforms the output to remove or obscure any sensitive personal information in the API responses.
  • Combine inputs: The sanitized API data joins with the original user question and knowledge from our Retool Vectors database, which covers key details of Verisoul’s platform and how it works. This collective information gets passed to Retool’s AI chat component.
  • Respond: Leveraging Retool’s existing AI chat configuration and integration with OpenAI, the question and context data are analyzed to produce an accurate and specific response that includes actual data about the account and its sessions.
  • Display and monitor the answer: Finally, the Analyst displays the answer in the Verisoul dashboard for the user. Meanwhile, the question and response get sent to an internal Slack channel for monitoring so our can continuously refine and improve the Fraud Analyst's knowledge.

How we built it: Vector database

Time: 1 hour

Using Retool Vectors for a vector database provides critical context for AI chatbots. It allows users to embed information and context covering relevant topics and details for the chatbot to reference. In essence, the vector DB serves as a customizable knowledge base fueling more intelligent, specific, and quasi-trained AI.

When deciding how to set up a vector database to power our AI chatbot, we explored two primary approaches:

  • The “easy” way is quickly adding existing resources—like documents, Slack messages, API reference, etc.—without much organization. This is fast and reflects available materials, but lacks traceability and control. If I went this route, it would be harder for us to know what’s there and improve it later.
  • The “harder” (yet arguably more effective) way is manually compiling and structuring resources up front. This can take far more initial effort to build an organized knowledge base, but it enables traceability and certainty about what's fueling your AI.

I took the second approach for the Fraud Analyst's vector DB. I manually compiled the most relevant fraud detection resources and organized them clearly into pages and definitions tables, then uploaded them as PDFs. Additionally, I used the Retool URL scraper to scrape our documentation. This process added to my own mental model of our internal organization, language, and capabilities.

Sample of what our Retool Vector database list looks like—well organized and clear
Sample of what our Retool Vector database list looks like—well organized and clear

The hour it took to synthesize our internal knowledge into a simple set of documents and tables was well worth it. I can now easily maintain and expand our knowledge base to improve the Analyst. Some key insights I had through the process:

  • Garbage in = garbage out. Quality resources drive quality output.
  • Traceability is critical for continuously enhancing the analyst’s knowledge base over time.
  • The up-front effort of structuring everything approximates the best version of your internal and personal knowledge, whereas an unstructured version is far murkier. (Analogously, there’s a reason writers go through dozens of versions of edits to get to the final product!)
Garbage in = garbage out. Quality resources drive quality output.

How we built it: Real-time data queries

Time: 15 minutes

What we used: Retool API integrations, Retool database integrations, ChatGPT

Retrieving current fraud analytics data is vital for our AI Fraud Analyst to provide accurate, timely responses. Using Retool’s REST API connector and BigQuery integration, I built data pipelines to call Verisoul’s APIs and databases during a chat interaction. I gave ChatGPT the context on what I needed to query for and what database tables we have; it wrote the queries for me.

This real-time data includes essential summary metrics and aggregate fraud scores tied to the related account and sessions. I optimized the queries and API requests to return only critical high-level data—keeping response sizes under control for speed and cost savings.

Sample API query that variably calls the endpoint with the account the user asks about
Sample API query that variably calls the endpoint with the account the user asks about

Configuring these real-time data flows only took 15 minutes, as I used Retool’s pre-built components. The data flows enable the AI Fraud Analyst to serve situationally aware responses drawing from the latest fraud analytics data.

Two key tips:

  • Limit the database queries and API responses to prevent overloading your AI Chat input token count
  • Use aggregate queries to feed summary data without requiring many rows

How we built it: Privacy-preserving JS transforms

Time: 20 minutes

What we used: Retool JS Transform component, ChatGPT

When handling sensitive customer data, it’s critical to protect privacy before sending information to third-party AI services like OpenAI. The Verisoul APIs returned account details containing PII like emails, IDs, IP addresses, and device IDs.

To obscure this information, I used ChatGPT to generate hash functions for data transformation. In 30 minutes, I had JavaScript that could intake API responses and obfuscate all PII into encrypted strings.

I told the Analyst that privacy protocols required such encoding of personal details. This set appropriate expectations for why account IDs, emails, etc. would have an obfuscated format.

The hash functions clone API payload objects, check for account IDs, emails, or other PII, and produce scrambled versions of those fields. For example:

1```
2const crypto = require(’crypto');
3
4// Define your secret key
5const secretKey = 'your_secret_key'; // Replace with your actual secret key
6
7// Define a secure hash function using HMAC with SHA-256
8const secureHash = s => {
9    return crypto.createHmac('sha256', secretKey).update(s).digest('hex');
10};
11
12// Function to obfuscate the payload
13function obfuscatePayload(payload) {
14    // Clone the payload to avoid mutating the original object
15    let obfuscatedPayload = JSON.parse(JSON.stringify(payload));
16
17    // Check if the account object exists and has an id
18    if (obfuscatedPayload.account && obfuscatedPayload.account.id) {
19        // Obfuscate the account id
20        obfuscatedPayload.account.id = `obfuscated_${secureHash(obfuscatedPayload.account.id)}`;
21    }
22
23    // Check if the account object exists and has an email
24    if (obfuscatedPayload.account && obfuscatedPayload.account.email) {
25        // Obfuscate the email within the account object
26        obfuscatedPayload.account.email = `obfuscated_${secureHash(obfuscatedPayload.account.email)}`;
27    }
28
29    // Check if the root email object exists and has an email field
30    if (obfuscatedPayload.email && obfuscatedPayload.email.email) {
31        // Obfuscate the email at the root level
32        obfuscatedPayload.email.email = `obfuscated_${secureHash(obfuscatedPayload.email.email)}`;
33    }
34
35    return obfuscatedPayload;
36}
37
38// Reference the payload from the API dynamically
39let apiPayload = {account: {
40    id: '123456789',
41    email: 'john@gmail.com'
42    }};
43
44// Run the obfuscation function on the payload from the API
45let obfuscatedPayload = obfuscatePayload(apiPayload);
46
47console.log(obfuscatedPayload);
48```

With PII protected, I could pass API data securely to Retool’s AI Chat to enable confidential fraud investigations. The Analyst can now leverage real customer information without exposing sensitive details. See below for an example of an obfuscated output:

1Original email: john@gmail.com  
2Obfuscated: obfuscated_3948103948012398

How we built it: Slack monitoring

Time: 20 Minutes

What we used: Retool Workflows, ChatGPT, Slack integration

To continuously improve the AI Fraud Analyst, I set up real-time Slack notifications showing every question and response. (This part took only 10 minutes in Retool!)

I configured a Retool Workflow to receive chat data, format it, and post interactions to a dedicated Slack channel. Then I selected that workflow as the Webhook destination within the Analyst’s settings.

Now after every question, the team and I can see the inputs, API data, and answers directly in Slack. This lets us monitor performance and quickly identify any issues.

The vector DB’s organized knowledge base has been invaluable here. With full traceability, I can easily tweak the content powering the Analyst when I spot inaccuracies or bad responses in Slack.

This monitoring and rapid iteration is making the AI Fraud Analyst smarter everyday. And by enabling direct customer feedback channels, we can confirm the tool is providing genuine value through timely, personalized investigation.

Setting up Slack monitoring in two steps

1. Build a Retool Workflow (outside of the analyst app) that connects a trigger to a JS code block, to a Slack block. Here is a sample of ours:

This code block simply formats the response we get from the Retool AI Fraud Analyst and readies it to send to Slack in a readable way.

1function jsonToSlackMarkdown(data) {
2    // Create an array to hold each line of the Slack markdown
3    const markdownLines = Object.entries(data).map(([key, value]) => {
4        // Check if the current key is 'Answer' to apply bold formatting
5        if (key === 'Answer') {
6            return `*${key.replace(/([A-Z])/g, ' $1').replace(/^./, str => str.toUpperCase())}:* *${value}*`;
7        } else {
8            return `*${key.replace(/([A-Z])/g, ' $1').replace(/^./, str => str.toUpperCase())}:* ${value}`;
9        }
10    });
11
12    // Join the lines with a newline character
13    return markdownLines.join('\\n');
14}
15
16// Convert JSON to Slack markdown
17return jsonToSlackMarkdown(startTrigger.data);

2. Create a Retool Workflow Resource in your Retool application and connect it to the workflow you just created.

Putting it all together: Retool-powered AI chat

Time: 30 Minutes

What we used: Retool AI chat

The last step was to compile everything in the Retool AI chat component to bring your superpowered AI chatbot to life. Start by adding this component to your application.

1. Select the Action type

For this, we used the generate chat response action type. Retool has several other options, like image generation, classification, etc.

2. Add the input prompt and message history

Here’s how I added the JS variables to the Retool chat AI component Input. Note that these are pulling from our transformed, privacy-preserving outputs.

1Question: {{ Verisoul_AI_Chat.lastMessage }}
2
3__________
4Data
5
6Account: 
7{{api_privacy_get_account_investigate.value}}
8
9Sessions: 
10{{privacy_get_sessions_investigate.value}}
11
12Accounts Linked: 
13{{accounts_linked_privacy.value.accounts_linked}}

Here’s what we included for message history. (We grabbed direct guidance from the Retool Docs.)

1{{ Verisoul_AI_Chat.messageHistory }}

3. Select the vectors

To enable vector context in the Retool Chat component, check the box and select the vectors you want to include.

4. Configure the model and system parameters

  • Choose which model you want to use. (We’re using the standard OpenAI GPT-4 integration.)
  • Draft the System Prompt. Here, we’ve explained its role, an overview of the data it has received in the Chat Input above, and its goal.

5. Connect the Slack Workflow

Write an event handler to trigger your Slack Workflow on success of the chat completion.

Closing thoughts

In just 3 hours, I was able to combine Retool’s versatile pre-built components with an AI tool like GPT-4. The result was an effective intelligent chatbot that can also be further modified or customized as needed in the future.

This solution has transformed our customer support operations. We can now handle fraud investigations that previously took 10–15 tedious minutes per case almost instantly. The AI Fraud Analyst saves my team significant time while delivering customers quicker, more personalized explanations.

In Verisoul’s experience, Retool’s AI tool suites and pre-built components can make it simple for any company to unlock conversational interfaces. Just as we did, you can prototype and iterate new solutions in a matter of hours. I hope this inspires you to automate manual workloads and build customized AI assistants tailored to your business needs.

Henry LeGard
Henry LeGard
CEO @ Verisoul
Feb 14, 2024
Copied