DEV Community

Cover image for Day 80: Stop letting your AI hallucinate on dirty data (Fintech Edge-cases)
Eric Rodríguez
Eric Rodríguez

Posted on

Day 80: Stop letting your AI hallucinate on dirty data (Fintech Edge-cases)

When you build AI-powered applications, the most important code you write has nothing to do with AI. It has to do with data sanitization.

Today, my Serverless Financial Agent was aggressively lecturing me for spending 500€. The catch? I didn't spend it. I transferred it between my own multi-currency accounts using Wise.

The Problem:
My backend was blindly feeding raw transaction arrays to Amazon Bedrock. The LLM saw a -500€ transaction and did exactly what I prompted it to do: it roasted me for bad financial habits. If your context window is fed garbage, the output will be garbage.

The Fix:
I had to build a deterministic sanitization layer before the LLM ever sees the data. I wrote a strict filter in the frontend to handle business logic mapping.

const INTERNAL_TRANSFER_RE = /^to (eur|usd|gbp|chf|pln|ron|huf|czk|sek|nok|dkk)\b/;

const isInternalTransfer = (tx) => {
const desc = String(tx.description || '').trim().toLowerCase();
return tx.is_internal === true || desc === 'balance' || INTERNAL_TRANSFER_RE.test(desc);
};

By explicitly flagging internal transfers and edge cases like intrst (Interest Payments), I prevented them from being grouped into the totalExpenses array.

Alongside this, I shipped two new UI components: Velocity Analysis and a Savings Streak calculator. Now, the React app mathematically proves to the user exactly why they are hitting their daily goal, comparing their dailyIncome against their todayExpenses.

The Golden Rule:
Do not use GenAI for deterministic math or data cleaning. Clean the data with code, calculate the limits with math, and use the LLM solely to explain the clean results to the user.

Top comments (0)