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

# Reviewed Queries

Reviewed queries are curated pairs of a natural language question and its ideal SQL response. They serve as a powerful tool to guarantee accuracy, especially for business-critical calculations or complex metrics that require a specific SQL structure, such as window functions or nested queries.

By building a repository of these pre-vetted queries, you ensure that everyone in your organization receives consistent, accurate answers to the most important questions. This is the most critical aspect of context for the language model to understand your data, as it provides direct, unambiguous examples of how to query your tables.

## Create Reviewed Queries

There are two primary ways to add queries to your knowledge base: directly from the chat interface or in bulk using a CSV file.

### Create from the chat interface

The most common workflow is to validate queries as you interact with the system. This allows you to refine the AI's generated SQL or provide your own from scratch.

An easy workflow to define reviewed queries is to ask the question in the chat, provide feedback or edit the generated SQL, and then validate the response.

1. Ask a question and review the generated answer.
2. If the answer is correct, click the **thumbs-up** icon.
   <Note>
     Currently, feedback icons (thumbs-up and thumbs-down) appear only for responses containing charts or structured data. Feedback for text-only responses is not yet supported but will be available in a future update.
   </Note>
3. In the **Review a Question** modal that appears, confirm or edit the natural language question that the SQL code answers.
4. After confirmation, the query will be saved and listed in the **Context > Reviewed Queries** tab.

The following code block shows an example query to calculate the win rate for sales, validated by clicking the thumbs-up button.

```text theme={null}
SELECT 
  SAFE_DIVIDE(
    SUM(CASE WHEN `stage_label` = 'Closed Won' THEN `acv` ELSE 0 END), 
    SUM(`acv`)
  ) AS `win_rate`
FROM `wisdom-staging-406623`.`b2bsaleshomebrew`.`Opportunity`
WHERE `stage_label` IN ('Evaluation', 'Negotiation', 'Closed Loss', 'Closed Won');
```

<Frame>
  <img src="https://mintcdn.com/wisdomai/82xgEVWUP7cwhDHG/images/review-question-v02-em.png?fit=max&auto=format&n=82xgEVWUP7cwhDHG&q=85&s=4f8b3ee46e270c4d7411643285b4e521" alt="Image showing the Review a Question modal" lightAlt="Image showing the Review a Question modal" darkAlt="Image showing the Review a Question modal" className="dark:hidden" width="759" height="462" data-path="images/review-question-v02-em.png" />

  <img src="https://mintcdn.com/wisdomai/fObDWqSPX2Ngm__Z/dark-img/review-question-v02.png?fit=max&auto=format&n=fObDWqSPX2Ngm__Z&q=85&s=25fd825163a0724c16e640a9a9000e1a" alt="Image showing the Review a Question modal" lightAlt="Image showing the Review a Question modal" darkAlt="Image showing the Review a Question modal" className="hidden dark:block" width="753" height="469" data-path="dark-img/review-question-v02.png" />
</Frame>

5. If the answer needs changes, click the **Edit** button (pencil icon) to modify the SQL. Once you are satisfied, click **Mark as reviewed**.

### Example: Editing a query for granularity

This example shows how to refine a query to get a more detailed view of your data.

Suppose you ask, **“Show me the yearly ARR trend,”** and the system generates the following correct, but high-level, query:

```text theme={null}
SELECT
  DATE_TRUNC(`close_date`, YEAR) AS `year`,
  SUM(`acv`) AS `arr`
FROM
  `wisdom-staging-406623`.`b2bsaleshomebrew`.`Opportunity`
WHERE
  `stage_label` = 'Closed Won'
GROUP BY
  `year`
ORDER BY
  `year` ASC
```

The chart shows a clear year-over-year trend. However, you decide that a **quarterly view** would be more insightful for tracking seasonal performance. To do this, click the **Edit** button (the pencil icon) to modify the SQL directly.

<Frame>
  <img alt="Image showing the Edit Sql option in chat" lightAlt="Image showing the Edit Sql option in chat" darkAlt="Image showing the Edit Sql option in chat" src="https://mintcdn.com/wisdomai/qzsF6lErt4IAl7uY/images/Edit-sql-0925.png?fit=max&auto=format&n=qzsF6lErt4IAl7uY&q=85&s=d4e2dd6e4341f2599a93725b5f1b359a" className="dark:hidden" width="954" height="905" data-path="images/Edit-sql-0925.png" />

  <img alt="Image showing the Edit Sql option in chat" lightAlt="Image showing the Edit Sql option in chat" darkAlt="Image showing the Edit Sql option in chat" src="https://mintcdn.com/wisdomai/fObDWqSPX2Ngm__Z/dark-img/Edit-sql-0925.png?fit=max&auto=format&n=fObDWqSPX2Ngm__Z&q=85&s=40ec63190b8978e07da05aaa5458e2bd" className="hidden dark:block" width="992" height="887" data-path="dark-img/Edit-sql-0925.png" />
</Frame>

The only change needed is to adjust the `DATE_TRUNC` function from `YEAR` to `QUARTER`.

Here is the **edited SQL**:

```text theme={null}
SELECT
  DATE_TRUNC(`close_date`, QUARTER) AS `quarter`,
  SUM(`acv`) AS `arr`
FROM
  `wisdom-staging-406623`.`b2bsaleshomebrew`.`Opportunity`
WHERE
  `stage_label` = 'Closed Won'
GROUP BY
  `quarter`
ORDER BY
  `quarter` ASC
```

<Frame>
  <img alt="Image showing the Edited SQL" lightAlt="Image showing the Edited SQL" darkAlt="Image showing the Edited SQL" src="https://mintcdn.com/wisdomai/8o-t5X_fx-_gUdmG/images/sql-edited-0925.png?fit=max&auto=format&n=8o-t5X_fx-_gUdmG&q=85&s=784fe479689dbf99a7122bb973cc66c2" className="dark:hidden" width="1827" height="797" data-path="images/sql-edited-0925.png" />

  <img alt="Image showing the Edited SQL" lightAlt="Image showing the Edited SQL" darkAlt="Image showing the Edited SQL" src="https://mintcdn.com/wisdomai/fObDWqSPX2Ngm__Z/dark-img/sql-edited-0925.png?fit=max&auto=format&n=fObDWqSPX2Ngm__Z&q=85&s=f60c7f531693220e1d2cd12ac27bf572" className="hidden dark:block" width="1780" height="881" data-path="dark-img/sql-edited-0925.png" />
</Frame>

After applying the change and seeing the updated quarterly chart, you can save this improved version. You would click **Mark as reviewed** and update the question to **“Show me the quarterly ARR trend”** to save it as a new, more specific Validated Query for future use.

<Frame>
  <img alt="Image showing the Review a Question modal" lightAlt="Image showing the Review a Question modal" darkAlt="Image showing the Review a Question modal" src="https://mintcdn.com/wisdomai/q563-b142AdAYiKz/images/review-question-sql-0925.png?fit=max&auto=format&n=q563-b142AdAYiKz&q=85&s=f20c39814fba505abb9e644417c7ff86" className="dark:hidden" width="947" height="610" data-path="images/review-question-sql-0925.png" />

  <img alt="Image showing the Review a Question modal" lightAlt="Image showing the Review a Question modal" darkAlt="Image showing the Review a Question modal" src="https://mintcdn.com/wisdomai/fObDWqSPX2Ngm__Z/dark-img/review-question-sql-0925.png?fit=max&auto=format&n=fObDWqSPX2Ngm__Z&q=85&s=7d5f42213f444f2fe200f6e59b2f86fc" className="hidden dark:block" width="747" height="467" data-path="dark-img/review-question-sql-0925.png" />
</Frame>

### Bulk upload with CSV

For adding many validated queries at once, you can use the CSV upload option in the **Context** > **Reviewed Queries** tab. This is ideal for migrating existing reports or defining a set of canonical metrics from the start.

To bulk upload, create a CSV file that contains two column headers: `Query` and `SQL`. Populate the rows with the natural language questions and their corresponding SQL code.

<Frame>
  <img alt="Import CSV File button shown" lightAlt="Import CSV File button shown" darkAlt="Import CSV File button shown" src="https://mintcdn.com/wisdomai/36WEIdh1uGlYFdZ7/images/new-ui-import-csv.png?fit=max&auto=format&n=36WEIdh1uGlYFdZ7&q=85&s=0041c10b9398e70865e4e720fed1806b" className="dark:hidden" width="1913" height="1022" data-path="images/new-ui-import-csv.png" />

  <img alt="Import CSV File button shown" lightAlt="Import CSV File button shown" darkAlt="Import CSV File button shown" src="https://mintcdn.com/wisdomai/FPeFp9c8fz1r_sxU/dark-img/new-ui-import-csv.png?fit=max&auto=format&n=FPeFp9c8fz1r_sxU&q=85&s=d20cc7903ceccb4c5adc89b07d227446" className="hidden dark:block" width="1913" height="1022" data-path="dark-img/new-ui-import-csv.png" />
</Frame>

## Best practices for well-formed SQL

For a reviewed query to be effective and reusable, follow these best practices when writing your SQL:

* **Keep it concise and readable:** Write SQL that is easy to understand. If the logic is complex, use comments or break it down.
* **Split complex examples:** Instead of creating one example that calculates multiple metrics (e.g., “Show revenue and ARR trend”), split it into two separate, focused examples (“Show revenue trend” and “Show ARR trend”).
* **Use CTEs for complex logic:** If the SQL requires multiple steps or transformations, break it down into more understandable Common Table Expressions (CTEs).
* **Be consistent:** Use a consistent SQL structure for different variations of the same metric. For example, the queries for “Yearly trend of ARR” and “ARR by segment” should be built from a consistent base calculation of ARR, ideally using the same CTE.

## Combining with language Knowledge for complex cases

While reviewed queries are powerful, some complex business rules are best enforced by pairing them with explicit instructions in your **language knowledge**. Reviewed queries teach the model *how* to calculate a specific metric, while language knowledge can teach it *what not to do* to avoid common logical errors.

For instance, imagine you have a `statewise_population` table with a pre-aggregated `country_population` column. Summing this column across multiple states from the same country would lead to massive double-counting.

While a validated query can show the correct way to get the population, adding a clear instruction in [language knowledge](/setting-up-wisdom-ai/advanced-data-modeling-creating-context#natural-language-context) provides an extra layer of protection against mistakes:

**Instruction Example:** “Never sum up the `country_population` column across different rows for the same country.”

Using both features together ensures that even when the AI generates new or slightly different queries, it still adheres to your most important business logic.

## Manage Reviewed Queries

As a Domain Data Admin, you can edit a reviewed query or reopen the conversation where it was created.

* To edit a reviewed query, click the query row and update the query text as needed.
* To reopen the original query workflow, click the **Open conversation** icon. This opens the conversation where the query was validated, allowing you to re-ask the question, modify the visualization, refine the query, edit its SQL, or regenerate the results.

<Frame>
  <img alt="Edit Reviewed Queries Chat" lightAlt="Edit Reviewed Queries Chat" darkAlt="Edit Reviewed Queries Chat" src="https://mintcdn.com/wisdomai/5Oa8t7wfNq9gW74x/images/edit-reviewed-queries-chat.png?fit=max&auto=format&n=5Oa8t7wfNq9gW74x&q=85&s=0e2f63858860150f96287b0707fc33b6" className="dark:hidden" width="1920" height="1031" data-path="images/edit-reviewed-queries-chat.png" />

  <img alt="Edit Reviewed Queries Chat" lightAlt="Edit Reviewed Queries Chat" darkAlt="Edit Reviewed Queries Chat" src="https://mintcdn.com/wisdomai/FPeFp9c8fz1r_sxU/dark-img/edit-reviewed-queries-chat.png?fit=max&auto=format&n=FPeFp9c8fz1r_sxU&q=85&s=dfc0074c36f69eb35acfbd43dae03dab" className="hidden dark:block" width="1920" height="1031" data-path="dark-img/edit-reviewed-queries-chat.png" />
</Frame>

## Next steps

<CardGroup cols={2}>
  <Card title="Limited Knowledge" icon="puzzle-piece" href="/setting-up-wisdom-ai/feedback-mechanisms/limited-context">
    Understand how to identify and flag when the system's answers lack necessary context.
  </Card>

  <Card title="Provide Feedback to the System" icon="thumbs-up" href="/setting-up-wisdom-ai/feedback-mechanisms/provide-feedback-to-the-system">
    Learn how to rate answers and provide corrections to improve the system's accuracy.
  </Card>

  <Card title="Monitor Negative Feedback" icon="thumbs-down" href="/setting-up-wisdom-ai/feedback-mechanisms/monitor-negative-feedback">
    Track and analyze negative user feedback to identify areas for system improvement.
  </Card>

  <Card title="Turn Answers into Dashboards" icon="book-open" href="/using-wisdom-ai-everyday/turn-answers-into-dashboards">
    Compile key insights and visualizations into a shareable, narrative-driven report.
  </Card>
</CardGroup>
