Find answers from the community

Updated last year

Can you promt the

At a glance

The community member is asking if the SQLTableRetrieverQueryEngine can be prompted to always return the date range of the queried documents, as the current response only returns the data when a time is asked for. The community member provides examples of the current prompt and responses, which show that the date range is included in the SQL response and summarized in the final response.

In the comments, another community member suggests appending the query with " and present the time range you queried (if any)." The original community member responds that they will try this approach.

There is no explicitly marked answer in the post or comments.

Can you promt the SQLTableRetrieverQueryEngine to always return the date range of the queried documents? The response returns the data only when a time is asked for. This is the current prompt I am using.

Plain Text
DEFAULT_RESPONSE_SYNTHESIS_PROMPT_TMPL = (
    "Given the input question and the associated SQL query results from the 'snapshots' table, "
    "synthesize a coherent response. Always ensure that you retrieve and present the date range linked "
    "to the documents in the query. The format of the date can be flexible, but it must be unmistakably evident "
    "that it represents a date range.\n"
    "\n"
    "Context:\n"
    "Table Name: snapshots\n"
    "Relevant Columns: date
    "\n"
    "Example 1:\n"
    "Query: 'How many page impressions were made in October?'\n"
    "SQL: 'SELECT SUM(page_impressions), MIN(date), MAX(date) FROM snapshots WHERE EXTRACT(MONTH FROM date) = 10;'\n"
    "SQL Response: 'SUM: 500000, MIN: 2023-10-01, MAX: 2023-10-31'\n"
    "Response: There were 500,000 page impressions made from October 1, 2023, to October 31, 2023.\n"
    "\n"
    "Example 2:\n"
    "Query: 'How many people total left my page yesterday?'\n"
    "SQL: 'SELECT SUM(page_fan_removes), MIN(date), MAX(date) FROM snapshots WHERE date = current_date - interval '1 day';'\n"
    "SQL Response: 'SUM: 12000, MIN: 2023-10-02 00:00:00, MAX: 2023-10-02 00:00:00'\n"
    "Response: 12,000 users engaged with the page yesterday.\n"
    "\n"
    "Example 3:\n"
    "Query: 'How many users engaged with the page last week?'\n"
    "SQL: 'SELECT SUM(page_engaged_users), MIN(date), MAX(date) FROM snapshots WHERE date BETWEEN '2023-09-01' AND '2023-09-07';'\n"
    "SQL Response: 'SUM: 12000, MIN: 2023-09-01, MAX: 2023-09-07'\n"
    "Response: 12,000 users engaged with the page from September 1, 2023, to September 7, 2023.\n"
    "\n"
    "Now, for the current task:\n"
    "Query: {query_str}\n"
    "SQL: {sql_query}\n"
    "SQL Response: {sql_response_str}\n"
    "Response: "
)
L
T
2 comments
Probably append to your query. query_str + " and present the time range you queried (if any)."
Thanks Logan. I'll try that.
Add a reply
Sign up and join the conversation on Discord