Probably by parsing the SQL string suggested by the model before executing.
For Python, I think we could use https://github.com/tobymao/sqlglot
For R, we may want to wrap something like https://github.com/apache/datafusion-sqlparser-rs (into an optional dependency?)
Additional context https://claude.ai/share/929cdd9d-3ec0-4245-9a4a-b24066356cea