DEV Community

LearnAI Resource
LearnAI Resource

Posted on

Stop Throwing Error Messages at ChatGPT: A Better Way to Debug with AI

You know that moment? Stack trace hits your terminal, you copy-paste the whole thing into ChatGPT, and get back some generic "try clearing your cache" nonsense. Yeah, that sucks.

The thing is, AI tools are actually really good at debugging — but only if you feed them right. Here's how I actually use AI in my workflow, and why it works way better than the error-dump approach.

The Problem with Error Dumps

When you paste a raw stack trace into an AI, it's playing detective with incomplete evidence. It doesn't know:

  • What you were trying to do
  • What you changed right before the error
  • Your project structure or dependencies
  • The actual business logic around that code

So it guesses. And guesses suck.

The Better Approach: Provide Context First

Here's my actual workflow:

Step 1: Write it down (yes, really)
Before talking to AI, I write a 2-3 sentence description:

I'm trying to paginate results in a Next.js API route. 
The limit/offset params work fine, but the total count 
is returning wrong when filtering by date range.
Enter fullscreen mode Exit fullscreen mode

This forces me to think through what's actually broken, not just "why broken."

Step 2: Show, don't tell
Instead of the full trace, I paste:

  • The specific function that's failing (10-20 lines max)
  • The test case that's breaking
  • The actual vs. expected output
// This is what's running
const getPostCount = async (filters) => {
  return db.posts
    .where('createdAt').gte(filters.startDate)
    .where('createdAt').lte(filters.endDate)
    .count();
};

// Expected: 15, Actual: 42
Enter fullscreen mode Exit fullscreen mode

Step 3: Ask a real question
Not "why is this broken?" but "is the timezone handling on createdAt off, or is the filter logic wrong?"

This turns a debugging session into an actual conversation.

What Changed

When I do this, the AI response goes from vague to specific. It asks good follow-up questions. It sometimes spots that the bug isn't in the code I showed — it's in the data layer or the test setup.

Most importantly: I solve the bug in one conversation instead of four. No more copy-pasting multiple attempts.

Real Example: The Timezone Thing

I had a date range filter that worked fine in my timezone but broke for users in UTC. If I'd dumped the error into ChatGPT, it would've said "check your timezone handling." Which... I obviously knew.

Instead, I told Claude: "Date filters work in PT but return 0 results in UTC. The dates in the database are stored as ISO strings."

Boom. Five seconds of thinking, and it caught that I was comparing ISO strings with timestamp objects in the filter logic.

Try This Today

Next time you're stuck:

  1. Write one sentence: What was I building when this broke?
  2. Show the code: The actual failing function, not the whole file
  3. Show the output: What it returns vs. what you need
  4. Ask specific: Not "why broken" but which part you think might be wrong

You'll actually be amazed how fast this works. It's not that AI tools got better at debugging — it's that feeding them real context works way better than error dumps.

One More Thing

If you're doing this kind of work regularly, check out LearnAI Weekly — it's a newsletter that actually covers how to work with AI tools, not just hype about what AI tools exist. Real workflows, real examples, none of the fluff.


What's your debugging workflow like? Hit me with your hot take in the comments. Do you still throw full stack traces at AI, or have you found something that works better?

Top comments (0)