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

> Retained reddit record from reddit:AI_Agents.

Canonical: https://highsignal.app/data/records/c060bcac6d4c3db4

[← sources](https://highsignal.app/data)


source: [reddit](https://highsignal.app/data/reddit) (reddit:AI_Agents)  published 2026-09-28 15:21 ingested 2026-09-29 02:36

[original source ↗](https://www.reddit.com/r/AI_Agents/comments/1wshhxr/building_an_agentic_texttosql_pipeline_for/)

## retained text



```
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:

1. **Classifier:** A fast, cheap LLM rewrites the user's question and extracts entities.
2. **Cache:** Checks if this exact question was answered before. If yes, return the answer. If no, proceed.
3. **Schema Lookup:** Checks if it needs more context, then pulls the exact table structures/DDL needed.
4. **Business Rules:** Injects custom company definitions (e.g., how "premium tier" is calculated) into the prompt.
5. **SQL Generation:** A heavy LLM (like GPT-4o) takes all that context and writes the SQL query.
6. **Security Check:** A Python script scans the SQL for malicious injections or drops.
7. **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.
8. **Final Grader:** A fast LLM checks the final data to ensure it actually answers the user's original question.
9. **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!
```



document fetched 2026-09-29 00:19 · canonical https://reddit.com/r/AI_Agents/comments/1wshhxr/building_an_agentic_texttosql_pipeline_for
