/fix Command

The /fix command helps you debug errors in your notebook. When code fails, use /fix to get an explanation of the error and a suggested solution.

Basic Usage

  1. Run a cell that produces an error
  2. With the error cell selected, type /fix in the chat

The AI analyzes the error and your code to suggest a fix.

How It Works

When you use /fix:

  1. The AI reads the error message from the failed cell
  2. It examines the code that caused the error
  3. It considers the context of surrounding cells
  4. It provides an explanation and fix

Example Workflow

Step 1: Run code with an error

def calculate_average(numbers):
    total = sum(numbers)
    return total / len(numbers)

result = calculate_average([])  # This will fail

Error:

ZeroDivisionError: division by zero

Step 2: Use /fix

With the error cell selected, type in chat:

/fix

Step 3: Get the solution

The AI responds with:

Error: ZeroDivisionError: division by zero

Cause: The function doesn’t handle empty lists. When numbers is empty, len(numbers) is 0, causing division by zero.

Fix:

def calculate_average(numbers):
    if not numbers:
        return 0  # or raise an exception
    total = sum(numbers)
    return total / len(numbers)

Common Error Types

Import Errors

import nonexistent_module

/fix suggests: checking the module name, installing the package, or finding alternatives.

Type Errors

"hello" + 5

/fix explains type incompatibility and shows how to convert types.

Index Errors

my_list = [1, 2, 3]
print(my_list[10])

/fix identifies the out-of-bounds access and suggests bounds checking.

Attribute Errors

my_string = "hello"
my_string.push("!")

/fix points out that strings don’t have push and suggests the correct method.

Syntax Errors

def my_function(
    print("hello")

/fix identifies missing parentheses or other syntax issues.

Tips

Select the Right Cell

Make sure the cell with the error is selected before using /fix.

Provide Context

If the error involves multiple cells, you can mention that:

/fix - the data comes from cell 3

Complex Errors

For complex errors, add context:

/fix - I'm trying to merge two dataframes on 'user_id'

Multiple Errors

Fix one error at a time. After fixing one, re-run and use /fix again if needed.

Alternative: %ai error

You can also use line magic for errors:

%ai error claude

This sends the last error to the specified model for analysis.

When /fix Can’t Help

Some issues are beyond syntax or runtime errors:

  • Logic errors (code runs but gives wrong results)
  • Performance issues
  • Design problems

For these, describe the issue in chat:

The code runs without errors but the output is wrong.
Expected: [1, 2, 3]
Got: [3, 2, 1]