What to Include in an LLM Prompt for a Chat App That Talks to a Database?

I’m building a chat app that generates SQL queries over a structured DB . What information should I include in the system prompt so the LLM can reliably query the database? I’m already thinking of schema, sample tables, PK/FK, and key columns. What else would you recommend (e.g., domain rules, constraints, ontology, security guidelines, etc.)?

To get consistent SQL generation from an LLM, the system prompt should define not just the schema but also the rules of interaction with your database. In addition to tables, PK/FK, and example rows, it helps to include domain constraints (valid ranges, business logic), naming conventions, and any semantic rules that govern how entities relate. If your app requires guardrails, specify strict security guidelines: which tables are read-only, which columns are off-limits, and whether the model must avoid UPDATE/DELETE entirely. Finally, define ontology or domain definitions so the model understands how natural-language concepts map to your columns — this improves reliability more than anything else.

If you want, you can share your current prompt and I can help refine it.