VOOZH about

URL: https://www.geeksforgeeks.org/artificial-intelligence/fraud-detection-using-crewai/

⇱ Fraud Detection Using CrewAI - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Fraud Detection Using CrewAI

Last Updated : 14 Apr, 2026

Fraud detection in finance requires analyzing large volumes of transactions and identifying anomalies. Here we will create a fraud detection project using CrewAI that analyzes financial transactions, identifies suspicious patterns, and generates a structured fraud report.

We will be using “Synthetic Financial Datasets For Fraud Detection” dataset which can be downloaded from Kaggle.

Setting Up the Environment

Before we start, we need to install CrewAI and set up the necessary tools:

!pip install crewai
!pip install crewai_tools

We also set our OpenAI API key if external LLMs are required:

1. Importing Required Libraries

First, we import the necessary libraries to define agents, tasks, crews and tools for reading files.

  • Agent: Defines an AI agent that performs tasks.
  • Task: Defines the tasks assigned to agents.
  • Crew: Groups agents and tasks for coordinated execution.
  • FileReadTool: A tool to read CSV datasets.

2. Defining Agents

Next, we define the agents that will work on this project. Each agent has a role, goal, backstory and optionally tools.

2.1 Data Collector

This agent is responsible for reading the dataset and summarizing it.

  • role: Defines what the agent does (e.g "Data Collector").
  • goal: The outcome the agent works toward (e.g., "Load and profile the dataset").
  • backstory: Context or skills that describe the agent's abilities.
  • tools: List of tools the agent can use like FileReadTool for reading CSV files.
  • verbose: When True, the agent explains its reasoning step-by-step.
  • reasoning: Enables the agent to use logical reasoning for its decisions.
  • memory: Allows the agent to retain context during task execution.

2.2 Pattern Recognizer

This agent analyzes the dataset to detect suspicious transactions, such as high-value amounts and abnormal types like TRANSFER and CASH_OUT.

2.3 Fraud Reporter

This agent prepares a professional summary report based on the findings from the previous agents.

3. Assigning Tasks

We now define the tasks that each agent will perform. Each task includes a description, the agent responsible, and the expected output.

3.1 Load Task

This task instructs the Data Collector to read the dataset in batches and summarize it, highlighting any anomalies.

  • description: Detailed instructions of what the task involves.
  • agent: The agent assigned to complete this task.
  • expected_output: What the task should produce when completed.

3.2 Detect Task

This task instructs the Pattern Recognizer to identify anomalies, providing row indices and explanations.

3.3 Report Task

This task instructs the Fraud Reporter to prepare a structured report summarizing findings and recommendations.

4. Creating the Crew

Now, we group all agents and tasks into a Crew. The Crew coordinates the execution sequence to ensure the workflow is orderly and systematic.

  • agents: List of all agents working in the Crew.
  • tasks: List of tasks to be executed by the agents.
  • verbose: If True, provides detailed explanations of each agent's reasoning.
  • planning: If True, the Crew manages the workflow planning.
  • process: Execution mode (Process.sequential or Process.parallel).

5. Executing the Workflow

Finally, we launch the Crew to run all tasks. The result will include the dataset profile, detected anomalies and a structured fraud report.

  • crew.kickoff(): Starts the execution of the crew, runs all tasks in the defined order and returns the final result.

Output:

The output contains:

  • A dataset profile including the total row count, column names, data types, missing values and sample records from the file.
  • A list of suspicious transactions flagged, showing row indices, transaction types, amounts and balance inconsistencies.
  • A structured fraud detection report with an executive summary, detailed findings and actionable recommendations.

You can download source code from here.

Comment

Explore