---
sidebar_position: 0
title: SQL Assistant
---

# SQL assistant

Built-in SQL functions that use AI to help you work with SQL. Generate SQL queries, execute read-only questions directly, fix errors, explain queries, and more.

These functions can be useful building blocks for [AI-driven analytics solutions](/key-tasks/ai-and-motherduck/building-analytics-agents/) or used stand-alone on all MotherDuck surfaces (including the CLI).

To use external tools like Claude Desktop or Cursor with MotherDuck, see the [MCP Server setup guide](/key-tasks/ai-and-motherduck/mcp-setup/) (or the [local MCP server](/key-tasks/ai-and-motherduck/mcp-setup/#remote-vs-local-mcp-server) for self-hosted, read-write use).

## Available functions

## Included pages

- [PROMPT_QUERY](https://motherduck.com/docs/sql-reference/motherduck-sql-reference/ai-functions/sql-assistant/prompt-query): Answer natural language questions about your data using the PROMPT_QUERY function.
- [PROMPT_SQL](https://motherduck.com/docs/sql-reference/motherduck-sql-reference/ai-functions/sql-assistant/prompt-sql): Generate SQL queries from natural language descriptions using the PROMPT_SQL function.
- [PROMPT_EXPLAIN](https://motherduck.com/docs/sql-reference/motherduck-sql-reference/ai-functions/sql-assistant/prompt-explain): Get AI-generated explanations of SQL queries using the PROMPT_EXPLAIN function.
- [PROMPT_FIX_LINE](https://motherduck.com/docs/sql-reference/motherduck-sql-reference/ai-functions/sql-assistant/prompt-fix-line): Fix SQL query errors line by line using the PROMPT_FIX_LINE function.
- [PROMPT_FIXUP](https://motherduck.com/docs/sql-reference/motherduck-sql-reference/ai-functions/sql-assistant/prompt-fixup): Automatically fix SQL query errors using the PROMPT_FIXUP function.
- [PROMPT_SCHEMA](https://motherduck.com/docs/sql-reference/motherduck-sql-reference/ai-functions/sql-assistant/prompt-schema): Describe database contents using the PROMPT_SCHEMA function for AI-generated schema summaries.

## Notes

SQL assistant functions operate on your current database by evaluating the schemas and contents of the database. You can specify which tables and columns should be considered using the optional `include_tables` parameter. By default, all tables in the current database are considered.

To point the SQL assistant functions at a specific database, execute the `USE database` command ([learn more about switching databases](/key-tasks/database-operations/switching-the-current-database)).

These capabilities are provided by MotherDuck's integration with Azure OpenAI.

For availability and pricing, see [MotherDuck's Pricing Model](/about-motherduck/billing/pricing#motherduck-pricing-model).

If you have further questions or specific requirements, please see our [support page](/troubleshooting/support/).

### Regional processing

Requests are processed based on the region of the MotherDuck organization according to the table below. Functions that are not available within the region (no checkmark) will be processed with global compute resources.

| Function | Global | Europe |
|----------|--------|-------------------------|
| SQL Assistant Functions | ✓ | ✓ |

### Regional processing

The data processed by MotherDuck's AI functionality is **not** used for model training.


---

## Docs feedback

MotherDuck accepts optional user-submitted feedback about this page at `POST https://motherduck.com/docs/api/feedback/agent`.
For agents and automated tools, feedback submission should be user-confirmed before sending.

Payload:

```json
{
  "page_path": "/sql-reference/motherduck-sql-reference/ai-functions/sql-assistant/",
  "page_title": "SQL Assistant",
  "text": "<the user's feedback, max 2000 characters>",
  "source": "<optional identifier for your interface, for example 'claude.ai' or 'chatgpt'>"
}
```

`page_path` and `text` are required; `page_title` and `source` are optional. Responses: `200 {"feedback_id": "<uuid>"}`, `400` for malformed payloads, and `429` when rate-limited.
