Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Trim Metabot's retry guidance and point charts at run_query (#84581)

Chris Truterffebfcef22eb
diff --git a/resources/metabot/prompts/shared/prompt_snippets/results_visible.selmer b/resources/metabot/prompts/shared/prompt_snippets/results_visible.selmer
index 5ddf79fbf63..aa1da4d2bc0 100644
--- a/resources/metabot/prompts/shared/prompt_snippets/results_visible.selmer
+++ b/resources/metabot/prompts/shared/prompt_snippets/results_visible.selmer
@@ -8,4 +8,4 @@ Values in a result are written for display, not copied exactly: `&`, `<`
The rows you read can differ from the ones on the user's screen. Filter values the user has set on a question or a dashboard are not applied when you run its query, and the data may have changed since the user loaded it. When your figures and the user's disagree, say that these are the likely reasons rather than treating either as wrong.
-You still learn the shape of the data through the metadata tools first. Run queries to answer, not to discover tables and fields.
+You still learn the shape of the data through the metadata tools first. Run queries to answer, not to discover tables and fields. If a run fails, read the error, fix the query and run it again. If it fails the same way twice, stop and tell the user what went wrong.
diff --git a/src/metabase/metabot/tools/construct.clj b/src/metabase/metabot/tools/construct.clj
index 566291c7359..4a1bca9069d 100644
--- a/src/metabase/metabot/tools/construct.clj
+++ b/src/metabase/metabot/tools/construct.clj
@@ -1229,14 +1229,17 @@
(defn- chart-instructions
"What to tell the model to do with the chart it just got."
- [chart-id]
+ [chart-id query-id]
(let [link (te/link "Chart" "metabase://chart/" chart-id)]
(te/lines
"Your query and chart have been created successfully."
""
"Next steps to present the chart to the user:"
(str "- Always provide a direct link using: `" link "` where Chart is a meaningful link text")
- "- If creating multiple charts, present all chart links")))
+ "- If creating multiple charts, present all chart links"
+ (when (shared/tool-offered? "run_query")
+ (str "- To state any of its values, call `run_query` with `query_id` `" query-id
+ "` first. Call it without telling the user you are doing so.")))))
(defrecord ConstructNotebookQueryTool []
tools/Tool
@@ -1271,7 +1274,7 @@
{:query-id (:query-id structured)
:chart-type chart-type
:queries-state {(:query-id structured) (:query structured)}})
- instruction-text (chart-instructions (:chart-id chart))]
+ instruction-text (chart-instructions (:chart-id chart) (:query-id structured))]
{:output (tool-output (structured->chart-xml structured (:chart-id chart) chart-type)
instruction-text)
:structured-output (assoc structured
diff --git a/test/metabase/metabot/tools_test.clj b/test/metabase/metabot/tools_test.clj
index 55429548045..444d5454c25 100644
--- a/test/metabase/metabot/tools_test.clj
+++ b/test/metabase/metabot/tools_test.clj
@@ -257,8 +257,8 @@
(testing "with run_query offered, the query is built and the user is shown nothing"
(is (= {:chart? false, :shown? false, :query-id "q-1", :run-it? true}
(construct! #{"construct_notebook_query" "run_query"} {:show_chart false}))))
- (testing "with run_query offered and the argument left out, the chart is shown"
- (is (= {:chart? true, :shown? true, :query-id "q-1", :run-it? false}
+ (testing "with run_query offered and the argument left out, the chart is shown and points at run_query"
+ (is (= {:chart? true, :shown? true, :query-id "q-1", :run-it? true}
(construct! #{"construct_notebook_query" "run_query"} {}))))
(testing "without run_query the chart is shown whatever the argument says"
(is (= {:chart? true, :shown? true, :query-id "q-1", :run-it? false}