Developers ask an AI assistant to write a query for last month's sales by region using a one-line prompt. Each time, the assistant returns different table names, a different definition of last month and sometimes nonstandard SQL. Which change best improves the consistency of the results?
Select an answer to reveal the explanation.
Short Explanation
A vague question gets you a vague answer, from people and from AI. Give the assistant the table names, tell it what "last month" means and that you want standard SQL, and show it one good example. Rolling the dice until a query returns rows isn't consistency; it's luck.
Full Explanation
Prompt engineering is the practice of structuring instructions and context so that a generative model produces accurate, consistent output. For SQL generation, effective prompts include the relevant schema, such as table and column names, keys and data types, explicit constraints, such as the SQL standard or dialect to target, the exact definition of business terms like last month, and the expected output columns, plus one or more examples of correct queries. Giving the model this context narrows the range of plausible completions, which reduces both variation and hallucinated objects. Repeating a short prompt and running whichever query returns rows confuses returning rows with being correct; a query can return rows while using the wrong table or date range, and this approach adds risk rather than consistency. Retraining the model on sales data is costly, slow and unnecessary for this problem, and it would not teach the model the current schema as reliably as supplying it in the prompt; retrieval or context injection is the usual approach. Removing the date requirement makes the query less useful and does not address the missing schema context that causes the variation. Exam caveat: even well-engineered prompts do not guarantee correctness, so generated SQL still requires validation and human review. Operational check: run the improved prompt several times, compare the generated queries, and confirm each produces the same totals as a hand-written reference query.