Unlocking the Power of GPT-4 for Automated Financial Analysis with Silverfin

Explore the integration of GPT-4 with Silverfin to revolutionize financial analysis and accounting. Learn to harness GPT-4 API for enhanced insights and automation within the Silverfin platform.

Unlocking the Power of GPT-4 for Automated Financial Analysis with Silverfin
Welcome to the next generation AI, thanks to Silverfin AI Labs (SAIL).


Hello dear readers, and welcome to another exciting exploration of cutting-edge AI technology! We're thrilled to have you join us as we delve into the world of GPT-4 and its incredible applications in the finance and accounting industries.


GPT-4, or Generative Pre-trained Transformer 4, is the latest iteration of OpenAI's state-of-the-art natural language processing (NLP) model. Building on the success of its predecessors, GPT-4 takes NLP to new heights by leveraging a massive amount of data, more parameters, and more sophisticated training techniques. The result is a highly advanced AI model capable of generating human-like text and understanding context, making it ideal for a wide range of applications.

In the world of finance and accounting, GPT-4 has the potential to revolutionize many processes, including financial analysis, report generation, and decision-making. By harnessing the power of GPT-4, businesses and accountants can gain valuable insights, automate manual tasks, and focus on providing strategic advice.

In this article, we will explore how GPT-4 can be utilized for automated financial analysis through its integration with Silverfin. We will cover the process of getting started with the GPT-4 API, understanding its endpoints and methods, and making API calls using Python. Additionally, we will discuss the design objectives, prompt engineering techniques, and the practical application of GPT-4 within the Silverfin platform. By the end of this article, you'll have a better understanding of how GPT-4 can revolutionize the finance and accounting industries and how you can leverage this powerful AI model to enhance your own projects and applications.

Getting Started with the GPT-4 API

The announcement regarding the launch of GPT-4 can be found at https://openai.com/research/gpt-4.

Signing up for GPT-4 API Beta access

To access the GPT-4 API, you'll need to sign up for the waiting list. Visit the OpenAI dashboard at https://platform.openai.com/ and navigate to the "Join API waitlist" section and follow the instructions to join the waiting list.

Creating an account and obtaining API keys

Once you've been granted access to the GPT-4 API, you'll need to create an account with OpenAI. After registering and logging in, navigate to the API keys page to generate your own unique API key, which is required to make requests to the GPT-4 API.

Understanding the API Endpoints and Methods

GPT-4 API endpoint

The chat completions API endpoint allows you to interact with GPT-4 and utilize its capabilities for various tasks. To use this feature, send a POST request to https://api.openai.com/v1/chat/completions with the required parameters like model, messages, role, and content of the message. This post call will return a model response for the given chat conversation.

Customizing API calls with parameters

To control the behavior of GPT-4 and tailor its output to your needs, you can use various parameters in your API calls, such as model, messages, temperature, max_tokens, and many more. For more information about the parameters and options available for the Chat Completions API, take a look at the detailed documentation at OpenAI API Reference - Chat Create. This comprehensive guide will help you understand and utilize the various parameters effectively to customize your chatbot's behavior and responses.


An example request using curl can be made to create a chat completion with the GPT-4 model and a simple user message saying "Hello!".

curl https://api.openai.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "gpt-4",
    "messages": [{"role": "user", "content": "Hello!"}]

The response will contain the assistant's message, along with other details like created timestamp, usage, and tokens used.

  "id": "chatcmpl-123",
  "object": "chat.completion",
  "created": 1677652288,
  "choices": [{
    "index": 0,
    "message": {
      "role": "assistant",
      "content": "\n\nHello there, how may I assist you today?",
    "finish_reason": "stop"
  "usage": {
    "prompt_tokens": 9,
    "completion_tokens": 12,
    "total_tokens": 21

Making API Calls to GPT-4 Using Python

With a good understanding of the GPT-4 API endpoint and parameters, let's move forward and learn how to integrate GPT-4 into your Python applications. In the following section, we will showcase a practical example of making API calls using Python to generate chat completions. This hands-on approach will help you get a better grasp of using GPT-4 effectively in your projects and harness its power to create intelligent and engaging chatbot responses.

Setting up Your Development Environment

Before you can start making API calls, you’ll need to set up your development environment. You can use any programming language such as Python, JavaScript, or Ruby. For this guide, we’ll assume you’re using Python.

First, ensure that you have Python installed on your system. If you don’t already have it, you can download the latest version from the Python website.

Next, create a new directory for your GPT-4 API project and navigate to it in your terminal or command prompt. We recommend using a virtual environment to keep your project dependencies organized. To create a virtual environment, run the following command:

python -m venv gpt4_project

Activate the virtual environment by running the appropriate command for your operating system:

source gpt4_project/bin/activate  # macOS/Linux

Installing Required Libraries and Dependencies

Now that your development environment is set up, you’ll need to install some libraries to interact with the GPT-4 API. For Python, we’ll use the openai Python library. If you don’t have it, it can be installed via the following command using the pip package manager of Python:

pip install openai

With your account, development environment, and dependencies in place, you’re now ready to start making API calls and unlock the power of GPT-4!

Start by importing the required libraries:

import openai

Once imported, let’s provide our API key.

openai.api_key = "OPENAI_API_KEY"

Obviously, you'll want to replace "OPENAI_API_KEY" with your actual OpenAI API key.

Now, we’ll define a function that allows us to interact with GPT-4. In this specific example, we set the model to "gpt-4", the temperature to 0.7, and we specify the system message, which serves as a crucial tool for establishing the model's behavior prior to initiating a conversation. We provide one possible argument representing the question asked to the system called prompt.

def ask_your_accountant(prompt):
    result = openai.ChatCompletion.create(
            {"role": "system", "content": "Assistant is an accounting expert working at Silverfin."},
            {"role": "user", "content": prompt}
    return result

Call the function above with the specific prompt "Tell a joke!".

output = ask_your_accountant("Tell a joke!")

When printing the generated output, we get the following answer based on our question:


> Why did the accountant become a gardener?
> Because he found he had a natural talent for "growing" assets!

We made a funny accountant! Isn't that special?

The ask_your_accountant function will send the messages to the GPT-4 API and return the assistant's response. In this example, the response will be a joke provided by the funniest automated AI accountant.

Now you can see that by modifying the list of messages and customizing the optional parameters, you can interact with the GPT-4 API for a wide range of applications, such as generating text, answering questions, or engaging in interactive conversations.

Integrating GPT-4 into Silverfin

GPT-4 has been integrated into Silverfin as a proof-of-concept to demonstrate its potential in automating financial analysis. The primary goal was to generate accurate and useful financial advice based on the provided information while minimizing the need for manual intervention. To achieve this, we focused on specific design objectives and prompt engineering techniques to enhance the generated output.

Design Objectives and Prompt Engineering

Design objectives played a crucial role in guiding the development of the GPT-4 integration in creating an effective automated financial analysis application. The objectives included ensuring that the generated advice was:

  1. Actionable: The advice should provide clear, instruction-based recommendations that accountants and their clients can implement to improve their financial performance.
  2. Concise: The advice should be presented in a maximum of five bullet point topics, making it easy to understand and digest for both accountants and their clients.
  3. Language-flexible: The application should be able to generate advice in multiple languages, including English, Dutch, and French, catering to a diverse user base.
  4. Informative: Each bullet point should contain financial reasoning and financial values, providing context for the advice and enabling users to make informed decisions.
  5. Comprehensive: The advice should conclude with a summary of the company's current financial situation, offering a complete understanding of their financial health for both accountants and their clients.

These design objectives set hard constraints on the output, enabling a more efficient evaluation of the generated advice and ensuring its alignment with user requirements and expectations.

Prompt engineering is essential for obtaining accurate and useful results from GPT-4. Well-designed prompts guide the model's behavior, ensuring that the generated output meets the desired design objectives and reduces manual intervention. To address the challenges in designing effective prompts for financial analysis, we implemented a specialist-in-the-loop approach, involving accounting specialists actively participating in the prompt engineering process. We also strongly focused on the role-level instructions provided by the ChatGPT API to guide the LLM's behavior throughout the conversation by composing the prompt in two parts (as seen in the Python coding example): the system role prompt and the user role prompt.

The system message prompt serves as a crucial tool for establishing the model’s behavior prior to initiating a conversation. The inclusion of the specific design objectives within the system message played a pivotal role in steering our model toward the desired direction, along with the incorporation of a language-specific rule mandating the system to respond exclusively in Dutch, French, or English.

The system message prompt.

The user message prompt includes the financial statement data that has been converted into a textual format. Rule-based comments were integrated to enhance accuracy, and financial ratios were organized by importance to ensure the model focuses on the most significant ones. A rule-based approach was also implemented to exclude irrelevant financial ratios, leading to improved accuracy, relevance, and overall efficacy of the LLM.

The user message prompt.

Application Overview

To use the new feature, accountants need access to the Silverfin platform. After logging in and selecting a client file, a banner with "We are exploring what GPT could do for your client files" and a "Prepare financial analysis" button appears. Clicking the button spawns a modal where a set of action points are generated within an editable text field. Accountants can modify the advice and post it as a note in the client file's communication pane, which facilitates the efficient sharing of information with other users within the accounting firm.

In summary, this demo demonstrates the capabilities of our cutting-edge GPT-4 based system in automating financial analysis for businesses and accountants. By leveraging large language models our solution generates actionable advice from financial ratios, making them more accessible and easier to interpret. This innovative approach streamlines decision-making processes, improves communication within accounting firms, and ultimately transforms the financial performance evaluation process for all parties involved. This novel system helps accountants increase their efficiency and effectiveness in analyzing and advising clients on their financial performance.


Our novel GPT-4-based application for automated financial analysis demonstrates the potential of LLMs in specialized fields like finance and accounting. By making use of specific design objectives and prompt engineering, we have developed a concise, language-flexible, and informative solution. As LLMs continue to evolve and improve, their applications in finance, accounting, and other industries will only grow more extensive.

🎉 We're delighted to announce that a paper detailing our exploration into the application of GPT-4 for automated financial analysis has been accepted for the demo track at the ECML-PKDD 2023 in Turin. Be sure to stay tuned, as a link to the open-access version of the paper will be provided in the future. This will allow you to explore our findings in further depth and contribute to the exciting conversation around AI and its applications in finance and accounting. 🎉

About the author: Sander Noels is a Ph.D. researcher and a data scientist at Silverfin, where he's part of the innovative AI team. He was recently appointed as the Research Coordinator within this team, further enhancing their work in the AI realm.