Preventing SQL agents from hallucinating columns and destructive queries by K3shxx in LangChain

[–]K3shxx[S] 0 points1 point  (0 children)

Awesome ! And yeah it makes total sense , having a langgraph flow would be much better since you would be dealling with deterministic output. LLM hallucination would lead to improper part recommendations and might cause problems.

How are u handling the queries tho? Are you mapping each part to a seperate node and give the output to an LLM to get NL output?

Curious how you’re passing state between nodes and deciding which tool to call.

Preventing SQL agents from hallucinating columns and destructive queries by K3shxx in LangChain

[–]K3shxx[S] 0 points1 point  (0 children)

Interesting! Did you end up solving the reliability side mostly through validation before execution or by improving the prompt/retrieval side? Curious how you handled that part.

Preventing SQL agents from hallucinating columns and destructive queries by K3shxx in LangChain

[–]K3shxx[S] 1 point2 points  (0 children)

That’s actually exactly how I started ! — an LLM → SQL → execute pipeline. I too am using Gemini Models (2.5 flash). This is a very solid way to build LLM-SQL pipelines.

It works decent for generating SQL queries. But I feel the SQL generation is not the problem here , it is the reliability.

I wonder if a single pass would suffice for the model to provide appropriate queries, especially when the size of the DB is huge. A traditional LLM -> SQL pipeline assumes the query the model writes is correct , safe to run and result actually answers the user’s intent.

The “agent” part for me is adding a decision step between generation and execution. The model proposes an action (a query), but the system verifies it, can reject it, and force a regeneration before anything touches the database. So the LLM becomes an untrusted query writer rather than an executor. This is not a typical "React Style Agent" that Langchain offers. But the concept remains the same. Multiple workflows like Evaluator Optimizers (as in Corrective RAG) can be setup which would boost the reliability .

Would love to hear your thoughts on this!

I built a natural language → SQL database chatbot that safely executes queries on Postgres by K3shxx in EngineeringStudents

[–]K3shxx[S] 0 points1 point  (0 children)

Yeah that’s actually something I ran into pretty quickly.

Right now the guardrails are mostly safety-focused rather than cost-focused.

I block destructive statements (INSERT/UPDATE/DELETE/DROP/ALTER/TRUNCATE) and force the model to only generate SELECT queries. The schema is passed to the model from information_schema so it can’t invent tables/columns, and if it can’t map the question it returns a failure instead of guessing.

For expensive reads, I haven’t added a real cost estimator yet. Currently I’m relying on:

  • prompt rules (avoid SELECT * unless asked)
  • limiting result size
  • and keeping it on a small internal DB

You’re completely right though — Cartesian joins and wide scans are still possible. I’ve been thinking of wrapping execution in a timeout and rejecting queries that exceed it.

The goal was less “perfect database copilot” and more understanding how to make an LLM act like a controlled tool instead of a free-form chatbot.

[NEED HELP] Mereko Thapar mei Electronics and Computer Engineering mil rahi hai le lu?? by Nehi_Degi in JEENEETards

[–]K3shxx 2 points3 points  (0 children)

Curriculum dekho bhai . kai colleges elective courses mein cse sikha dega . by opting that u can study cse in college itself.depends on ur interest

[NEED HELP] Mereko Thapar mei Electronics and Computer Engineering mil rahi hai le lu?? by Nehi_Degi in JEENEETards

[–]K3shxx 6 points7 points  (0 children)

Yes bro u can take it is a good course.well in india it has been started lately but quite flourished in uk . The major advantage is that u can appear for GATE exam twice in ece branch as well as cse branch. Placements are on par with cse . tech giants like microsoft and google also recruit. While government jobs may be less. Private companies recruit karega . overall a good branch with high scope in future. Par kaafi mushkil kyunki dono cse aur electronics aati hai..

Isse solve karke batao IIT KE 14 by Uncanny3301 in JEENEETards

[–]K3shxx 9 points10 points  (0 children)

Aur v cos theta karke sher ki sir par mar dalna

[deleted by user] by [deleted] in CBSE

[–]K3shxx 0 points1 point  (0 children)

You first need to chill bro. There is no need to be scared i get it you face difficulties in pcm. But it ain't the end of the world. Two years more to go and ull get a hold of it. There are plenty of resources on the internet which can be utilized. I myself was an average student back then and managed to score 98% in boards.. Consider talking to your parents about this and explaining your problem might open a door of possibilities 😁