Problem
Q4 Inc., a capital markets platform, wanted a chatbot where Investor Relations Officers ask questions about ownership records, transactions and stock quotes. The data is mostly numbers and dates, and answers had to be accurate and arrive in seconds. Pre-training was too costly, fine-tuning hallucinated, and conventional RAG (search, semantic search, embeddings) retrieved wrong rows because embeddings of numbers rank similarity badly.
Example from the article: a proof of concept on an ownership dataset: assets owned over time and transactions between institutions, individuals and public companies.
Solution in brief
The LLM turns the question into SQL, with the table schema, a few sample rows and short field explanations in the prompt. The query runs on the database, and a cheaper LLM call summarizes the returned rows. Each step uses the smallest accurate model, and the SQL validation step was dropped once the SQL proved reliable.
Questions this case answers
- How to retrieve exact context for an LLM answer from numerical, time-series tables where embedding similarity ranks numbers poorly
- How to choose the smallest model per step of a multi-call LLM pipeline without losing answer accuracy under a latency budget
- How to answer numerical questions over financial tables when vector search returns the wrong rows?
- How to make an LLM write correct SQL for a table it has never seen?
Tools and methods
- Text-to-SQL — replaces vector search as the retrieval step
- Amazon Bedrock — one API to several LLMs; swap a model by changing its name
- LangChain SQLDatabaseChain — builds the prompt from schema and sample rows, runs the query
- Claude V2 / Claude Instant — SQL generation (V2 for complex questions) and summaries
- Prompt engineering — human/assistant format, XML tags, explicit "say you cannot help" instruction
Google or a one-time email code. No password.