Use Databricks Assistant
Databricks Assistant is a context-aware AI assistant that is available in notebooks, SQL editor, AI/BI dashboards, and file editor. This document focuses on notebooks. Usage in the other features of Databricks is similar.
For an account: Disable or enable Databricks Assistant features
Partner-powered Databricks Assistant features are enabled by default. However, account admins can disable Partner-powered Assistant features for all workspaces within an account. Account admins can also enforce enabling Databricks Assistant for the entire account:
Tip
The act of enabling or disabling Partner-powered Databricks Assistant features for your account is captured as an account event in your audit logs, see Account events.
As an account admin, log in to the account console.
Click Settings.
Click the Feature enablement tab.
For the Enable partner-powered AI features option, select Off or On.
Prevent workspace overrides with the Enforce setting:
To learn about the services used for Partner-powered Databricks Assistant features, see Features governed by the **Partner-powered AI assistive features** setting.
For a workspace: Disable or enable Assistant features
If your account admin enables Assistant, it is enabled by default in workspaces. Unless the account admin chose to enforce the setting, workspace admins can disable it for their workspaces.
To disable Databricks Assistant in a workspace:
Click your username in the top bar of the Databricks workspace > Settings.
In the left pane under Workspace admin, click the Advanced tab.
To disable Assistant, click the toggle Off for AI-powered AI assistive features.
Tour of the Assistant pane
This section describes the default experience of the Assistant pane.
To open the Assistant pane, click in the left sidebar.
Type questions in the text box at the bottom of the Assistant pane and press Enter or click at the right of the text box. Assistant displays its answer. The following screenshot shows actions you can take after Assistant has generated code in the Assistant pane.
You can run the same query again to generate another answer. To do so, hover your cursor over the answer and click .
To close the pane, click the icon again or click in the upper-right corner of the cell. You can expand the pane to full width by clicking ; click to return the pane to default width.
The Assistant pane keeps track of your conversations even if you close the pane or notebook. To clear previous conversations, click at the upper-right of the Assistant pane.
Threads and prompt history
Conversation threads persist across the different contexts where Databricks Assistant is available. From the Assistant pane, you can create new conversation threads, view the question and prompt history, and manage your Databricks Assistant experience.
Databricks Assistant titles the threads based on the context of your prompts, so you can navigate the history of your Assistant conversation. The following example is from a question about a notebook.
Use Databricks Assistant in a notebook cell
In a notebook, Databricks Assistant is available in the Assistant pane or inline in a code cell.
To use Databricks Assistant directly in a code cell, press Cmd + i on MacOS or Ctrl + i on Windows. A text box appears in the cell. You can type a question or comment in English and then press Enter (not Shift+Enter, like you would to run a cell) to have Assistant generate a response.
Use slash commands for prompts
Slash commands are a shortcut for creating common prompts.
Prompt text |
What Assistant does |
---|---|
|
Displays common commands |
|
Comments the code in a diff view |
|
Provides an explanation of the code in a cell |
|
Proposes a fix to any code errors in a diff view |
|
Searches for relevant tables based on Unity Catalog metadata. To find features or feature tables, mention “features” or “feature tables” in the query. See Find features and feature tables using Databricks Assistant. |
|
Searches for relevant queries based on Unity Catalog metadata. |
|
Improves inefficient SQL queries. |
|
Formats code for readability. |
|
Suggests updated names to notebook cells and other elements, depending on the context. |
|
Adjusts your notebook settings directly from Assistant. |
When you use /fix
or /doc
, in the diff window select Accept to accept the proposed changes or Reject to keep the original code. If you accept the proposed code, the code does not automatically run. You can review the code before running it. If the generated code is not what you wanted, try again by adding more details or information to your comment. See Tips for using Databricks Assistant.
Get detailed explanations of code snippets. Use the /explain
prompt and include terms like “be concise” or “explain code line-by-line” to request the level of detail that you want. You can also ask Databricks Assistant to add comments to the code.
For code autocomplete, performance may be better using the Assistant pane than in a notebook cell.
Assistant closes automatically if you Accept or Reject the code it generated.
Get help with code
Databricks Assistant helps with code, both SQL and Python:
AI-based autocomplete in Databricks notebooks, the SQL editor, and the file editor.
Data filtering with natural-language prompts.
Code debugging with Diagnose Error (Public Preview).
Filter data with natural language prompts
Use Databricks Assistant to filter data outputs with natural language prompts.
To filter outputs with natural language, click the Filter icon in the output table and enter a prompt. For example, as in the animated example following, you can prompt “Show me only males over 70.”
Get inline code suggestions: Python and SQL examples
As you type, suggestions automatically appear. Press Tab to accept a suggestion. To manually trigger a suggestion, press Option + Shift + Space (on macOS) or Control + Shift + Space (on Windows).
AI-based autocomplete can also generate code from comments:
Debug code: Python and SQL examples
Preview
This feature is in Public Preview.
To use Databricks Assistant to fix code, do any of the following:
Ask a question in the Assistant pane.
Click the Diagnose Error button that appears in the cell results when an error occurs.
Click Debug to interactively step through the code line-by-line, set breakpoints, inspect variables, and analyze a program’s execution.
The tabs below show examples in Python and SQL code:
When you click Diagnose error, Assistant automatically runs /fix
.
Quick Fix
When code returns errors, Quick Fix automatically recommends fixes for basic errors that can be fixed in a single line change.
Click Accept and run to make the recommended fix and continue running your code:
Diagnose errors in jobs (Public Preview)
Preview
This feature is in Public Preview.
Databricks Assistant helps diagnose errors in jobs.
To diagnose a job with Assistant:
Open the failed job from the Jobs UI.
Select Diagnose Error.
Get answers from Databricks documentation
In the notebook editor, Databricks Assistant can answer questions based on Databricks documentation. Type your question or prompt into the prompt box.
Tips for using Databricks Assistant
This section includes some general tips and best practices when using Databricks Assistant.
Databricks Assistant uses context to provide better answers
Databricks Assistant has access to table and column schemas and metadata. This allows you to use natural language and generate more accurate queries. For example, if a table has a column called State, you can ask Databricks Assistant to generate a list of users who live in Michigan.
Databricks Assistant uses the following context:
Code or queries in the current notebook cell or Databricks SQL editor tab.
Table and Column names and descriptions.
Previous prompt questions.
Favorite and active tables.
For the diagnose error feature, the stack trace from the error output.
When selecting columns from a DataFrame, you can get more accurate results by providing a starting query. For example, provide a statement like SELECT * FROM <table_name>
. This allows Databricks Assistant to get the column names and not have to guess.
Because Databricks Assistant uses your conversation history to provide better and more accurate answers, you can ask Databricks Assistant to alter the output of a previous response without having to rewrite the entire prompt. Use Assistant’s chat history to iteratively clean, explore, filter, and slice DataFrames in the Assistant pane.
Be specific
The structure and detail that Databricks Assistant provides varies from time to time, even for the same prompt. Try to provide Assistant as much guidance as you can to help it return the information you want in the desired format, level of detail, and so on. For example:
“Explain this code in a couple sentences” or “Explain this code line-by-line”.
“Create a visualization using MatPlotLib” or “Create a visualization using Seaborn”.
Give examples of row-level data values
Because Databricks Assistant does not use row-level data, you might need to provide more detail to prompts to get the most accurate answer. Use table or column comments in Catalog Explorer to add a line of sample data. For example, suppose your height column is in the format feet
-inches
. To help Assistant interpret the data, add a comment such as “The height column is in string format and is separated by a hyphen. Example: ‘6-2’.” For information about table and column comments, see Add comments to data and AI assets.
If you need to use column data type conversions to run an operation, you might need to provide details. For example: “convert this code from pandas to PySpark, including the code needed to convert the pandas DataFrame to a PySpark DataFrame and changing the data type of column churn from boolean to integer”.
Use Shift+Enter to add a new line in the chat text box
Use Shift+Enter to add a new line in the Assistant chat text box. This makes it easy to format and organize your messages to Databricks Assistant.
Edit and run code in Databricks Assistant chat pane
Run code in the Assistant pane to validate it or use it as a scratchpad. To run code, click in the upper-left corner of the code box in the Assistant pane.
The tabs below show examples for Python and SQL code:
When you run code in the Assistant pane, output is displayed and the variables become usable in the notebook.
You can also edit the code that Databricks Assistant generates directly in the Assistant chat box before moving the code to the notebook.