An LLM agent that answers financial data questions in SQL

Role
AI Engineer Intern, LLM Systems
Company and dates
Capital Fund Management (CFM), hedge fund, Paris. Mar to Sep 2025
Stack
LangGraph, GPT-4.1, GPT-4.1-nano, o4-mini, Oracle, ChromaDB, Redis, LangSmith, Pydantic, Streamlit, FastAPI
Output
Agent built for the data referential team; internship report

Results

On a 48-question benchmark I designed with gold SQL, the agent answered 87.5% correctly, up from 83% without examples. Table retrieval reached 95% top-k with hybrid search. Giving each task a suitable model cut the cost per query about 20× compared with o3, at similar accuracy.

End-to-end accuracy, 48 questions
Without examples83%
With validated question–SQL examples, kept separate from the benchmark87.5%
Cost per query, at similar accuracy
o3 on the whole task€5
The agent, a suitable model per task€0.24

Approximate figures.

The problem

The data referential team needed answers from an internal Oracle financial database without writing SQL, in English, French or Spanish. The evaluation subset alone has 30 core tables; the full database is larger, so the agent first has to find the right tables.

What I did

  • Built a LangGraph agent with 7 tools: o4-mini plans the steps, GPT-4.1 writes the SQL and judges answers, GPT-4.1-nano filters context.
  • Designed the 48-question benchmark with gold SQL from about 12 starter questions, and scored runs with an LLM judge.
  • Built table retrieval with BM25 and ChromaDB embeddings, merged with reciprocal rank fusion, plus a Redis lookup tool for financial product names.
  • Added validated question–SQL examples to the model's context, from a set kept separate from the benchmark questions.
  • Built the Streamlit interface and part of the FastAPI backend; traced and evaluated runs in LangSmith and validated outputs with Pydantic.

Results

Accuracy rose from 83% to 87.5% on the benchmark, table retrieval reached 95% top-k, and giving each task a suitable model cut the cost per query about 20 times compared with o3, at similar accuracy.

The code and final architecture belong to CFM. The internship report, approved for sharing, has more detail on the method.