Kaight: AI-Powered Financial Planning Assistant
Inspiration
The idea for Kaight came from three main sources:
Personal Experience: I was using ChatGPT for my own financial and retirement planning. I wanted an AI that could act more like a dedicated financial planner—asking relevant questions, making reasonable assumptions when needed, and crafting truly personalized recommendations. I also wanted a tool I could periodically return to for monitoring my financial progress, as recommended by many experts.
Professional Need: My brother, an investment advisor, receives sporadic questions from clients about a wide range of financial matters. He needed a tool that could answer questions while being familiar with each client's specific financial background to provide accurate, personalized guidance.
Financial Education: I wanted to create a tool to help people develop financial literacy. Since everyone's financial situation is different, I knew the advice needed to be specific to be valuable. I thought this would be an engaging way for people to explore retirement planning and learn about saving and investing concepts in the context of their own finances.
What it does
Kaight is an AI financial planner web app with two key components:
AI Chatbot Interface: Users can create a comprehensive financial profile by entering information about their income, savings, investments, retirement goals, and other financial details. The AI then provides personalized financial advice incorporating this context.
Firms Feature: Financial advisors can create a firm, add other advisors and clients as members, and leverage the AI to analyze specific clients' financial situations. This feature bridges the gap between AI capabilities and human financial expertise.
Key technical features include:
- Financial profile forms for capturing detailed user information
- LangChain-based AI agent optimized for financial planning
- Math equation rendering via LaTeX for clear financial formulas
- Data visualization with Google Charts for retirement projections
- Secure handling of financial data with separate storage from personal information
How I Built the Project
Kaight was built in May 2024, building on my experience with previous AI chatbot projects. I started with a WordPress plugin architecture featuring a JavaScript UI and a Python LangChain API for processing messages.
As development progressed, I evolved the backend from a simple chain to a more sophisticated LangChain agent integrating tools like LangSmith. I implemented a split database architecture where user information and PII (Personally Identifiable Information) is stored in WordPress, while anonymous, encrypted financial data is stored in a Firestore database for enhanced security and compliance.
I enhanced the UI with several features to improve user experience:
- Markdown support for rich text formatting
- LaTeX integration for displaying financial equations clearly
- Google Charts for visualizing financial projections and scenarios
The API system prompts were designed to instruct the AI to return content with these formatting elements using special tokens that the chatbot JavaScript could extract and process appropriately.
The system also includes a "Firms" feature allowing financial advisors to create a firm, add other advisors and clients as members, and use the AI to provide personalized analysis for specific clients using their financial profiles.
Challenges I Ran Into
One significant challenge was implementing the LangChain Agent effectively. LangChain was undergoing substantial refactoring, making tutorials and documentation from just months earlier quickly obsolete. While getting a basic agent running was straightforward, I needed to modify the inputs to combine financial data with chat messages in a token-efficient way. I also wanted to implement token limits, which required modifying LangChain's highly abstracted agent classes.
I eventually solved this by using RunnableLambda to wrap the LangChain agent chain elements, allowing me to add my customizations without fighting the framework.
Another notable challenge involved consistent structured data output from earlier LLM models (circa early 2024). Many system features relied on mixing open text with structured JSON elements, which worked about 80% of the time—but that remaining 20% of malformed JSON was problematic. I implemented JavaScript filtering on the chatbot side and used creative system prompting to stress standards to the LLM. Fortunately, modern models are much better trained on structured data output, making this less of an issue today.
What I Learned
My initial implementation using simple LangChain chains quickly revealed limitations, particularly with mathematical calculations. Since LLMs don't perform actual math operations, the system would produce incorrect results for complex calculations like long-term savings projections based on savings rates, inflation, and investment returns.
I addressed this by switching to a LangChain agent architecture that integrated:
- A reasoning logic tool to formulate mathematical equations
- A calculator tool to process formulas accurately
- Knowledge expansion tools including Wikipedia search, DuckDuckGo search, and Yahoo! Finance News
This transformation fixed the mathematical accuracy issues and added valuable capabilities. However, I noticed that while retirement analyses were now mathematically correct, they lacked standardization. To solve this, I developed a custom retirement calculator that processes numerous user inputs (or makes reasonable assumptions via the LLM) and generates a time series of savings and income projections. These projections are then interpreted by the LLM to provide personalized recommendations based on robust data.
I also gained valuable experience in creating a hybrid system that leverages both the natural language capabilities of LLMs and the precision of traditional programming for handling mathematical operations and data processing.
Accomplishments That I'm Proud Of
Mathematical Accuracy: The system can perform complex financial calculations correctly, overcoming the limitations of traditional LLMs in mathematical operations.
Custom Retirement Calculator: The specialized tool analyzes numerous variables to create accurate retirement projections, making personalized financial planning accessible to everyone.
Adaptive AI Responses: The system can mix natural language with visualizations and structured data to make complex financial concepts more accessible and engaging. This enables the system to adapt its communication style—from formal equations to visual charts to plain language—depending on the user's preferences and the complexity of the financial concepts being explained.
Flexible Data Gathering: The hybrid form input system combines structured fields with free-form text inputs, complemented by an agent interviewing methodology in the system prompt that has proven to be a flexibile and robust approach to gathering vital context. This approach allows Kaight to intelligently make assumptions when data is missing, creating a system that works equally well for financial experts who can provide detailed information and novices who may only have basic knowledge of their finances. Everyone gets valuable insights regardless of their starting point.
Philosophy-Aligned Analysis: I designed Kaight to adapt its financial analysis approach based on a user's financial philosophy and values. Whether someone follows the FIRE (Financial Independence, Retire Early) movement, prefers conservative Bogleheads-style index investing, or is interested in cryptocurrency and alternative investments, the system can tailor its recommendations to align with these different financial worldviews while maintaining mathematical accuracy.
Firm Management System: The firms feature allows financial advisors to utilize AI to enhance their client relationships and service offerings, bridging the gap between AI technology and professional financial services.
Secure Architecture: The database structure keeps user identity separate from financial data, prioritizing security and privacy in an area where trust is essential.
What's Next for Kaight
Advanced Goal Planning: Expanding beyond retirement to encompass other financial goals like education funding, home buying, and estate planning.
Data Integration: Building connections to financial institutions to automatically import user data, reducing manual input and increasing accuracy.
Scenario Comparison: Developing tools to compare multiple financial scenarios side by side to help users make more informed decisions.
Expanded Visualization Tools: Adding more sophisticated charts and interactive elements to help users better understand complex financial concepts.
Built With
- firestore
- javascript
- langchain
- php
- python
- wordpress
Log in or sign up for Devpost to join the conversation.