Urgent.News

What's breaking now, across thousands of outlets.

AI

Text-to-SQL in Practice: When to Trust AI Output and When to Gate It

AI assistants are now a normal part of SQL work. You describe what you need, get a query back in seconds and move on. The problem is not that these queries fail. Most of the time, they run perfectly. The problem is that a query can run perfectly and still be wrong. This post covers why that happens, how to sort database tasks by risk and how to build guardrails into a normal workflow. Adoption is…

Text-to-SQL is becoming a common part of SQL work, where you describe what you need and get a query back quickly. However, the problem is not that these queries fail, as most run perfectly. The issue is that a query can run perfectly and still be wrong. This article explains why that happens, how to categorize database tasks by risk, and how to build guardrails into a normal workflow.

Of the Stack Overflow 2025 Developer Survey, 84% of developers use or plan to use AI tools, but 46% distrust AI output accuracy compared to 33% who trust it. 66% cited "almost right, but not quite" answers as their top frustration. This scenario describes text-to-SQL well, where the output looks correct, compiles, and executes, but whether it answers the right question is another matter.

An example of this is a silent join query that counts order lines instead of orders, inflating the results. When reviewing generated SQL, focus on schema misinterpretation, silent logic errors, governance gaps, and context collapse. These four failure modes are categories for most AI-generated SQL bugs. To address these, sort tasks by risk and build a risk-tiered workflow.

Low-risk tasks include exploratory queries in dev or drafting documentation, while high-risk tasks require gatekeeping. Guardrails can be integrated into an existing pipeline by validating reporting queries against a baseline, running AI changes through CI/CD, enforcing the same permissions, tagging AI-assisted changes, and reviewing joins and aggregations first.

AI assistants are fast at producing SQL, but they lack the ability to determine if the SQL aligns with business meaning. Treat AI output like a pull request from a new team member: useful, often right, and always reviewed when it matters.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in AI

Optimal liability for offensive and defensive AI

How much liability should AI providers bear when their services enable both attack and defence? Liability can improve welfare while increasing harm.

  • Liability for AI services is complex, balancing offense and defense.
  • Overly strict liability weakens defense and boosts attacker profits.
  • High liability can lead to universal guarding in pure equilibrium.

More from Wednesday 23 September →