AI Powered Software Development
November 17, 2026 2 min read

Prompting for Debugging

HS
HEMANT SINGH
Technical Writer & Educator

What is Prompting for Debugging?

Debugging means finding and fixing errors in a program.

Prompting for Debugging means giving AI the right information about an error so it can identify the root cause and suggest a reliable solution.

For example, suppose your Laravel application displays this error:

SQLSTATE[42S22]: Column not found: 1054
Unknown column 'category_id' in 'where clause'

You could simply ask:

Fix this error.

But this is not a good debugging prompt. AI does not know which query, table or model is involved.

A better prompt provides the error, relevant code, database structure and expected behaviour.

2. The six elements of a debugging prompt


Element

What to provide

1. Error message

Complete error or exception

2. Relevant code

Code where the error occurs

3. Environment

Language, framework and versions

4. Expected behaviour

What should happen

5. Actual behaviour

What is happening instead

6. Previous attempts

What you have already tried

These details help AI investigate instead of guessing.

3. Practical example: Debugging a PHP error

Suppose you have written:

<?php

declare(strict_types=1);

function calculateTotal(int $price, int $quantity): int
{
return $price * $quantity;
}

echo calculateTotal(100, "5");

You receive this error:

TypeError:
Argument #2 ($quantity) must be of type int, string given.

Weak debugging prompt:

Why is my PHP code not working?

Better debugging prompt:

Act as an experienced PHP developer.

I am using PHP 8.3 with strict_types enabled.

Here is my code:

[Paste code]

Error message:

[Paste complete error]

Expected behaviour:
The function should calculate the total price for
a product with a price of 100 and quantity of 5.

Actual behaviour:
PHP throws a TypeError.

Please:
1. Identify the root cause.
2. Explain why the error occurs.
3. Provide the corrected code.
4. Explain whether the solution should use
type conversion or change the input type.
5. Show how to prevent this problem in future.


Advanced technique: Ask AI to investigate before fixing

This is particularly useful when working with AI coding agents such as Google Antigravity, Cursor or Claude Code.

Instead of immediately asking the agent to change files, use a two-stage approach.

Stage 1 — Investigation

Investigate this bug.

Do not modify any files.

Analyze:
1. Relevant source files.
2. Related database queries.
3. Application logs.
4. Possible root causes.

Return:
- Root cause
- Evidence
- Proposed solution
- Files that need modification

Stage 2 — Implementation

Implement the approved solution.

Requirements:
1. Make only necessary changes.
2. Preserve existing functionality.
3. Do not modify unrelated files.
4. Add appropriate tests.
5. Run the relevant tests.
6. Report all changes.