A database copilot is a task-focused AI assistant for exploring databases, translating natural-language questions into SQL, checking queries, and explaining results. It acts as a partner for specialized database work rather than a general chatbot. section 13.1.2
A practical design sends database schema and user questions to the AI application instead of giving the model direct database access. The schema can be included in the system message, while system, user, and assistant roles guide the conversation. section 13.1.2
A safe query workflow separates the main tasks:
- Understand what information the user needs. section 13.1.3
- Generate SQL from the question and database schema. section 13.1.3
- Check syntax, performance concerns, validity, and security risks before execution. section 13.1.3
- Run validated queries and return the results; reject unsafe or invalid requests. section 13.1.3
Counting orders
For “How many orders were placed in 1996?”, get_sql_query can produce SELECT COUNT(*) AS order_count FROM orders WHERE YEAR(order_date) = 1996;. After examine_sql approves it, the database returns 152 orders. A request to delete all orders from 1996 should be rejected rather than executed. section 13.1.3
