Include schema

Column names + types + relationships. Just relevant tables (routing via classifier). Table + column descriptions if available.

Advertisement

Hints from FKs + values

'orders.user_id joins users.id.' 'status ∈ {pending, shipped, cancelled}.' Reduces hallucination.

Advertisement

Chain: intent → SQL → verify

1. Understand intent (rephrase). 2. Generate SQL. 3. Explain query in plain English. 4. Check explain matches intent.

Execute + retry on error

Run query. On SQL error: feed error back, retry. On empty result: check filter conditions with user.