What you will be able to do
- Use Genie Code autocomplete, inline prompts and @ table references to write SQL in a notebook or the SQL editor
- Pick the right slash command for a task, including /optimize for slow queries and /explain, /doc and /fix for other jobs
- Tell Quick Fix, Diagnose Error and /fix apart, and say what each does when a query fails
- Review code Genie Code generates before running it, and explain why accepting a diff does not run it
Key concept
Genie Code (formerly Databricks Assistant) — Genie Code is the AI assistant built into notebooks and the SQL editor. It reads your Unity Catalog metadata and the code you are working on, then writes, explains, optimizes and fixes queries. You still review everything it proposes before you run it.
1.What Genie Code is and what it can see
Genie Code is the AI coding and data assistant in a Databricks workspace. It used to be called Databricks Assistant, and exam questions often use both names. For an analyst, the useful part is that it works inside the tools where queries are written. It is available in notebooks, the SQL editor, the Lakeflow Pipelines Editor, AI/BI dashboards and MLflow. You can describe a task in plain English and get SQL back, or ask it to explain, optimize or fix a query you already have.
Genie Code writes better SQL than a general chatbot because it knows your data. It reads Unity Catalog metadata: table names, column names, descriptions, and which assets are popular across the company. Each request it sends to the model includes your prompt plus context such as the code you are editing, data samples from tables and cell outputs. That is why a prompt like "list users who live in Michigan" can produce a correct WHERE clause. Genie Code sees a column called State and uses it.
Genie Code can only see what you can see. It is governed by your Unity Catalog permissions, so it cannot read a table you have no grant on or run an operation you are not allowed to run. If Genie Code "can't find" a table, the cause may be your access rather than the prompt. How those grants work is covered in Unity Catalog roles and securables.
Genie Code works as an autonomous agent by default. It plans, retrieves context, runs code and uses the output to improve its answer. Every tool action, such as running code or querying a table, goes through an approval mode. The first-time default is Auto-approve, where an AI classifier blocks actions outside the scope of your request. You can switch to Ask every time to approve each action yourself. If you only want an explanation, say so in the prompt, for example "Just explain this to me, don't run any code." When it does run code, it uses the compute already selected on the page, such as the warehouse attached to your SQL editor tab. If the page has no compute, it uses serverless.
Checkpoint 1 of 8· Check yourself
An analyst asks Genie Code in the SQL editor to write a query against finance.payroll.salaries. Genie Code replies that it cannot find or read the table, but a colleague's Genie Code uses it without trouble. What is the most likely cause?
Genie Code acts with the user's own Unity Catalog permissions. It cannot see or query a table the analyst has no grant on, even if a colleague with access can. In this case the cause is access, not the prompt.
“Genie Code is governed by your Unity Catalog permissions, so it can only access data and perform operations that you have permissions for.”Source: docs.databricks.com
2.Writing queries with autocomplete, inline prompts and table context
Genie Code helps you write queries in three ways, from least effort to most.
AI-based autocomplete runs as you type in notebooks, the SQL editor and the file editor. Suggestions appear on their own, and Tab accepts one. To ask for a suggestion manually, press Option+Shift+Space on macOS or Control+Shift+Space on Windows. Autocomplete understands aliases. If you type select * from table_name as t where t., it suggests the columns of table_name. It can also turn a comment describing what you want into code.
Inline prompts let you write a request in plain English inside a cell. Press Cmd+I (macOS) or Ctrl+I (Windows) to open a text box in the cell, type the request, and press Enter. Use Enter here, not Shift+Enter, which runs the cell. In the SQL editor, the Genie Code icon on the right side of the editor gives inline help while you write, and the left pane opens a chat with suggested questions.
The chat pane is for longer requests and follow-ups. It keeps the conversation history, so you can ask it to change its last answer, for example "now group that by region", without writing the whole prompt again. Type @ followed by a table name to point Genie Code at a specific table, or use Add context to select it. A referenced table stays attached for the rest of the chat.
Specific prompts get better SQL. Name the table with @, and give a starting query such as SELECT * FROM <table_name> so Genie Code reads the real column names instead of guessing them. Column comments in Unity Catalog also help. If a height column stores values like '6-2', a comment explaining that format lets Genie Code parse it correctly. Answers can differ even for the same prompt, so if the first result misses, add detail rather than repeating the request.
| Context | Where it comes from |
|---|---|
| Code or queries you are editing | The current notebook cell or Databricks SQL editor tab |
| Table and column names and descriptions | Unity Catalog metadata |
| Previous prompt questions | The chat history |
| Favorite and active tables | Your recent work in the workspace |
| Stack trace | The error output, used by the diagnose error feature |
Checkpoint 2 of 8· Check yourself
In the SQL editor's Genie Code chat, an analyst's generated queries keep using made-up columns such as cust_name, but the real column is customer_full_name. Which change to the request is most likely to fix this?
Pointing Genie Code at the table with @ and giving it a starting SELECT * query lets it read the actual column names, so it doesn't have to guess them. Sending the same prompt again doesn't add context. Shift+Enter runs the cell instead of submitting the prompt. Chat history helps with follow-ups, so starting new chats removes useful context.
“provide a statement like SELECT * FROM <table_name>. This allows Genie Code to get the column names and not have to guess.”Source: docs.databricks.com
3.Slash commands, and /optimize for slow queries
Slash commands are shortcuts for prompts you would otherwise type out. Type / in the prompt box to see the list. Each command does one specific job, and exam questions often turn on matching the command to the job. A command that describes a query does not change it, and a command that changes a query is not necessarily fixing an error.
| Prompt text | What Genie Code does |
|---|---|
| /explain | Provides an explanation of the code in a cell |
| /doc | Comments the code in a diff view |
| /fix | Proposes a fix to any code errors in a diff view |
| /optimize | Suggests performance improvements for SQL queries |
| /prettify | Formats SQL queries for readability |
| /findTables | Searches for relevant tables based on Unity Catalog metadata |
| /findQueries | Searches for relevant queries based on Unity Catalog metadata |
/optimize is for queries that are correct but slow. It evaluates Python, PySpark and SQL code. To use it in a notebook cell or the SQL editor, click the Genie Code icon, type /optimize, click Generate, and click Accept to apply the suggestions. It helps at three points:
- Before you run the query: yellow underlines mark spots worth optimizing, such as a filter that does not use the partition column. Hover over the underline to see the suggestion.
- After the query runs: an Optimize button reviews the query you just ran.
- When you create a table: you get a hint recommending
CREATE TABLE CLUSTER BY AUTO.
The other commands have different jobs. /explain describes what a query does and leaves it unchanged. Adding "be concise" or "explain code line-by-line" sets how much detail you get. /doc adds comments to the query in a diff view and does not affect how fast it runs. /prettify reformats the SQL so it is easier to read. Neither /doc nor /prettify makes a slow query faster. To find the right table before writing anything, use /findTables, for example "Find tables related to NFL games".
Checkpoint 3 of 8· Match them up
An analyst has five jobs to do in the SQL editor. Match each slash command to the job it handles.
Tap a term, then the definition that fits it.
Each command does one job. /doc and /explain both help a reader understand a query: /doc writes comments into the code as a diff, and /explain answers in prose. /fix targets errors. /prettify only changes layout. /findTables searches Unity Catalog metadata for relevant tables.
“/doc | Comments the code in a diff view”Source: docs.databricks.com
Sources3
4.Debugging failed queries: Quick Fix, Diagnose Error and /fix
When a query fails, Genie Code offers two tools that differ in how much of the problem they take on. Quick Fix handles small mistakes. Diagnose Error investigates larger failures.
Quick Fix appears on its own when code returns an error, but only for basic errors that a single-line change can fix. A stray trailing comma before FROM or a mistyped name on one line are typical examples. Click Accept and run to apply the fix and run the code again in one step. Quick Fix is the only path in this section where accepting a fix also runs the code.
Diagnose Error is a button that appears in the cell results when an error occurs. Clicking it makes Genie Code run /fix for you. It uses the stack trace from the error output as context and proposes a correction in a diff view. Its reach goes beyond typos. Genie Code can help diagnose and suggest fixes for environment failures, including library installation errors. In that case it may run /repairEnvironment in the Genie Code pane. Diagnose Error does not disable the cell, schedule a retry or contact an administrator. It proposes a fix for you to review.
There are two other ways to get the same help. You can type /fix yourself, or describe the failure in the Genie Code pane. In a notebook, Debug lets you step through code line by line, set breakpoints and inspect variables, which is useful when there is no error message at all.
| Situation | Tool | What you get |
|---|---|---|
| Basic error, fixable in a single-line change | Quick Fix | A recommended fix you can Accept and run |
| Complex error or environment failure | Diagnose Error | Genie Code automatically runs /fix and proposes a fix in a diff view |
| Library installation failure | Diagnose error from the pip logs | /repairEnvironment runs in the Genie Code pane |
| Query works but runs slowly | /optimize | Performance suggestions you can Accept |
Checkpoint 4 of 8· Match them up
Each situation below came up while working with queries in a notebook or the SQL editor. Match each Genie Code tool to the situation it fits.
Tap a term, then the definition that fits it.
Quick Fix only covers basic errors that a single-line change can fix, and it is the only tool that offers Accept and run. Diagnose Error runs /fix for complex failures and leaves the diff for you to review. Library installation failures go to /repairEnvironment. Slow but correct queries go to /optimize. Debug lets you step through code that has no error to diagnose.
“When code returns errors, Quick Fix automatically recommends fixes for basic errors that can be fixed in a single-line change.”Source: docs.databricks.com
Checkpoint 5 of 8· Exam question
A data analyst is writing a query in the Databricks SQL editor and introduces a trailing comma before the FROM clause. Genie Code (the assistant formerly named Databricks Assistant) underlines the line and offers a one-click correction that the analyst can accept and immediately rerun. Which Genie Code capability is behaving this way?
Correct answer: A — Quick Fix, which flags common single-line issues like trailing commas or mistyped names and lets the analyst accept the correction and rerun the query immediately.
- A. This describes Quick Fix, which is designed to catch common single-line mistakes like trailing commas, mistyped identifiers, or missing
GROUP BYclauses and surface an inline correction the analyst can accept and run immediately, matching the scenario. - B. This behavior handles deeper, multi-cause failures rather than a simple one-line syntax slip, and it works by triggering a fix request under the hood instead of surfacing an instant one-click correction, so it does not match a trailing-comma typo.
- C. This capability targets query performance rather than syntax correctness, so it would not be the feature that flags and offers to correct a malformed clause.
- D. This capability summarizes query logic in prose and leaves the code untouched, so it would not be the source of an inline syntax correction the analyst can accept and run.
Checkpoint 6 of 8· Exam question
In a notebook cell, a query fails with an error that Genie Code identifies as caused by a misconfigured cluster environment rather than a simple typo. The analyst clicks a button labeled "Diagnose error" to investigate further. What happens when the analyst does this?
Correct answer: B — Genie Code analyzes the complex failure, including possible environment causes, and automatically runs /fix on the analyst's behalf to propose a resolution.
- A. Diagnose error investigates and proposes a fix immediately rather than pausing the cell and deferring the retry to a later scheduled run.
- B. Diagnose error is built to reason about complex failures, including environment problems, and it triggers a
/fixrequest automatically so a proposed resolution is presented to the analyst, which matches this behavior. - C. Genie Code shows proposed fixes in a diff view for the analyst to review rather than silently editing and rerunning code without any visibility into the change.
- D. Diagnose error works within the editor to analyze and propose a code-level fix; it does not file tickets with workspace administrators on the analyst's behalf.
Checkpoint 7 of 8· Exam question
An analyst notices a query against a large fact table is taking much longer than expected to return results in the SQL editor. The query is syntactically correct and produces the right output, but it runs slowly. The analyst highlights the query and asks Genie Code for help making it run faster. Which Genie Code feature should the analyst use?
Correct answer: C — The /optimize command, which evaluates the selected SQL query and suggests specific changes aimed at improving its execution performance on the warehouse.
- A. This feature adds explanatory comments for readability, which does not affect how fast the query executes.
- B. This feature produces a prose summary of the query's logic and leaves the query unchanged, so it would not address a performance problem.
- C. This slash command is designed to evaluate and optimize the performance of selected SQL or code, which is exactly the goal when a correct query runs too slowly.
- D. This feature targets syntax-level mistakes rather than a query that already runs correctly but too slowly, so it would not change execution performance.
5.Reviewing what Genie Code generates
Diffs are where you review Genie Code's work. For /fix and /doc, the proposed change appears beside your original code. Accept replaces your code and Reject keeps the original. Either choice closes Genie Code. Accepting does not run anything, so you get one more chance to read the SQL before it touches the warehouse. Quick Fix is different because its button is Accept and run.
Review matters because Genie Code can make mistakes. Databricks recommends reading any generated code before you run it. For an analyst, the usual risks are a join on the wrong key, a filter on a column whose name looks right but holds different values, or an aggregate that double-counts. Check the tables and columns the query uses against what you asked for, and run it on a small slice before trusting the result.
If the answer is wrong, improve the prompt instead of editing around the problem. Reference the table with @, say what output you expect, and give the response format, such as "provide instructions in numbered steps". Genie Code is built for Databricks languages and dialects and is not meant as a general-purpose programming assistant. It performs best on questions that Databricks documentation, Unity Catalog and the code in your workspace can answer.
Checkpoint 8 of 8· Check yourself
A revenue query that Genie Code generated runs without error, but its totals are about double the figures finance reports. The join looks like it uses the wrong key. What is the recommended next step?
When the generated SQL is wrong, Databricks recommends adding detail to the request rather than working around the problem, and then reviewing the result before running it. /optimize only deals with performance. Diagnose Error needs an error and its stack trace, and this query raised no error. /explain describes a query without changing it.
“If the generated code is not what you wanted, try again by adding more details or information to your comment.”Source: docs.databricks.com
Sources
(6)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.https://docs.databricks.com/aws/en/genie-codeOfficial docs
“It runs in notebooks, the SQL editor, the Lakeflow Pipelines Editor, AI/BI dashboards, and MLflow”
↩︎ What Genie Code is and what it can see“Genie Code is governed by your Unity Catalog permissions, so it can only access data and perform operations that you have permissions for.”
↩︎ What Genie Code is and what it can see“Genie Code is governed by your Unity Catalog permissions, so it can only access data and perform operations that you have permissions for.”
↩︎ Exam trap 4 - 2.
“If you want a direct conversational response without autonomous task execution, say so in your prompt”
↩︎ What Genie Code is and what it can see“When you use Genie Code for the first time, the default mode for every chat is Auto-approve.”
↩︎ What Genie Code is and what it can see - 3.
“already has a compute resource selected (for example, notebooks or the SQL editor), Genie Code automatically uses that compute instead.”
↩︎ What Genie Code is and what it can see“As you type, suggestions automatically appear. Press Tab to accept a suggestion.”
↩︎ Writing queries with autocomplete, inline prompts and table context“To use Genie Code directly in a code cell, press Cmd+I on MacOS or Ctrl+I on Windows.”
↩︎ Writing queries with autocomplete, inline prompts and table context“Pre-run warnings: Yellow underlines highlight opportunities to optimize your query before execution, such as when you are not filtering on a partition column.”
↩︎ Slash commands, and /optimize for slow queries“Post-run analysis: After you run the code, click the Optimize button.”
↩︎ Slash commands, and /optimize for slow queries“when users create a table, they receive a hint recommending CREATE TABLE CLUSTER BY AUTO.”
↩︎ Slash commands, and /optimize for slow queries“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.”
↩︎ Slash commands, and /optimize for slow queries“When code returns errors, Quick Fix automatically recommends fixes for basic errors that can be fixed in a single-line change.”
↩︎ Debugging failed queries: Quick Fix, Diagnose Error and /fix“Click Accept and run to make the recommended fix and continue running your code”
↩︎ Debugging failed queries: Quick Fix, Diagnose Error and /fix“When you click Diagnose error, Genie Code automatically runs /fix.”
↩︎ Debugging failed queries: Quick Fix, Diagnose Error and /fix“Genie Code can help diagnose and suggest fixes for environment failures, including library installation errors.”
↩︎ Debugging failed queries: Quick Fix, Diagnose Error and /fix“If you accept the proposed code, the code does not automatically run.”
↩︎ Reviewing what Genie Code generates“Genie Code uses Unity Catalog metadata to understand your tables, columns, descriptions, and popular data assets across your company”
↩︎ Key concept“When code returns errors, Quick Fix automatically recommends fixes for basic errors that can be fixed in a single-line change.”
↩︎ Exam trap 1“Suggests performance improvements for SQL queries.”
↩︎ Exam trap 2“If you accept the proposed code, the code does not automatically run.”
↩︎ Exam trap 3“Suggests performance improvements for SQL queries.”
↩︎ Prediction“/doc | Comments the code in a diff view”
↩︎ Checkpoint“If the generated code is not what you wanted, try again by adding more details or information to your comment.”
↩︎ Checkpoint - 4.
“autocomplete recognizes that t is an alias for table_name and suggests the columns inside table_name.”
↩︎ Writing queries with autocomplete, inline prompts and table context“Click the Genie Code icon on the right side of the editor to get inline help and suggestions when writing queries.”
↩︎ Writing queries with autocomplete, inline prompts and table context - 5.https://docs.databricks.com/aws/en/genie-code/tipsOfficial docs
“When selecting columns from a DataFrame, you can get more accurate results by providing a starting query.”
↩︎ Writing queries with autocomplete, inline prompts and table context“The structure and detail that Genie Code provides varies from time to time, even for the same prompt.”
↩︎ Writing queries with autocomplete, inline prompts and table context“For the diagnose error feature, the stack trace from the error output.”
↩︎ Debugging failed queries: Quick Fix, Diagnose Error and /fix“provide a statement like SELECT * FROM <table_name>. This allows Genie Code to get the column names and not have to guess.”
↩︎ Checkpoint - 6.
“Databricks recommends that you always review any code generated by Genie Code before running it, because it can sometimes make mistakes.”
↩︎ Reviewing what Genie Code generates“It is not intended to be a general-purpose programming assistant.”
↩︎ Reviewing what Genie Code generates