---
title: Tips to improve Genie Code responses
description: Get better Genie Code responses with specific prompts, @ references to tables and cells, attached images, and well-documented Unity Catalog tables and columns.
canonical_url: https://docs.databricks.com/aws/en/genie-code/tips
---

# Tips to improve Genie Code responses

<a id="tips" />

Genie Code responses improve dramatically with specific prompts and clear context. Be explicit about what you want, reference tables and notebook cells with `@`, attach images when text is insufficient, and document your tables and columns in Unity Catalog so Genie Code understands your schema.

You can also tailor Genie Code to your needs in the following ways:

* Provide [instructions](https://docs.databricks.com/aws/en/genie-code/instructions.md) to customize Genie Code to your preferences.
* Create [agent skills](https://docs.databricks.com/aws/en/genie-code/skills.md) to expand Genie Code's capabilities.
* Add [MCP servers](https://docs.databricks.com/aws/en/genie-code/mcp.md) to connect Genie Code to external tools and data sources.

## Write specific prompts

The structure and detail that Genie Code provides varies from time to time, even for the same prompt. Try to provide Genie Code as much guidance as you can to help it return the information you want in the desired format, level of detail, and so on. Consider doing the following:

* Specify the level of detail you're looking for. For example, "Explain this code in a couple sentences" or "Explain this code line-by-line."
* Specify which library you want Genie Code to use. For example, "Create a visualization using Matplotlib" or "Create a visualization using Seaborn."
* Specify the structure of the response you want. For example, "Provide instructions in numbered steps" or "Provide instructions with the steps as bullet points with brief explanations."
* Be specific in your prompts. Genie Code knows about your table and column schema and metadata, so you can use natural language to ask your question. For example, "List active and retired NFL quarterbacks' passing completion rate, for those who had over 500 attempts in a season." Genie Code answers using data from columns such as `s.player_id` and `s.attempts`.

## <a id="context" />Genie Code uses context to provide better answers

You can provide Genie Code with specific context, such as tables, pipelines, notebooks, queries, and files. In the Genie Code chat pane, click **![At icon.](https://docs.databricks.com/aws/en/images/product-icons/AtIcon.svg) Add context** to manually select the resource you want to provide it. You can also reference context by typing `@<resource-name>` in the chat prompt. Each selected context is listed at the top of the prompt box and persists in the chat.

In notebooks, you can also reference specific cells. Click **![At icon.](https://docs.databricks.com/aws/en/images/product-icons/AtIcon.svg) Add context**, select **Cells**, and then select the cell you want to reference. You can also type `@cell` in the chat prompt and select a cell from the list that appears. This is useful when you want to ask Genie Code about a specific cell's code or output.

In addition to the context you manually provide, Genie Code 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 Genie Code to generate a list of users who live in Michigan.

Genie Code 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.

Because Genie Code uses your conversation history to provide better and more accurate answers, you can ask Genie Code to alter the output of a previous response without having to rewrite the entire prompt. Use Genie Code's chat history to iteratively clean, explore, filter, and slice DataFrames in the Genie Code pane.

## <a id="images" />Attach images to prompts

You can attach images to your Genie Code prompts. To attach an image, use any of the following methods:

* Copy and paste an image directly into the chat prompt.
* Drag and drop an image into the chat prompt.
* Click ![New icon.](https://docs.databricks.com/aws/en/images/product-icons/PlusIcon.svg) the plus icon, then **![Image icon.](https://docs.databricks.com/aws/en/images/product-icons/ImageIcon.svg) Attach image** to select an image from your local machine.

Images are useful when they add information that you can't easily or accurately convey with text alone. Consider attaching images when:

* You need to provide visual information that Genie Code doesn't have access to. Genie Code can see images and charts in your workspace files and notebooks, so you only need to attach external images.
* You want help understanding visual content, such as diagrams, flowcharts, architecture sketches, slide screenshots, or whiteboard photos.
* You're asking about external data that's shown, not described, such as graphs, charts, dashboards, or reports where trends, anomalies, or labels matter.
* You need text extracted from an image, such as photos or scans of documents, handwritten notes, or labels and signs.
* You're working with real-world photos and want to ask about what's happening in the image, describe scenes for documentation, or check whether something matches a specification.

## <a id="datasets" />Help Genie Code work with datasets

Genie Code can access context about the tables you're working with. Here are some things you can do to help it respond better when working with datasets:

* When searching for a table, use the prompt "Find tables" or the command `/findTables` for better responses. For example, "Find tables related to NFL games."

* Use `@<table-name>` to reference a specific table in a prompt. You can also manually select the table by clicking **![At icon.](https://docs.databricks.com/aws/en/images/product-icons/AtIcon.svg) Add context** in the chat. Genie Code tailors its responses to use that table.

* 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 Genie Code to get the column names and not have to guess.

* 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."

* Document tables and columns in Unity Catalog. See [Add AI-generated comments to Unity Catalog objects](https://docs.databricks.com/aws/en/comments/ai-comments.md). This gives Genie Code more context on the data. 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 Genie Code 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](https://docs.databricks.com/aws/en/comments/index.md).

## <a id="code" />Edit and run code in the Genie Code chat pane

Run code in Genie Code pane to validate it or use it as a scratchpad. Code execution is available on all pages in Databricks. Genie Code defaults to the current compute resource of the page you're on. If there's no compute resource currently in use, Genie Code uses serverless compute resources. By default, Genie Code uses auto-approve to run code in the chat. To approve each request yourself, change the approval mode. See [Approve tool actions](https://docs.databricks.com/aws/en/genie-code/navigate-genie-code.md#approve-tools). After the code runs, output is displayed directly in the chat pane.

The tabs below show examples for Python and SQL code:

### Python

![Run Python code in the Genie Code pane.](https://assets.docs.databricks.com/_static/images/assistant/run-code-in-assistant.gif)

### SQL

![Run SQL code in the Genie Code pane.](https://assets.docs.databricks.com/_static/images/notebooks/run-code-sql.gif)

## Use `Shift + Enter` to add a new line in the chat text box

Use `Shift + Enter` to add a new line in the Genie Code chat text box. This makes it easy to format and organize your messages to Genie Code.

## Use cell actions in a notebook

Cell actions include shortcuts to common tasks, such as documenting (commenting), fixing, and explaining code.

![/doc cell action prompts Genie Code to comment the code.](https://assets.docs.databricks.com/_static/images/assistant/cell-action-doc.gif)

## Additional resources

* To customize Genie Code to your preferences, provide [instructions](https://docs.databricks.com/aws/en/genie-code/instructions.md).
* To expand Genie Code's custom capabilities, create [agent skills](https://docs.databricks.com/aws/en/genie-code/skills.md).
* To give Genie Code access to external tools and data sources, connect it to [MCP servers](https://docs.databricks.com/aws/en/genie-code/mcp.md).
* [Genie Code Tips and Tricks for Data Analysts](https://www.databricks.com/blog/databricks-assistant-tips-and-tricks-data-analysts)
* [Genie Code Tips and Tricks for Data Engineers](https://www.databricks.com/blog/5-tips-get-most-out-your-databricks-assistant)
