DEV Community

전규현 (Jeon gyuhyeon)
전규현 (Jeon gyuhyeon)

Posted on

Why AI Code Generation Fails: The Communication Problem

"I asked ChatGPT to make a login feature, but it gave me weird code."

I hear this complaint frequently lately. GitHub Copilot, ChatGPT, Claude... AI tools are flooding in, but production-ready code isn't coming out.

Is AI the problem? No.

The problem is how we communicate with AI.

What We Asked AI vs What We Got

Let's look at a real case.

Developer's Request

"Make a login feature"

AI's Result

def login(username, password):
    if username == "admin" and password == "password":
        return {"status": "success"}
    return {"status": "failed"}
Enter fullscreen mode Exit fullscreen mode

Developer's Reaction

"What is this? AI is not good..."

Wait, who made the mistake here?

Junior Developer vs AI: Same Mistake

What happens if you just tell a junior developer "make a login feature"?

You'll probably get questions like:

  • "What framework should I use?"
  • "What database?"
  • "Session? JWT?"
  • "Social login too?"
  • "Any password rules?"

But AI doesn't ask questions. It just gives the most generic answer.

Garbage In, Garbage Out

There's an old computer science saying:
"Garbage in, garbage out"

In the AI era, it's changed to:
"Ambiguous request in, ambiguous code out"

Let's look at actual test results:

Test 1: Ambiguous Request

Request: "Make a user management feature"
Result: Basic CRUD skeleton (30 lines)
Practicality: 10%
Enter fullscreen mode Exit fullscreen mode

Test 2: Specific Request

Request: "Make a user management API with Django REST Framework.
- Email authentication
- JWT token
- Permission groups (admin, user)
- Profile image upload
- Soft delete
- Pagination"

Result: High-quality code (500 lines)
Practicality: 85%
Enter fullscreen mode Exit fullscreen mode

See the difference?

The Art of Communicating with AI

AI is a slave to context. It only understands and implements as much information as we provide.

Structure of a Good Prompt

1. Background

   - Project type
   - Technology stack
   - Constraints

2. Specific Requirements

   - Feature list
   - Non-functional requirements
   - Edge cases

3. Examples or References
   - Similar code
   - API documentation links
   - Desired output format
Enter fullscreen mode Exit fullscreen mode

Real Example: Payment System

❌ Bad Request

"Make a payment feature"
Enter fullscreen mode Exit fullscreen mode

✅ Good Request

Implement a payment system using Stripe in a Node.js Express server.

Requirements:
1. Card payment (one-time)
2. Subscription payment (monthly/yearly)
3. Payment status update via webhook
4. Retry logic on failure (3 times)
5. Payment history query API
6. Refund processing

Technology Stack:
- Node.js 18+
- Express 4
- TypeScript
- Stripe API v2023
- PostgreSQL

Error Handling:
- Card declined
- Insufficient funds
- Network timeout
- Prevent duplicate payment

Security:
- API keys in environment variables
- Webhook signature verification
- Rate limiting
- SQL Injection prevention
Enter fullscreen mode Exit fullscreen mode

Requesting this way produces actually usable code.

What AI Does Well vs What It Doesn't

What AI Does Well ✅

  1. Boilerplate Code
  • Basic CRUD structure
  • Configuration files
  • Test templates
  1. Algorithm Implementation
  • Sorting, searching
  • Data transformation
  • Mathematical calculations
  1. Documentation
  • Adding comments
  • Writing README
  • API documentation
  1. Refactoring
    • Code cleanup
    • Naming improvements
    • Removing duplication

What AI Doesn't Do Well ❌

  1. Understanding Business Logic
  • Domain-specific rules
  • Company-specific policies
  • Implicit requirements
  1. Architecture Decisions
  • Scalability considerations
  • Performance optimization
  • Technical debt management
  1. Creative Problem Solving
    • New algorithms
    • Innovative approaches
    • Special optimizations

Practice: Pair Programming with AI

Think of AI as a junior developer and collaborate.

Step 1: Explain the Big Picture

"We're building an e-commerce platform.
Main features are product management, orders, payments.
Tech stack is Next.js + NestJS + PostgreSQL."
Enter fullscreen mode Exit fullscreen mode

Step 2: Break Down Specific Tasks

"First, we'll make the product management API.
1. Product CRUD
2. Category management
3. Inventory tracking
4. Image upload"
Enter fullscreen mode Exit fullscreen mode

Step 3: Implement One by One

"Let's start with the product creation API.
POST /api/products
Request body: {name, price, category_id, stock}
Validation: price > 0, stock >= 0
Response: 201 Created with product object"
Enter fullscreen mode Exit fullscreen mode

Step 4: Gradual Improvement

"Good, now add transactions here"
"Improve error handling"
"Write unit tests"
Enter fullscreen mode Exit fullscreen mode

The Synergy of WBS and AI

This is where WBS (Work Breakdown Structure) shines.

When you break down work with WBS, each task becomes a size that AI can easily understand.

Using AI Without WBS

"Make an e-commerce site"
→ AI: "???" (useless code)
Enter fullscreen mode Exit fullscreen mode

Using AI After Breaking Down with WBS

1. User Authentication
   1.1 Signup API
      1.1.1 Email duplicate check
      1.1.2 Password encryption
      1.1.3 Send verification email
   1.2 Login API
      1.2.1 Credential verification
      1.2.2 JWT token issuance
      1.2.3 Refresh token management
Enter fullscreen mode Exit fullscreen mode

Each lowest-level task (1.1.1, 1.1.2...) is a size that AI can accurately implement.

AI Prompt Template

A template I actually use:

## Context

- Project: [Project Name]
- Current Task: [WBS number and description]
- Technology Stack: [Language, Framework, DB]

## Requirements

### Functional Requirements

- [ ] Requirement 1
- [ ] Requirement 2

### Non-Functional Requirements

- Performance: [Response time, throughput]
- Security: [Authentication, authorization, encryption]
- Scalability: [Concurrent users, data growth]

## Constraints

- [Compatibility with existing code]
- [External API limitations]
- [Library versions]

## Expected Input/Output

Input: [Example data]
Output: [Expected result]

## Reference Code

```

[language]
// Existing code or similar example


```
```

`

Using this template increases AI accuracy by 3x.

## Characteristics by AI Tool

### ChatGPT

- Advantages: Good at explanations, various languages
- Disadvantages: Lacks latest information
- Use: Concept explanation, algorithms

### GitHub Copilot

- Advantages: IDE integration, understands context
- Disadvantages: Only short code
- Use: Autocomplete, boilerplate

### Claude

- Advantages: Long code, high accuracy
- Disadvantages: Conservative
- Use: Complex logic, refactoring

### Cursor

- Advantages: Understands entire codebase
- Disadvantages: Paid
- Use: Large-scale refactoring

## Conclusion: AI is Just a Tool

Will AI replace developers? **Absolutely not.**

AI is a **tool that amplifies power**. Just as a hammer can't replace a carpenter, AI can't replace developers.

However, developers who use AI well will be 10x more productive than those who don't.

**The key is clear requirements.**

Break down work with WBS, clearly define each task, and AI becomes an amazing productivity tool.

Before complaining "AI can't write code," we need to reflect on whether we properly communicated the requirements.

**Garbage In, Garbage Out.**

Clear input, clear output. This is the development methodology of the AI era.

---

_Need efficient project management with AI? Check out [Plexo](https://plexo.work)._
Enter fullscreen mode Exit fullscreen mode

Top comments (0)