AI generated wrong SQL
A query can execute successfully and still answer the wrong question; check its meaning as well as its syntax.
Symptoms
Section titled “Symptoms”Execution can produce database errors such as:
column does not existrelation does not existOther signs include unexpected totals, duplicate rows, missing records, or names from a different database.
Quick checks when AI generated wrong SQL
Section titled “Quick checks when AI generated wrong SQL”- Confirm the active connection and database.
- Compare the SQL with the actual table and column names.
- Check the join keys, filters, date boundaries, and expected result columns.
- Keep proposed writes under review until the result is understood.
If the provider returned no usable answer, use AI key or model problems.
The answer uses the wrong schema or dialect
Section titled “The answer uses the wrong schema or dialect”Open Context Options from the chat’s three-dot menu. Enable Database Schema for table questions and SQL Editor Content when correcting the current query.
Check that the editor contains only SQL relevant to the request. Review what AI sees before including database context.
Grid Ask AI uses the current tab’s context and omits chat history. Include the complete correction in a grid request, even if you already discussed it in chat.
The question leaves a business rule unclear
Section titled “The question leaves a business rule unclear”Specify the rule that the answer missed. For example:
Count each customer once if they placed a completed order during October 2026, using the order timestamp in UTC. Exclude cancelled orders.
Explain which columns define completion, dates, and customer identity when their meaning is unclear. Ask the table owner about business definitions before supplying a correction.
For a request checklist, see better AI results.
Correct the answer and verify it
Section titled “Correct the answer and verify it”State the incorrect assumption and provide the intended rule. If execution failed, include the database message after removing private values.
Review the revised SQL, then check a read query against a small, known example. Compare which records should appear, rather than only checking the row count. A local or Docker test database is useful for synthetic examples.
Use write and run SQL to execute reviewed statements. Guardrails protect execution; they do not verify business meaning. The database agent can gather read-only evidence when a question needs database checks.
Still stuck
Section titled “Still stuck”Prepare a sample schema, question, expected result, and actual result for a support report. Use synthetic names and rows that reproduce the error without exposing private data.