> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bagofwords.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Use saved queries for faster, more reliable answers

> Save a reviewed query once, and the agent loads it instead of writing new SQL every time someone asks the same question.

A saved query is a query you have checked and published to an agent's catalog. When someone asks a question it answers, the agent loads the saved query instead of writing new SQL. People get the same reviewed numbers every time, and the answer comes back faster.

<img src="https://mintcdn.com/bagofwords/HEk1MpXsB6aTo8um/images/guides/saved-queries/reuse-created-from-entity.png?fit=max&auto=format&n=HEk1MpXsB6aTo8um&q=85&s=b8b2f6b2644d1d4f2f89f6879e9fca16" alt="The agent answers from a saved query" width="2880" height="1800" data-path="images/guides/saved-queries/reuse-created-from-entity.png" />

## Before you start

* **You can publish to the agent.** This guide uses an admin account. When you save, the dialog says **As an admin, your query will be published directly.**
* **The agent has data.** The examples use the **Music Store** demo agent.

## Step 1: Ask for the data you want to save

Start a new report with the agent and ask a question.

> *Show total revenue by genre*

Check the result. Open the **Data** and **Code** tabs and make sure the numbers and the logic are right. Whatever you save here is what the agent will serve later.

## Step 2: Save the query

Under the chart, click **Save Query**.

<img src="https://mintcdn.com/bagofwords/HEk1MpXsB6aTo8um/images/guides/saved-queries/save-query-button.png?fit=max&auto=format&n=HEk1MpXsB6aTo8um&q=85&s=c1c9bbacdb9b9608710058fc5ddc7d8e" alt="Save Query under a result" width="2880" height="1800" data-path="images/guides/saved-queries/save-query-button.png" />

Fill in the dialog:

* **Title** – a short name, for example *Revenue by genre*.
* **Description** – write it with the words people actually type. The agent finds saved queries by matching words in the title and description. For example: *Total revenue (sales) by music genre, highest first. Use for: sales by genre, genre revenue, top genres, best-selling genres.*
* **Agents** – the agents that can use this query. It starts with the agent from your report.
* **Status** – keep **Published**. The agent only uses published saved queries. The other options are **Draft** and **Archived**.

<img src="https://mintcdn.com/bagofwords/HEk1MpXsB6aTo8um/images/guides/saved-queries/save-query-modal.png?fit=max&auto=format&n=HEk1MpXsB6aTo8um&q=85&s=098fe67ef22df8096c52049a33fe59e2" alt="The Save Query dialog" width="2880" height="1800" data-path="images/guides/saved-queries/save-query-modal.png" />

Click **Save Entity**. You see **Query published to the catalog**, and the button under the chart changes to **Saved Query**.

## Step 3: Ask again in a new report

Start a new report with the same agent and ask the question in your own words.

> *Which genres sell the most?*

The agent finds the saved query and loads it instead of writing a new one. While it works you see **Loading from catalog**. When it finishes, the step reads **Created from entity "Revenue by genre"**, and the chart and data come from the saved query.

In our test, this answer took one tool call (load the saved query) and no SQL generation. It finished in 15 seconds, compared with 26 seconds for the first answer that wrote the SQL.

## Step 4: Save a query with a parameter

A parameter lets one saved query answer many versions of a question, like "revenue by country" for any year. Ask for the parameter when you build the query.

> *Show total invoice revenue by billing country for one year at a time. Make the year a parameter I can change later, defaulting to 2025.*

Click **Save Query**. The dialog now has a **Parameters** section that lists the parameter and its default, here **Year** · number · = 2025.

<img src="https://mintcdn.com/bagofwords/HEk1MpXsB6aTo8um/images/guides/saved-queries/save-query-parameters.png?fit=max&auto=format&n=HEk1MpXsB6aTo8um&q=85&s=45e1369e152c77909f4924c9a7d0c63f" alt="A saved query with a Year parameter" width="2880" height="1800" data-path="images/guides/saved-queries/save-query-parameters.png" />

Put the parameter name in the title or the description, for example *Revenue by billing country for a year* and *Parameter: year*. The agent reads the title and description to decide whether a saved query fits. If neither mentions the year, the agent may write a new query instead.

Now ask for a different year in a new report:

> *Which countries brought in the most revenue in 2023?*

The agent loads the saved query with your value. The result shows a **Year** box with **Run**, and **ran with year = 2023**. Type another year and click **Run** to change it without asking again.

<img src="https://mintcdn.com/bagofwords/HEk1MpXsB6aTo8um/images/guides/saved-queries/reuse-with-parameter.png?fit=max&auto=format&n=HEk1MpXsB6aTo8um&q=85&s=297b59dd573a75244cf776227d3abfc5" alt="The saved query loaded with year 2023" width="2880" height="1800" data-path="images/guides/saved-queries/reuse-with-parameter.png" />

## Step 5: Find and run your saved queries

Open **Agents**, expand the agent, and click **Queries**. The number next to it is how many saved queries the agent has. Use **Search entities…** to filter the list, or **New query** to write one yourself.

<img src="https://mintcdn.com/bagofwords/HEk1MpXsB6aTo8um/images/guides/saved-queries/agent-queries-list.png?fit=max&auto=format&n=HEk1MpXsB6aTo8um&q=85&s=5b4059ccbffb97728be5716d905becd8" alt="The agent's saved queries" width="2880" height="1800" data-path="images/guides/saved-queries/agent-queries-list.png" />

Click a query to open it. You see the title, description, a **Parameterized** badge if it has parameters, and the **Visual**, **Data**, and **Code** tabs. Use **Edit** to change it, **Delete** to remove it, and **Refresh Data** to update its stored result.

For a query with parameters, type a value and click **Run**. The query runs right away with no AI involved, and the page shows **ran with year = 2024**.

<img src="https://mintcdn.com/bagofwords/HEk1MpXsB6aTo8um/images/guides/saved-queries/query-detail-run.png?fit=max&auto=format&n=HEk1MpXsB6aTo8um&q=85&s=fb06073e7bf36688e91936419ea26876" alt="Running a saved query with a different year" width="2880" height="1800" data-path="images/guides/saved-queries/query-detail-run.png" />

## Step 6: Point the agent to a saved query with @

You can tell the agent exactly which saved query to use. In the prompt box, type **@** and choose **Queries**, or keep typing the name. Pick the query and finish the prompt.

> *Show @Revenue by billing country for a year for 2024*

<img src="https://mintcdn.com/bagofwords/HEk1MpXsB6aTo8um/images/guides/saved-queries/mention-picker.png?fit=max&auto=format&n=HEk1MpXsB6aTo8um&q=85&s=d2d48c9ee3a80ca12b147960e399229a" alt="Mention a saved query with @" width="2880" height="1800" data-path="images/guides/saved-queries/mention-picker.png" />

The agent loads that query with the value you gave, here 2024.

## More prompts to try

| Goal | Prompt |
| - | - |
| Reuse a saved query | *Which genres sell the most?* |
| Pass a parameter | *Which countries brought in the most revenue in 2023?* |
| Name the query | *Show @Revenue by genre and list the top 3.* |

## Tips

* **Check before you save.** A saved query is served as-is. Review the **Data** and **Code** tabs first.
* **Describe it the way people ask.** Add the phrases people type ("sales by genre", "top genres") to the description. That is how the agent finds it.
* **Name the parameters.** Mention each parameter in the title or description, such as *for a year* or *Parameter: year*.
* **Keep one query per question.** If you change a saved query, edit it from **Agents → Queries** instead of saving a second copy.

## Troubleshooting

**The agent wrote new SQL instead of using my saved query.**
Check that the query's status is **Published** and that it is attached to the agent you are chatting with. Then add the words from your question to its description. To force it, mention the query with **@**.

**The agent ignored the parameter and built a new query.**
Mention the parameter in the title or description (for example *Parameter: year*), or mention the query with **@** and give the value in the prompt.

## Saved queries and custom queries

Saved queries are reviewed answers the agent loads in chat. [Custom queries](/bow-fast/custom-queries) are something else: admin-defined SQL on a connection that is turned into a table on a schedule, which the agent then queries like any other table.

## Related

* [Reports](/using-bow/reports)
* [Parameterized queries](/using-bow/parameterized-queries)
* [Dashboards](/using-bow/dashboards)
* [Train an agent](/agents/train-an-agent)
* [Custom queries](/bow-fast/custom-queries)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.