Use text-to-SQL (or an API) for questions with exact answers like counts, sums and filters: give the model the schema with descriptions and examples, use a read-only role, validate the query (SELECT only, row limits, timeouts), execute it, and have the LLM explain the result.
Use semantic retrieval over text columns or documentation for descriptive questions, and combine both when a question mixes them.
Risks: wrong joins and invented columns, so validate against the schema, retry with the error message, and evaluate on question-to-SQL pairs; never let embeddings answer an aggregation question.
Loading…