Templating
Templating is a great way to allow more flexibility for queries that return canonical answers. Rather than creating different Golden Queries for different filters, time periods, etc, you can create a single Golden Query and template it to make it maximally useful.
Create a Golden Query
You can create a Golden Query by asking a question in chat to generate a query, and then clicking "Add Golden Query". You can find more details in the Quick Start Guide or in the Golden Query docs.
Template an Existing Golden Query
First, navigate to the Catalog section of the Rulebook.
Next, click "Edit" on any Golden Query.
There are two ways to create a template:
- Use an AI Generated Template. In the Golden Query edit modal, scroll to the bottom to the "AI Generated Template" section. Accept or reject the suggested template.
-
Manually.
a. To do this, replace any part of the query with a variable like
<<my_variable>>
. At the bottom of the modal, you will see a table of variables, including the newmy_variable
.b. Give your variable a description and a default value. The description tells the AI how to use the variable.
c. Give the variable a default value. The default value can be used by the AI, and when it's unused, it provides the AI an example of how to fill the variable.
d. Be sure to "Dry Run" your template to be sure it executes with the default values, and then save the Golden Query.
Don't forget to update your Golden Query's name! If you template a query for "Revenue 2022" to work for any year, update the name to something like "Annual Revenue" or "Revenue".
If you use short names, make sure you add Associated Questions to the Golden Query so that the AI is able to find and use your template!
Associated Questions
To help the AI make better use of your Golden Query, consider adding associated questions to help the AI find it. Associated Questions are examples of questions that your Golden Query can answer. These will improve search across your Golden Queries and make the AI more useful.
Using a Template
-
In the "Overview" chat, ask a question that can be answered by one of your Golden Queries. For example, if you have a Golden Query for "Users with the most sessions", you might add a question like "Which users have the most organic traffic?".
-
The AI will search across Golden Queries and show options. Click the desired Golden Query.
-
You can click to show the SQL query to examine how the AI filled the template.