/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
- Run a cell that produces an error
- With the error cell selected, type
/fixin the chat
The AI analyzes the error and your code to suggest a fix.
How It Works
When you use /fix:
- The AI reads the error message from the failed cell
- It examines the code that caused the error
- It considers the context of surrounding cells
- 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 failError:
ZeroDivisionError: division by zeroStep 2: Use /fix
With the error cell selected, type in chat:
/fixStep 3: Get the solution
The AI responds with:
Error:
ZeroDivisionError: division by zeroCause: The function doesn’t handle empty lists. When
numbersis 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 3Complex 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 claudeThis 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]