> ## Documentation Index
> Fetch the complete documentation index at: https://ngquct-docs-fix-500-query-results.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# AI Assistant

> Built-in AI for SQL: chat with tool calling, inline suggestions, explain, optimize, and fix-error across 14 providers

One provider is active at a time and answers every AI request in the app, from the chat panel to the ghost text in the editor. Switch it and all of them switch with it. Keys are yours and live in the macOS Keychain, so every request bills to your own account with that provider.

## Configure a provider

Open **Settings > AI** (`Cmd+,`). **Enable AI Features** at the top gates the whole tab; turning it off also hides the per-connection AI policy in the connection form.

<Frame caption="AI settings">
  <img className="block dark:hidden" src="https://mintcdn.com/ngquct-docs-fix-500-query-results/hA72m8tSnRe3b-ew/images/ai-chat-settings-provider.png?fit=max&auto=format&n=hA72m8tSnRe3b-ew&q=85&s=f0388714ebae2ee3c68c5961f41503ea" alt="AI settings" width="1560" height="960" data-path="images/ai-chat-settings-provider.png" />

  <img className="hidden dark:block" src="https://mintcdn.com/ngquct-docs-fix-500-query-results/hA72m8tSnRe3b-ew/images/ai-chat-settings-provider-dark.png?fit=max&auto=format&n=hA72m8tSnRe3b-ew&q=85&s=62864ae712e1e1f4fe1aa8917104ab67" alt="AI settings" width="1560" height="960" data-path="images/ai-chat-settings-provider-dark.png" />
</Frame>

<Steps>
  <Step title="Add the provider">
    Click **Add Provider…** and pick a type. **Add Custom Provider…** at the bottom takes any OpenAI-compatible endpoint.
  </Step>

  <Step title="Authenticate">
    Paste an API key, or sign in for GitHub Copilot, ChatGPT, Cursor, and xAI.
  </Step>

  <Step title="Pick a model and test">
    Type a model name or pick one from the fetched list, then click **Test Connection**.
  </Step>
</Steps>

The **Active Provider** picker decides which one handles requests. Where a model supports reasoning effort, its detail sheet adds a picker for it and replies render their thinking in a collapsible **Reasoning** block.

With no preference, start with Claude or OpenAI on an API key: both take a key, tools, and images with no further setup. The others each come with something to know.

| Provider               | Sign-in                                                                                                                                     | Worth knowing                                                                                                                                                                |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| GitHub Copilot         | GitHub device flow                                                                                                                          | Runs its own tool loop, so the tool call limit never applies                                                                                                                 |
| ChatGPT                | Your ChatGPT account, on the Codex quota from Plus, Pro, Business, and Enterprise plans. **Import from Codex CLI** reuses an existing login | Unofficial interface, may change                                                                                                                                             |
| Cursor                 | API key, or **Sign in with Cursor** with the Cursor CLI installed                                                                           | Runs as an agent, not a chat-completions endpoint, so it cannot call TablePro's tools: Edit and Agent modes run no queries through it                                        |
| xAI                    | API key, or **Sign in with xAI** on a SuperGrok or X Premium+ subscription                                                                  | Sign-in opens a Grok Build consent screen and is unofficial. Presets: Grok 4.5, Grok 4.3                                                                                     |
| Ollama, llama.cpp, MLX | None. Start the server first                                                                                                                | Presets fill in `http://localhost:11434` for Ollama and `http://localhost:8080` for `llama-server` and `mlx_lm.server`. Start `llama-server` with `--jinja` for tool calling |
| Claude Agent           | Claude Code's `claude` command, no key                                                                                                      | Bills against a Claude subscription, with tradeoffs                                                                                                                          |

### Claude Agent

Install Claude Code, run `claude /login` in Terminal, then pick Opus, Sonnet, or Haiku. Replies bill against your Claude subscription instead of an API key. The provider answers from your schema when the MCP server is on in **Settings > Integrations**, and falls back to plain chat when it is off.

The `claude` tool runs headless here. Claude Code is built for you to use directly rather than as a backend for other apps, so this path can break with any Claude Code release. Your subscription is governed by Anthropic's [Consumer Terms](https://www.anthropic.com/legal/consumer-terms) and [Usage Policy](https://www.anthropic.com/legal/aup), which TablePro cannot grant rights under. Replies also count against the limits you share with claude.ai and your own Claude Code sessions, so running out here stops your work there. For a metered path on commercial terms, add the **Claude** provider with an API key.

## Chat

Open the inspector (`Cmd+Option+I`) and switch the segmented control at its top from **Details** to **AI Chat**. There is no dedicated chat shortcut or menu item.

<Frame caption="AI chat panel">
  <img className="block dark:hidden" src="https://mintcdn.com/ngquct-docs-fix-500-query-results/hA72m8tSnRe3b-ew/images/ai-chat-panel.png?fit=max&auto=format&n=hA72m8tSnRe3b-ew&q=85&s=0a0187839bac24e6419e5011d37310cb" alt="AI chat panel" width="1560" height="960" data-path="images/ai-chat-panel.png" />

  <img className="hidden dark:block" src="https://mintcdn.com/ngquct-docs-fix-500-query-results/hA72m8tSnRe3b-ew/images/ai-chat-panel-dark.png?fit=max&auto=format&n=hA72m8tSnRe3b-ew&q=85&s=4689f05dd3d0a0d401598b91e3345677" alt="AI chat panel" width="1560" height="960" data-path="images/ai-chat-panel-dark.png" />
</Frame>

Type a question and press Return. Code blocks carry **Copy** and **Insert**, and Insert fills the current query tab when it is empty and opens a new one otherwise. A token count sits under each response, a failed one offers **Retry**, a finished one **Regenerate**, and **Stop Generating** cancels a reply mid-stream.

Conversations save themselves and take their title from your first message. The clock icon in the inspector header opens recent ones; the pencil-and-square icon starts a new one. Editing a message you already sent puts its text and attachments back in the composer and drops that turn and everything after it.

Paste or drag images into the composer on any provider that takes them, which is all of them except GitHub Copilot, Cursor, ChatGPT, and Claude Agent.

### Chat modes

The mode picker in the composer footer controls which tools the AI can call. It is an app-level setting that survives restarts, and a fresh install starts in **Ask**.

| Mode      | Tools available                                                                                                                                            | When to use                                                |
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- |
| **Ask**   | Read-only schema lookups: `list_connections`, `get_connection_status`, `list_databases`, `list_schemas`, `list_tables`, `describe_table`, `get_table_ddl`. | Questions, exploration, drafting queries you run yourself. |
| **Edit**  | All Ask tools, plus `execute_query` for `SELECT`, `INSERT`, `UPDATE`, `DELETE`. Destructive DDL (`DROP`, `TRUNCATE`, `ALTER…DROP`) stays blocked.          | Letting the AI run the queries it proposes.                |
| **Agent** | All tools, plus `confirm_destructive_operation` for destructive DDL. Runs tools in a loop.                                                                 | Multi-step migrations and schema changes.                  |

Mode and [Safe Mode](/features/safe-mode) are independent gates. Agent mode does not bypass Safe Mode.

### Tool calling

In Edit and Agent modes each tool call appears as a card in the reply. Read-only tools run immediately. Write tools wait for **Run**, for **Always for this connection** (which whitelists that one tool on that one connection and syncs with it over iCloud), or for **Cancel**, which hands the model an error result and lets it carry on.

<Frame caption="Per-card tool approval">
  <img className="block dark:hidden" src="https://mintcdn.com/ngquct-docs-fix-500-query-results/hA72m8tSnRe3b-ew/images/ai-chat-tool-approval.png?fit=max&auto=format&n=hA72m8tSnRe3b-ew&q=85&s=af414f62397f01bc4055f1682dbfe1a2" alt="Per-card tool approval" width="1560" height="960" data-path="images/ai-chat-tool-approval.png" />

  <img className="hidden dark:block" src="https://mintcdn.com/ngquct-docs-fix-500-query-results/hA72m8tSnRe3b-ew/images/ai-chat-tool-approval-dark.png?fit=max&auto=format&n=hA72m8tSnRe3b-ew&q=85&s=fb87968532ba7dbf049fe8d31ac43649" alt="Per-card tool approval" width="1560" height="960" data-path="images/ai-chat-tool-approval-dark.png" />
</Frame>

Safe Mode **Silent** auto-approves write tools and **Read-Only** auto-denies them. Destructive operations are the exception: `confirm_destructive_operation` always needs a click, Silent does not auto-approve it, **Always for this connection** is refused for it, and the model must pass the verbatim phrase `I understand this is irreversible`.

Every provider except Cursor can call tools. Claude Agent reaches them through the MCP server, so that has to be on, and local models depend on the model.

A reply pauses after 25 tool calls, keeps everything it has done, and offers **Continue** for a fresh budget or **Adjust Limit** to change the number, 5 to 200, under **Agent** in **Settings > AI**. Every call is another request with the schema attached, so a higher limit costs tokens.

### Attach context with `@`

Type `@` in the composer to open a picker at the caret: **Schema**, a specific **Table**, **Current Query**, **Query Results**, or a **Saved Query** ([favorites](/features/favorites)). Return or Tab inserts, Escape dismisses. The `@` button in the footer offers the same list minus saved queries. A saved query chip resolves at send time, so the AI sees its current SQL.

### Slash commands

Type `/` for **`/explain`**, **`/optimize`**, and **`/fix`**, which act on the active query, or **`/help`** for the list. Add your own under **Settings > AI > Custom Slash Commands**: a template substitutes `{{query}}`, `{{schema}}`, `{{database}}`, and `{{body}}`, the text typed after the command, at send time.

### Model picker

The cpu icon beside the mode picker lists every configured provider and its models. A pick there overrides the active provider for this chat panel until you change it, across turns.

## Explain, optimize, and fix

**Query > Explain with AI** (`Cmd+L`) and **Query > Optimize with AI** (`Cmd+Option+L`) act on the whole query tab; the editor's right-click menu has both and acts on the selection instead, appearing only when text is selected. When a query fails, **Fix with AI** on the inline error banner sends the query and the error. All three open a new conversation and send at once.

The reply comes back as a walkthrough. Optimize and Fix diff your query against the rewritten one, switchable between **Unified** and **Split**; Explain anchors its steps to the query as it stands. Each numbered step carries a one-line reason and a tag (**Critical**, **Change**, or **Context**), expands to the lines it refers to, and offers **Jump to lines** and **Ask about this change**, which keeps a follow-up anchored to that step. **Apply to Editor** replaces the editor content after you confirm; nothing is applied on its own. A model that answers in prose instead renders as a normal message.

## Per-connection AI rules

Pin plain-text context to a connection so the AI sees it every turn: open the connection's edit form and pick **AI Rules** in the sidebar. Use it for what the schema cannot show, like `Always filter orders by deleted_at IS NULL` or `Never select users.ssn`. The text joins the system prompt and syncs with the connection over iCloud.

## Inline suggestions

Turn on **Enable inline suggestions while typing** in the AI tab; it is off by default. Pause typing and the active provider suggests a completion as ghost text at the cursor. `Tab` accepts, `Escape` dismisses, and typing anything else dismisses it too.

The pause is the **Debounce** setting beside the toggle: 500 ms by default, adjustable from 100 to 3,000 ms in 50 ms steps. With Copilot active the suggestions come from Copilot's inline-completion model; every other provider serves them through chat completions.

## What leaves your Mac

Every message carries a system prompt built from **Settings > AI > Context**, so these settings decide what the provider sees on every turn, not only the first.

| Setting                 | Default | What it sends                                                   |
| ----------------------- | ------- | --------------------------------------------------------------- |
| Include database schema | On      | Columns and foreign keys for up to **Max schema tables** tables |
| Include current query   | On      | The editor's text, truncated at 2,000 characters                |
| Include query results   | Off     | The rows in the results grid                                    |
| Max schema tables       | 20      |                                                                 |

Ollama, llama.cpp, and MLX run on your own machine, so nothing reaches a third party. Every other provider is a network call to that vendor under the terms of your account with them.

Per connection, the **Advanced** pane of the connection form sets an AI policy: **Use Default**, **Always Allow**, **Ask Each Time**, or **Never**. The app-wide default is **Ask Each Time**, and **Never** also blocks external AI tool calls against that connection. External clients such as Raycast and Claude Desktop reach the same tools through the [External API](/external-api), bounded by the connection's **External Clients** level and the token's scope.
