CertSafari
    Databricks Certified Data Analyst Associate· Lessons

    Domain 4 · Lesson 9/39

    Databricks Assistant (Genie Code) for SQL Query Writing and Debugging

    Utilize Databricks Assistant within a Notebook or SQL Editor to facilitate query writing and debugging.

    17 min read
    2.56% of exam
    8 sources
    Published 3 Oct 2026
    Docs as of 30 Sep 2026

    What you will be able to do

    • Open the Databricks Assistant (Genie Code) in a notebook cell, the notebook pane, and the SQL editor, and know which compute it uses to run code
    • Write queries faster by using autocomplete, natural-language prompts, @ references and well-documented Unity Catalog metadata
    • Pick the right slash command (/explain, /fix, /doc, /findTables, /optimize, /prettify) for a query task
    • Tell Quick Fix, Diagnose Error and /fix apart, and know which Accept button runs code and which does not
    • Use /optimize's pre-run warnings, post-run analysis and table-level suggestions to improve a SQL query

    Key concept

    Databricks Assistant (Genie Code) — The exam guide calls it the Databricks Assistant. The current documentation pages for this feature call it Genie Code. It is a context-aware AI helper built into notebooks and the SQL editor. It reads the code you are working on and your Unity Catalog metadata, then generates, explains, fixes and optimizes queries for you to review before you run them.

    1.Where the assistant lives: notebooks and the SQL editor

    The exam guide asks you to use the Databricks Assistant "within a Notebook or SQL Editor". The documentation pages for this feature now use the name Genie Code, so expect to see both names. The tool does the same jobs in both places. It generates SQL or Python from plain-English requests, explains code, debugs errors, and transforms, optimizes or refactors existing code. What changes from one surface to the other is how you open it.

    In a notebook you can reach the assistant in two ways: the Genie Code pane at the side, or inline inside a code cell. To work inline, press Cmd+I (macOS) or Ctrl+I (Windows). A text box appears in the cell. Type your request and press Enter, not Shift+Enter. In a notebook, Shift+Enter runs the cell, so pressing it here would not send your prompt to the assistant. You can also mention Genie Code in a notebook comment to get help in that comment thread.

    In the SQL editor the assistant is a chat window you open from the Genie Code icon. The write-queries page describes the left pane as the place to find workspace files, browse data objects and get help from Genie Code. It also says to click the Genie Code icon on the right side of the editor for inline help while you write. In both cases you can click a suggested question or type your own. The SQL editor overview lists the integrated assistant as a key feature: you chat with it to write, refine or understand queries, and you can run its code straight from the side pane.

    Which compute runs that code? By default Genie Code uses serverless compute. But the notebook and the SQL editor already have compute attached, and on a page like that Genie Code uses the attached compute instead. If you don't have serverless access, you need some other compute available before you can run code from the Genie Code panel.

    Checkpoint 1 of 9· Check yourself

    An analyst has a SQL editor tab attached to a running SQL warehouse. They ask the Databricks Assistant (Genie Code) to write a query and run it from the side pane. Which compute runs the query?

    Sources123

    2.Writing queries: autocomplete, prompts and context

    The lightest form of help is AI-based autocomplete, which works in notebooks, the SQL editor and the file editor. Suggestions appear as you type, and Tab accepts one. To ask for a suggestion yourself, press Option+Shift+Space on macOS or Control+Shift+Space on Windows. Autocomplete can also generate code from a comment, so a line such as a comment describing the query you want can become the query. The docs add that autocomplete may perform better in the Genie Code pane than in a notebook cell.

    For whole queries you describe the result you want in plain English. This works because Genie Code doesn't only see your words. The docs list the context it uses:

    What Genie Code reads when it answers a prompt
    Context sourceHow it helps query writing
    Code or queries in the current notebook cell or Databricks SQL editor tabLets it explain, fix or extend what you have already written
    Table and Column names and descriptionsLets it map plain-English terms, such as a State column, to real identifiers
    Previous prompt questionsLets you refine a previous answer without rewriting the whole prompt
    Favorite and active tablesPoints it toward the data you are actually working with
    The stack trace from the error output (diagnose error feature)Gives it the failure details it needs to propose a fix

    You can also add context on purpose. Type @ followed by a resource name, such as @<table-name>, or click Add context to attach tables, queries, notebooks or files. Every item you attach stays listed at the top of the prompt box for the rest of the chat. In notebooks, @cell lets you point at a particular cell's code or output. To find data you don't know yet, ask "Find tables" or use /findTables.

    Two habits make the generated SQL more accurate. First, give it a starting query. If the assistant has already seen a statement that selects from a table, it can read the column names instead of guessing them. The SQL editor documentation includes a sample query that does this job:

    A plain starting query in a SQL editor tab gives Genie Code the real column names to build onsql
    SELECT
      o_orderdate,
      o_orderkey,
      o_custkey,
      o_totalprice,
      o_shippriority
    FROM
      samples.tpch.orders

    Second, document your tables and columns in Unity Catalog. The docs give the example of a height column stored as a string like '6-2'. A comment that explains this format tells the assistant how to read the values. Finally, be specific about what you want back, such as the level of detail, the structure of the answer, or which library to use. The same prompt can produce differently structured answers from one try to the next.

    Checkpoint 2 of 9· Check yourself

    Why does giving Genie Code a starting query such as a SELECT statement from a table make its generated SQL more accurate?

    Sources14

    3.Slash commands: shortcuts for common query tasks

    Many requests come up again and again, so they have slash commands, which are shortcuts that start a common prompt. Typing just / shows the list. These are the commands an analyst uses when writing and tidying queries:

    Genie Code slash commands and what each does
    CommandWhat Genie Code does
    /explainProvides an explanation of the code in a cell
    /docComments the code in a diff view
    /fixProposes a fix to any code errors in a diff view
    /findTablesSearches for relevant tables based on Unity Catalog metadata
    /findQueriesSearches for relevant queries based on Unity Catalog metadata
    /optimizeSuggests performance improvements for SQL queries
    /prettifyFormats SQL queries for readability

    You can control how much detail /explain gives by adding a phrase such as "be concise" or "explain code line-by-line". Notice that /fix and /doc do not edit your code directly. Each one shows its proposal in a diff view, where you choose Accept or Reject. The next section explains what Accept does and doesn't do.

    Checkpoint 3 of 9· Match them up

    Match each slash command to the task an analyst would use it for

    Tap a term, then the definition that fits it.

    Checkpoint 4 of 9· 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?

    Sources1

    4.Debugging: Quick Fix, Diagnose Error and /fix

    When a query fails, the assistant offers help at three levels. Each one fits a different kind of error, and the exam expects you to tell them apart.

    Quick Fix appears on its own when an error is simple, meaning one that a single-line change can fix, such as a misspelled column name. You don't need to ask for it. Diagnose Error is a button that appears in the cell results when an error occurs. The features page says it analyzes more complex errors and attempts to fix them. Behind the scenes, clicking it just runs /fix. You can also describe the problem in the Genie Code pane, or click Debug to step through code line by line with breakpoints.

    The difference is in the buttons. A Quick Fix offers Accept and run, which applies the one-line change and continues running your code. A /fix (or /doc) proposal shows up in a diff window with Accept and Reject. Accept writes the proposal into your code but does not run it, so you get a chance to review it first. If the proposal is wrong, try again with more detail in your prompt. The assistant closes automatically after you accept or reject.

    Choosing a debugging path
    FeatureWhen it appliesWhat accepting does
    Quick FixBasic errors that can be fixed in a single-line change; it appears automaticallyAccept and run applies the fix and continues running your code
    Diagnose ErrorButton in the cell results when an error occurs; for more complex errorsRuns /fix, so the proposal arrives in a diff view
    /fixYou type it, or Diagnose Error triggers itAccept changes the code but does not run it

    One more difference matters if your team customizes the assistant. Custom user or workspace instructions, such as coding conventions, apply to almost every response, including chat, inline suggestions and Suggest Fix. They do not apply to Quick Fix or Autocomplete.

    Checkpoint 5 of 9· Check yourself

    A SQL cell fails with a long, multi-part error. No single-line Quick Fix is offered. The analyst clicks the Diagnose Error button in the cell results. What happens?

    Checkpoint 6 of 9· 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?

    Sources15

    5.Optimizing queries with /optimize

    A query can be correct and still be slow. The /optimize command evaluates code and suggests performance improvements. The SQL editor documentation names it specifically as the way to ask Genie Code to evaluate and optimize queries. To use it explicitly, open Genie Code from a notebook cell or the SQL editor, type /optimize, click Generate, and click Accept to apply the suggestions.

    Checkpoint 7 of 9· Put it in order

    Put the steps for running /optimize on a query in order

    1. 1.In a notebook cell or the SQL editor, click the Genie Code icon
    2. 2.To use the optimization suggestions from Genie Code, click Accept
    3. 3.In the prompt box, type /optimize, and click the Generate button

    /optimize also helps at three points that don't need a typed prompt:

    The three ways /optimize surfaces suggestions
    ModeWhenWhat you see
    Pre-run warningsBefore executionYellow underlines, for example when you are not filtering on a partition column; hover to see the suggestion
    Post-run analysisAfter you run the codeAn Optimize button to click
    Table-level suggestionsWhen you create a tableA hint recommending CREATE TABLE CLUSTER BY AUTO

    Checkpoint 8 of 9· 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?

    Sources1

    6.Reviewing what the assistant produces

    Everything above ends with you making the decision. Databricks says to review generated code before you run it, because the assistant can make mistakes. That is why the diff view requires an Accept, and why accepted /fix code does not run on its own. The assistant is also limited to what you are allowed to do. It works within your Unity Catalog permissions, so it cannot read data or run operations that you couldn't.

    Genie Code runs in Agent mode. In this mode it can plan multi-step work, run code and fix errors on its own. Genie Code asks for your permission before running code in the chat. Approval modes control how often it asks. Auto-approve is the default for first-time users, and an AI classifier checks each action against your request. If you only want an explanation, say so in the prompt, for example "Just explain this to me, don't run any code."

    Checkpoint 9 of 9· Check yourself

    Which statement about queries generated by the Databricks Assistant (Genie Code) is accurate?

    Sources647

    Exam traps

    Each one states something that sounds right. Open it to see what is actually true.

    1. 1.Clicking Accept on a /fix or /doc suggestion re-runs the cell with the corrected code.Why is that wrong?

      The diff-view Accept only puts the proposed code in place. It does not run it, so you review it and run it yourself. Only Quick Fix's "Accept and run" continues running your code.

      Covered in Debugging: Quick Fix, Diagnose Error and /fix

    2. 2.Quick Fix is the tool for any query error, including complex multi-part failures.Why is that wrong?

      Quick Fix only covers basic errors that a single-line change can fix. For more complex errors, use Diagnose Error, which runs /fix.

      Covered in Debugging: Quick Fix, Diagnose Error and /fix

    3. 3.After typing a prompt into the inline Cmd+I box in a notebook cell, press Shift+Enter to submit it.Why is that wrong?

      Press Enter to have Genie Code generate a response. Shift+Enter is the shortcut for running a cell.

      Covered in Where the assistant lives: notebooks and the SQL editor

    4. 4.Custom workspace instructions, such as naming conventions, shape every Genie Code suggestion, including Quick Fix and Autocomplete.Why is that wrong?

      Instructions apply to chat, inline suggestions and Suggest Fix, but Quick Fix and Autocomplete are the exceptions.

      Covered in Debugging: Quick Fix, Diagnose Error and /fix

    Sources

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “To use Genie Code directly in a code cell, press Cmd+I on MacOS or Ctrl+I on Windows.”
      ↩︎ Where the assistant lives: notebooks and the SQL editor
      “As you type, suggestions automatically appear. Press Tab to accept a suggestion.”
      ↩︎ Writing queries: autocomplete, prompts and context
      “Slash commands are a shortcut for creating common prompts.”
      ↩︎ Slash commands: shortcuts for common query tasks
      “Click Accept and run to make the recommended fix and continue running your code”
      ↩︎ Debugging: Quick Fix, Diagnose Error and /fix
      “Pre-run warnings: Yellow underlines highlight opportunities to optimize your query before execution, such as when you are not filtering on a partition column.”
      ↩︎ Optimizing queries with /optimize
      “Table-level suggestions: For example, when users create a table, they receive a hint recommending CREATE TABLE CLUSTER BY AUTO.”
      ↩︎ Optimizing queries with /optimize
      “Genie Code uses Unity Catalog metadata to understand your tables, columns, descriptions, and popular data assets across your company and provide personalized responses.”
      ↩︎ Key concept
      “If you accept the proposed code, the code does not automatically run.”
      ↩︎ Exam trap 1
      “When code returns errors, Quick Fix automatically recommends fixes for basic errors that can be fixed in a single-line change.”
      ↩︎ Exam trap 2
      “press Enter (not Shift+Enter, like you would to run a cell) to have Genie Code generate a response.”
      ↩︎ Exam trap 3
      “already has a compute resource selected (for example, notebooks or the SQL editor), Genie Code automatically uses that compute instead.”
      ↩︎ Checkpoint
      “Formats SQL queries for readability.”
      ↩︎ Checkpoint
      “If you accept the proposed code, the code does not automatically run.”
      ↩︎ Prediction
      “When you click Diagnose error, Genie Code automatically runs /fix.”
      ↩︎ Checkpoint
      “In the prompt box, type /optimize, and click the Generate button.”
      ↩︎ Checkpoint
    2. 2.
      “Use the left pane in the SQL editor to find workspace files, view data objects, and get help from Genie Code.”
      ↩︎ Where the assistant lives: notebooks and the SQL editor
      “Click the Genie Code icon on the right side of the editor to get inline help and suggestions when writing queries.”
      ↩︎ Where the assistant lives: notebooks and the SQL editor
    3. 3.
      “Chat with Genie Code to help you write, refine, or understand queries. Run code generated by Genie Code from the side pane.”
      ↩︎ Where the assistant lives: notebooks and the SQL editor
    4. 4.
      “Code or queries in the current notebook cell or Databricks SQL editor tab.”
      ↩︎ Writing queries: autocomplete, prompts and context
      “This allows Genie Code to get the column names and not have to guess.”
      ↩︎ Writing queries: autocomplete, prompts and context
      “you can ask Genie Code to alter the output of a previous response without having to rewrite the entire prompt.”
      ↩︎ Writing queries: autocomplete, prompts and context
      “Genie Code asks for your permission before running code in the chat.”
      ↩︎ Reviewing what the assistant produces
    5. 5.
      “Diagnose error Genie Code analyzes more complex errors, including environment errors, and attempts to fix them.”
      ↩︎ Debugging: Quick Fix, Diagnose Error and /fix
      “Databricks recommends that you always review any code generated by Genie Code before running it, because it can sometimes make mistakes.”
      ↩︎ Checkpoint
    6. 6.
      “Genie Code is governed by your Unity Catalog permissions, so it can only access data and perform operations that you have permissions for.”
      ↩︎ Reviewing what the assistant produces
    7. 7.
      “Auto-approve is a productivity feature, not a security boundary.”
      ↩︎ Reviewing what the assistant produces

    Also cited

    Spotted a mistake, or was something unclear? Tell us.