← VCE Software Development U3O1

Automated debugging with AI tools

Giving an AI tool your code, the error message and the expected behaviour so it suggests a cause and a fix, which you must still understand and test yourself.

Understanding Automated debugging with AI tools in VCE Software Development U3O1

What it does: An assert test runs the fixed function with known input and expected output, so you can confirm the AI's fix really works. The prompt combines all three pieces of information the AI needs: the code, the error message and what the program should do. The traceback shows the error type, the message and where it happened, which helps the AI locate the cause. Logic errors give no traceback. Describing expected and actual output lets the AI find where the logic goes wrong. A syntax error produces a message pointing to the problem. A logic error has no message, so you must describe the wrong behaviour.

Common mistakes: This is a logic error. The program runs with no error message, but it prints 10.0 when the expected output is 110.0. Describing expected vs actual output helps an AI tool find it. The line should be return price * (1 + rate). You still have to test the AI's fix. The string is missing its closing quote, which causes a SyntaxError. The error message you paste into an AI prompt must be stored as a complete string: error = "NameError: total".

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 178–193) and word search (Modules 168–193).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
You get a Python error and want an AI tool to help. Which prompt gives it the best chance of finding the cause?
Write 'my code is broken, fix it' without any code or errorPaste your code, the full traceback and what the program should do
Matches
Prompt: "My code doesn't work. Fix it."
↓
The prompt gives no code, no error message and no expected behaviour, so the AI can only guess at the cause
Applying
Meanings
Term
AI debugging
Meaning
Giving an AI tool your code, the error message and the expected behaviour so it suggests a cause and a fix, which you must still understand and test yourself.
Practice
My Python code has a logic error:
Testing
Gaps
add(2, 3) == 5
Check Answer
Spots
2 rate = 0.1
3 return price * rate

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Cosmic Owl' badge — Comprehension Guru, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. You get a Python error and want an AI tool to help. Which prompt gives it the best chance of finding the cause?
A. Write 'my code is broken, fix it' without any code or error
B. Paste your code, the full traceback and what the program should do ✓
The AI needs the code, the error message and the expected behaviour to suggest a useful cause and fix.
2. What is the most useful part of an error to paste into an AI tool?
A. The whole traceback, including the error type and line number ✓
B. Only the word 'Error' from the message
The traceback shows the error type, the message and where it happened, which helps the AI locate the cause.
3. Your program runs with no error, but it prints 12 when it should print 15. What should you tell the AI?
A. The expected output is 15, the actual output is 12, and here is the code ✓
B. There is no error message, so there is nothing to ask the AI about
Logic errors give no traceback. Describing expected and actual output lets the AI find where the logic goes wrong.
4. Which kind of error is describing expected vs actual output MOST useful for?
A. A logic error, where the program runs but gives the wrong result ✓
B. A syntax error, where Python refuses to run the program at all
A syntax error produces a message pointing to the problem. A logic error has no message, so you must describe the wrong behaviour.
5. An AI tool suggests a fix for your bug. What should you do next?
A. Paste it in and assume it works because an AI wrote it
B. Read it to understand why it works, then run it and test it ✓
AI suggestions can be wrong or can fix one bug and cause another. You must understand and verify the fix yourself.

Match the Pairs

Traceback (most recent call last): File "main.py", line 5 ZeroDivisionError: division by zero → The error message you paste into an AI tool so it can see the error type and the line where the program failed
Expected: 15, Actual: 5 → A description of expected vs actual output that helps an AI find a logic error where there is no error message
After an AI suggests a fix, you verify it by running the program again with test data and checking the output → assert average([10, 20, 30]) == 20
A good debugging prompt includes the code, the error message and the expected behaviour → prompt = code + traceback + "Expected: total of 15"
Prompt: "My code doesn't work. Fix it." → The prompt gives no code, no error message and no expected behaviour, so the AI can only guess at the cause
Paste the AI's fixed code into the project and submit it without running it → The fix was not understood or tested, but AI suggestions can be wrong and must always be checked

Key Term

AI debugging
Giving an AI tool your code, the error message and the expected behaviour so it suggests a cause and a fix, which you must still understand and test yourself.

Fill in the Blanks

1. def add(a, b): return a + b assert add(2, 3) == 5
Hint: Type the keyword that checks the fixed function gives the expected result
2. try: result = 10 / 0 except ZeroDivisionError:
Hint: Type the error name an AI would report for dividing by zero
3. for price in prices: total = total + price
Hint: Type the operator that fixes a logic error so the loop adds up the total
4. expected = 5 actual = average([4, 6]) print(expected == actual)
Hint: Type the comparison operator that checks whether expected and actual output are equal
5. def average(nums): return sum(nums) / len(nums)
Hint: Type the function that counts the items in the list, as in an AI-suggested fix

Spot the Error

Question 1
A def add_gst(price):
B rate = 0.1
C return price * rate
D print(add_gst(100))
Line C — This is a logic error. The program runs with no error message, but it prints 10.0 when the expected output is 110.0. Describing expected vs actual output helps an AI tool find it. The line should be return price * (1 + rate). You still have to test the AI's fix.
Question 2
A code = "print(total)"
B error = "NameError: total
C prompt = code + " " + error
D print(prompt)
Line B — The string is missing its closing quote, which causes a SyntaxError. The error message you paste into an AI prompt must be stored as a complete string: error = "NameError: total".
Question 3
A def double(n):
B return n * 2
C assert double(4) = 8
Line C — assert needs the comparison operator == and not the assignment symbol =. The test should be assert double(4) == 8. Writing a test like this lets you verify that an AI-suggested fix really works.
Question 4
A expected = [1, 2, 3]
B actual = sorted[3, 1, 2]
C print(expected == actual)
Line B — sorted is a function, so it must be called with round brackets: sorted([3, 1, 2]). Square brackets cause a TypeError, and pasting that traceback into an AI tool would point you to this line.
Question 5
A def is_adult(age):
B # 18 should count as adult
C return age > 18
Line C — This is a boundary logic error. The comment says 18 should count as an adult, but > leaves 18 out. The line should be return age >= 18. Test the AI's fix with the boundary value 18.

Student with a class code? Join your class →