(+351) 21 24 10006  ·  info@bconcepts.pt
Carnaxide, Lisbon

How to fix code errors in a Fabric Notebook with Copilot

João Barros 06 de July de 2026 4 min read

An error in a single cell can block your whole analysis and cost you time hunting for the cause. In Microsoft Fabric, Copilot helps you fix code errors right inside the Notebook: it summarises what went wrong, explains the likely cause and suggests a ready-to-apply correction. Below is the step-by-step way to solve a real PySpark error with the /fix command.

Note: Copilot features in Fabric Notebooks are in preview and change often. Button and command names may differ slightly in your version.

Prerequisites

  • A Microsoft Fabric capacity with Copilot available (F2 or higher, or a trial).
  • Your tenant administrator must have enabled the Copilot switch.
  • A Fabric Notebook attached to a Lakehouse with at least one Delta table.
  • Basic knowledge of Python and PySpark.

Step 1: Turn on Copilot in the Notebook

Open your Notebook and, on the ribbon, click the Copilot button. Fabric adds an initialisation cell at the top of the Notebook — run that cell to load Copilot. Once it finishes, the chat pane opens on the right.

Copilot only works with an active Spark session. If you haven't run anything yet, run a simple cell first so the session starts and your data is reachable:

df = spark.read.format("delta").load("Tables/vendas")
df.show(5)

Step 2: Reproduce an error

To see Copilot in action, deliberately run a cell with a common mistake. Notice the misspelled grouBy method:

df = spark.read.format("delta").load("Tables/vendas")
df.select("Regiao", "Total").grouBy("Regiao").sum("Total").show()

Fabric shows a message similar to AttributeError: 'DataFrame' object has no attribute 'grouBy'. Before moving on, always read the last line of the error: it usually points to exactly what failed. Typos in method or column names are among the most frequent PySpark mistakes, so this is a good case to test Copilot.

Step 3: Ask for the fix with the /fix command

When a cell fails, Fabric shows the Fix with Copilot option below the output. Alternatively, select the failing cell and type the /fix command in the Copilot pane:

/fix

Copilot reads the error message and the code, gives a summary of the cause (the grouBy method does not exist in PySpark) and proposes the corrected version. You can use /fix for a single cell or for the whole Notebook. The Fix with Copilot button focuses on the failing cell; the /fix command in the pane gives you more context and lets you keep the conversation going with follow-up questions.

Step 4: Review and apply the fix

Always read the suggestion before accepting it — Copilot can be wrong. Here it proposes replacing grouBy with groupBy:

df = spark.read.format("delta").load("Tables/vendas")
df.select("Regiao", "Total").groupBy("Regiao").sum("Total").show()

Click Insert to place the corrected code in the cell (or copy the block) and run it again. If you want to understand the cause rather than just copy the solution, use the /explain command in the same cell: Copilot explains, line by line, what the code does.

Check the result

The cell stops failing and now shows a table with the total per region. Confirm that:

  • No red error message appears below the cell any more.
  • The result has the columns Regiao and sum(Total).
  • The summed values make sense for your data.

Tip: fix one error at a time and rerun the cell after each change — that way you know which correction solved the problem and you avoid introducing new mistakes.

Conclusion

With Copilot's /fix command you fixed a PySpark error without leaving the Fabric Notebook. From here, try /explain to learn from every correction, /comments to document your code and /optimize to improve performance. What was the last error that cost you too much time — and how could Copilot have helped?