An AI assistant produces a plausible SELECT query, and the result grid fills with numbers. Neither the syntax nor the presence of results proves that the query answers the business question. A wrong join can multiply rows while producing totals that still look credible.
Begin with a small, sanitised test dataset and credentials restricted to the required data. Where supported, use a read-only transaction as an additional control. PostgreSQL’s transaction documentation describes what its read-only mode restricts; it is not a general promise that every permitted query is cheap, private or semantically correct.
Make a result you can calculate yourself
Suppose the question asks for order totals by customer. Build a tiny example with two customers, one order containing several lines and one customer with no orders. Calculate the expected answer manually before running the generated query.
Then inspect the join keys, grouping and treatment of missing values. Does joining order headers to line items duplicate a header-level amount? Does an inner join silently remove the customer with no orders? Does a date filter use the intended time zone and boundary?
These questions test the meaning of the query. A successful execution tests only that the database accepted the statement and could return a result.
Keep the review boundary intact
- Inspect every statement, not only the first visible SELECT.
- Allow only the tables, columns and functions actually required.
- Set appropriate time and resource limits for the test environment.
- Review the execution plan before considering a large dataset.
- Keep sensitive production records out of prompts and test exports.
Read-only permissions do not prevent an authorised read from exposing information to the wrong recipient. Nor do they guarantee that a large cross join will be harmless to performance. Access, confidentiality, cost and correctness require separate checks.
Promote the query through the team’s normal review process only after the expected results and access requirements are understood. Treat generated SQL as an unreviewed contribution: useful for drafting, but still accountable to the same evidence as code written by a person.

