Explain and fix errors with Gemini assistance

This document describes how you can use Gemini in Colab Enterprise, which is a product in the Gemini for Google Cloud portfolio, to help you explain and fix errors in a Colab Enterprise notebook.

Learn how and when Gemini for Google Cloud uses your data.

This document is intended for data analysts, data scientists, and data developers who work with Colab Enterprise. It assumes you have knowledge of how to write code in a notebook environment.

Overview

When you run code that generates an error, Gemini in Colab Enterprise can suggest a fix or explain the error to help you resolve the issue.

For syntax errors, a Fix error button appears. Click this button to see a suggested fix for your code. For more details, see Fix errors.

For other types of errors, an Explain error button appears. Click this button to see an explanation of the error and potential ways to resolve it. For more details, see Use error explanations.

Before you begin

  1. Ensure that Gemini in Colab Enterprise is set up for your Google Cloud user account and project.
  2. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  3. Enable the Vertex AI, Cloud AI Companion, Dataform, and Compute Engine APIs.

    Enable the APIs

  4. Enable the Vertex AI, Cloud AI Companion, Dataform, and Compute Engine APIs.

    Enable the APIs

Required roles

To get the permissions that you need to use Gemini in Colab Enterprise, ask your administrator to grant you the following IAM roles on the project:

For more information about granting roles, see Manage access to projects, folders, and organizations.

You might also be able to get the required permissions through custom roles or other predefined roles.

Use error explanations

To use Gemini for Google Cloud to explain errors in your code:

  1. In the Google Cloud console, go to the Colab Enterprise My notebooks page.

    Go to My notebooks

  2. In the Region menu, select the region that contains your notebook.

  3. Click the notebook that you want to open.

  4. In a code cell of your notebook, enter code that contains an error, and then run the cell. For example, you might enter print(a + random()) without defining a.

    After your code cell runs, Colab Enterprise prints an error message below your code cell. If Gemini in Colab Enterprise has an explanation for this error, an Explain error button appears.

  5. Click the Explain error button.

    Colab Enterprise opens a chat dialog that contains an explanation of the error. The dialog might also include recommendations and suggested changes for how to resolve the problem.

  6. After evaluating the content, you can do any of the following:

    • To copy a suggested change, click the  Copy button. Then paste the code into a code cell in your notebook.
    • To add a code cell to your notebook that contains the suggested change, click the  Add code cell button. Adding the code cell doesn't remove the original code cell with the error in it.
    • Use the chat dialog to discuss the error with Gemini.
  7. To close the chat dialog, click  Close.

Fix errors

To use Gemini for Google Cloud to help you fix syntax errors in your code:

  1. In the Google Cloud console, go to the Colab Enterprise My notebooks page.

    Go to My notebooks

  2. In the Region menu, select the region that contains your notebook.

  3. Click the notebook that you want to open.

  4. In a code cell of your notebook, enter code that contains an error, and then run the cell. For example, you might enter print(1, which is missing a closing parenthesis.

    After your code cell runs, Colab Enterprise prints an error message below your code cell. If Gemini in Colab Enterprise has a suggestion that might fix your code, a Fix error button appears.

  5. Click the Fix error button.

    Colab Enterprise shows you a suggested fix to the code.

  6. Evaluate the suggestion, and then do one of the following:

    • To accept the suggestion, click  Accept suggestion.
    • To reject the suggestion, click  Reject suggestion.

Turn off Gemini in Colab Enterprise

To turn off Gemini in Colab Enterprise for a Google Cloud project, an administrator must turn off the Gemini for Google Cloud API. See Disabling services.

To turn off Gemini in Colab Enterprise for a specific user, an administrator needs to revoke the Gemini for Google Cloud User (roles/cloudaicompanion.user) role for that user. See Revoke a single IAM role.

What's next