This repository contains the code and data accompanying the paper "Chat Bankman-Fried: An Exploration of LLM Alignment in Finance"[1].
The paper presents a simulation environment with seven pressure variables designed to test the alignment of large language models (LLMs) in high-stakes financial scenarios. This repository includes the code to simulate these financial situations using several LLMs acting in the role of an agentic CEO.
The code and data have been tested on Linux systems using Python 3.11.
Download link: https://www.dropbox.com/scl/fi/dknzeueneaxhzl52m5f2e/sim_data.zip?rlkey=b13h7l1r3htfbzxfahw5xzcve&st=3qiwv04p&dl=0
The data should be placed into data/simulation_results/
To install the codebase, follow these steps:
- Clone the repository:
git clone [email protected]:bancaditalia/llm-alignment-finance-chat-bf
-
Install anaconda
-
Create a virtual environment using python 3.11
conda create -n ai_align python=3.11
conda activate ai_align
- Install the package running bash install-dev.sh
bash install-dev.sh
- Create a .env file to place on top of the repository, which should contains your API keys, as follows:
OPENAI_API_KEY=this_is_my_private_open_ai_key
ANTHROPIC_API_KEY=this_is_my_private_anthropic_key
...
Your repository structure should look like this:
.
├── .env
├── install-dev.sh
├── install.sh
├── notebooks
│ └── run_simulation.ipynb
├── requirements.txt
├── src
│ ├── analytics
│ ├── experiments
│ │ ├── utils.py
│ │ ├── runner.py
│ │ ├── exec_full_sim.py
│ │ └── exec_baseline.py
│ ├── simconfig
│ │ ├── base_config.py
│ │ ├── sim_env.yaml
│ │ ├── llm_system_prompt.txt
│ │ └── agent_prompts.json
│ ├── tests
│ │ └── sample_llm.json
│ ├── main.py
│ ├── setup.cfg
│ ├── setup.py
│ └── simulator
│ ├── agents.py
│ ├── core.py
│ ├── logging.py
│ └── utils.py
├── data
│ └── simulation_results/
└── README.md
First, be sure all configuration paths are correct in simconfig/base_config.py, so that your simulation env is setup correctly. The Jupyter notebook "run_simulation.ipynb" provides detailed instructions for customizing and running individual simulations, along with examples of outputs and results.
To run a single simulation, use the following command:
Usage: python src/main.py
This will generate three output files:
── simulation_results_llm.json
── simulation_results_logs.json
── simulation_results_prompts.json
To replicate the baseline experiments, use the following command:
Usage: python src/experiments/exec_baseline.py
To execute the full simulation with all pressure variables, run:
Usage: python src/experiments/exec_full_sim.py
-
Regular agent actions (triggered at each timestep) are defined in simconfig/sim_env.yaml along with environment properties.
-
Static prompts (potential user interactions with the CEO) are defined in simconfig/agent_prompts.json for each agent and action.
-
The LLM system prompt for the agent (CEO) is provided in config/llm_system_prompt.txt.
-
All file paths, pressure variables, and agent parameters are configured in config/base_config.py.
The list of authors (in alphabetical order) that contributed to this project:
Claudia Biancotti Banca d'Italia Email: [email protected] |
Carolina Camassa Banca d'Italia Email: [email protected] |
Andrea Coletta Banca d'Italia Email: [email protected] |
Oliver Giudice Banca d'Italia Email: [email protected] |
Aldo Glielmo Banca d'Italia Email: [email protected] |
[1] Claudia Biancotti, Carolina Camassa, Andrea Coletta, Oliver Giudice, Aldo Glielmo, "Chat Bankman-Fried: an Exploration of LLM Alignment in Finance", under submission.
This package is an outcome of a research project. All errors are those of the authors. All views expressed are personal views, not those of Bank of Italy.