Building an agentic Text-to-SQL pipeline for financial data. Is this architecture good?

Reddit r/AI_Agents News

Summary

A developer is building an agentic Text-to-SQL pipeline for querying financial databases and seeks community feedback on the architecture's robustness, security, and performance.

Hey everyone, I'm building a Text-to-SQL chatbot so users can ask natural language questions against a company's financial database. I want to make sure this workflow is robust and not over-engineered. Here is my current step-by-step pipeline: Classifier: A fast, cheap LLM rewrites the user's question and extracts entities. Cache: Checks if this exact question was answered before. If yes, return the answer. If no, proceed. Schema Lookup: Checks if it needs more context, then pulls the exact table structures/DDL needed. Business Rules: Injects custom company definitions (e.g., how "premium tier" is calculated) into the prompt. SQL Generation: A heavy LLM (like GPT-4o) takes all that context and writes the SQL query. Security Check: A Python script scans the SQL for malicious injections or drops. Execution & Auto-Fix: Runs the query in MySQL. If MySQL throws a syntax error, the agent catches the error and asks the LLM to fix it automatically. Final Grader: A fast LLM checks the final data to ensure it actually answers the user's original question. Return: Send the data to the user (or kick to a human reviewer if it failed). My questions for the community: Is this a solid architecture for financial data, or is there a better/standard way to do this? Is relying on a Python script for security (Step 6) a bad idea? Will running this many LLM nodes sequentially cause massive latency issues? Are there better architectures out there for this specific use case? Would love any feedback or advice on how to optimize this!
Original Article

Similar Articles

Building data agents

Reddit r/AI_Agents

Discusses the evolution from text-to-SQL to autonomous data agents, comparing custom-built agents using LangGraph with managed platforms like Snowflake Cortex Analyst, Databricks Genie, and PowerBI Copilot.