A database schema describes how data is organized. For a SQL database, table definitions give a query writer the table names, column names, and data types it needs. For a graph database, the useful description instead lists node labels, relationship types, and properties. When asking a language model to turn a question into a query, provide this structure alongside the question and the target query language. section 5.2.4 section 5.4.5
Describe a table before asking for SQL
Suppose you want to ask questions about video-game sales. A prompt can begin with the games table’s CREATE TABLE statement, which names columns such as platform, genre, and globalsales. Follow it with an instruction to translate a question into SQL, then insert the question. The same template works for different questions as long as the database structure stays the same. section 5.2.4
Database: #1 CREATE TABLE games(rank int, name text, platform text, year int, genre text, publisher text, americasales numeric, eusales numeric, japansales numeric, othersales numeric, globalsales numeric); Translate this question into SQL query: #2 [Question] #3
This prompt places the table definition before the translation instruction and question, so the model can use the actual column names. section 5.2.4
Hardcoding a schema is convenient for one database, but an interface for arbitrary SQLite databases needs to discover the current structure. SQLite’s automatically created sqlite_master table stores SQL statements used to create database objects. Retrieve its table-creation statements and join them into a description for the prompt; Python’s sqlite3 module can perform this step. A reusable prompt function then accepts that description and the user’s question as separate inputs. section 5.3.2 section 5.3.3
import sqlite3
def get_structure(data_path):
with sqlite3.connect(data_path) as connection: #1
cursor = connection.cursor() #2
cursor.execute("select sql from sqlite_master where type =
'table';") #3
table_rows = cursor.fetchall() #4
table_ddls = [r[0] for r in table_rows] #5
return '\n'.join(table_ddls) #6
The Python function connects to a SQLite file, fetches its table definitions, and returns them as prompt-ready text. section 5.3.2
For a Neo4j movie database, a corresponding prompt names node labels such as Movie and Person, relationship types such as ACTED_IN, and relevant property keys before requesting a Cypher query. Replace that description when changing databases. Whether the target is SQL or Cypher, treat the generated query as a proposal: it may be incorrect or fail to execute. Copy the database before running generated queries. section 5.4.5 section 5.5











































