# Ask AI on Virtual Apps and Direct SQL

Source: https://help.dashboardfox.com/ai-query/ask-ai-on-virtual-apps-and-direct-sql

Most questions are answered from a normal category. Ask AI can also answer questions about an existing document through a **Virtual App**, and can suggest SQL when a question needs more than a standard document.

| Where | Does Ask AI work? | What it uses |
|---|---|---|
| **A normal category** | Yes | The tables and fields your App Builder prepared |
| **A Virtual App** | Yes | The columns of the saved document the Virtual App is built on |
| **A Direct SQL document** | No, but Ask AI can suggest SQL for you to review | — |

## Ask AI on a Virtual App

A Virtual App is built on the result of another saved document, such as an imported spreadsheet, an API fetch, a SQL query or blended data. Ask AI answers questions about that document's columns.

### Prerequisites

- AI turned on for the Advanced Reports app and for the app the source document uses
- A saved source document

### Ask a Question

1. Open the Virtual App in the document builder and select **Ask AI**.
2. Ask as usual: *"total amount by vendor"*, *"top 10 by count"*.
3. If the AI asks which value you meant, pick from the choices.

**Good to know:**

- There is no Prepare for AI step. The AI works from the source document's column names and types.
- To answer well, it also uses the values of short text columns and the range of number and date columns. This does not apply when **Strict privacy** is on, or to fields hidden in the source app.
- If **Starter questions** is on for the app, Ask AI opens with three suggested questions.
- A Virtual App uses the AI provider of the app its source document is built on.

## Suggested SQL

Some questions can't be built as a standard document. Ask AI says so and explains why.

If you have permission to see SQL and to write Direct SQL, you also get **Show suggested SQL** and **Copy SQL**.

1. Select **Show suggested SQL** and review it.
2. Select **Copy SQL**.
3. Paste it into a new Direct SQL document in the **Advanced SQL** app.
4. Run it, check the result, and save.

**Important:** Ask AI never runs SQL it wrote. You review and run it yourself. Every Direct SQL document is checked to be read-only when it runs.

## Best Practices

- **Name source columns clearly.** "Invoice Amount" works far better than "col\_7". Rename columns in the source document and answers improve straight away.
- **Make SQL results askable.** Save a Direct SQL document, build a Virtual App on it, and you can ask plain-language questions of it from then on.
- **Source documents with prompts work,** as long as the prompt can be skipped or answered.

## Additional Resources

- [Build a Document with Ask AI](https://help.dashboardfox.com/ai-query/build-a-document-with-ask-ai)
- [Troubleshooting Ask AI](https://help.dashboardfox.com/ai-query/troubleshooting-ask-ai)
- **DashboardFox Academy:** [Ask AI on Virtual Apps and SQL](https://dashboardfox.com/academy/ask-ai-advanced-reports/)
