Why AI Code Generation Fails: The Communication Problem

Published: (December 20, 2025 at 09:49 AM EST)
5 min read
Source: Dev.to

Source: Dev.to

Introduction

“I asked ChatGPT to make a login feature, but it gave me weird code.”
I hear this complaint a lot lately. AI tools (GitHub Copilot, ChatGPT, Claude, …) are everywhere, yet the output often isn’t production‑ready.

Is AI the problem? No.
The problem is how we communicate with AI.

A Real‑World Example

Prompt

Make a login feature

AI’s Response

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

“What is this? AI is not good…”

Who made the mistake?
If you tell a junior developer (or an AI) only “make a login feature”, you’ll get follow‑up questions such as:

  • Which framework should I use?
  • Which database?
  • Session‑based or JWT?
  • Do we need social login?
  • Any password rules?

AI doesn’t ask those questions—it just gives the most generic answer it can.

“Garbage In, Garbage Out” → “Ambiguous Request In, Ambiguous Code Out”

RequestResultPracticality
“Make a user‑management feature”Basic CRUD skeleton (≈30 lines)10 %
“Make a user‑management API with Django REST Framework - Email authentication - JWT token - Permission groups (admin, user) - Profile image upload - Soft delete - Pagination”High‑quality code (≈500 lines)85 %

The difference is the amount of context you provide.

What AI Needs to Produce Usable Code

1. Background

  • Project type (e.g., e‑commerce, SaaS)
  • Technology stack (frameworks, language versions)
  • Constraints (performance, security, compliance)

2. Specific Requirements

  • Feature list (what exactly should be built)
  • Non‑functional requirements (latency, scalability)
  • Edge cases (failure modes, validation rules)

3. Examples or References

  • Similar code snippets
  • API documentation links
  • Desired output format (JSON schema, OpenAPI spec)

Bad vs. Good Prompt

❌ Bad Request

Make a payment feature

✅ 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 (max 3 attempts)
  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

Providing this level of detail yields code that can be dropped straight into a repo.

Typical AI‑Generated Artifacts

CategoryExamples
BoilerplateCRUD scaffolding, config files, test templates
Algorithm ImplementationSorting, searching, data transformation, math calculations
DocumentationInline comments, README, API docs
Refactoring / CleanupNaming improvements, duplicate removal, architecture decisions
Advanced TopicsScalability, performance tuning, technical‑debt management, creative problem solving
New AlgorithmsInnovative approaches, special optimizations

Think of the AI as a junior developer—you need to guide it.

Collaborative Workflow Example

Project: E‑commerce platform
Tech Stack: Next.js + NestJS + PostgreSQL

  1. Define the first module

    First, we'll make the product‑management API.
    1. Product CRUD
    2. Category management
    3. Inventory tracking
    4. Image upload
  2. Drill down to a concrete task

    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
  3. Iterate

    • “Add transaction handling here.”
    • “Improve error handling.”
    • “Write unit tests.”

Work Breakdown Structure (WBS) for AI

When you give a large, vague request, AI returns “???”.
Break the work into small, well‑scoped tasks that AI can understand.

Make an e‑commerce site
→ AI: ??? (useless code)

Sample 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

Each lowest‑level task (e.g., 1.1.1) is a size that AI can accurately implement.

My Prompt Template (What I Actually Use)

[Project Overview]
- Brief description
- Business goals

[Technology Stack]
- Language / framework versions
- External services (e.g., Stripe, AWS)

[Feature Description]
- High‑level purpose
- Detailed functional requirements (list)
- Non‑functional requirements (performance, security, etc.)

[Edge Cases & Validation]
- Input constraints
- Failure scenarios

[References]
- Links to docs, similar code, OpenAPI specs

[Deliverables]
- Code files (list)
- Tests (unit/integration)
- Documentation (README, API docs)

Copy, fill in the blanks, and feed the prompt to the AI. The result will be production‑ready code you can merge with confidence.

Option 1 – Bullet List (with bold labels)

## Context

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

Option 2 – Table (compact and easy to scan)

## Context

| Item                | Details                     |
|---------------------|-----------------------------|
| **Project**         | [Project Name]             |
| **Current Task**    | [WBS number and description] |
| **Technology Stack**| [Language, Framework, DB]  |

Both versions preserve the original information while improving readability and visual consistency. Use whichever fits best with your documentation.

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

// Existing code or similar example

Using this template increases AI accuracy by 3×.

Characteristics by AI Tool

AI ToolAdvantagesDisadvantagesTypical Use
ChatGPT• Excellent at explanations • Supports many programming languages• Lacks up‑to‑date information• Concept explanation • Algorithm design
GitHub Copilot• Seamless IDE integration • Understands surrounding code context• Generates only short snippets• Autocomplete • Boilerplate creation
Claude• Handles long code blocks • High accuracy• Tends to be conservative in suggestions• Complex logic implementation • Refactoring
Cursor• Grasps the entire codebase • Good for large‑scale changes• Requires a paid subscription• Large‑scale refactoring • Project‑wide code improvements

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.

Developers who use AI effectively can be 10× more productive than those who don’t.

The Key: Clear Requirements

  1. Break down work with a Work Breakdown Structure (WBS).
  2. Clearly define each task.

When requirements are explicit, AI becomes an amazing productivity aid.

“Garbage In, Garbage Out.”
Clear input → Clear output. This is the development methodology for the AI era.

Need efficient project management with AI? Check out Plexo.

Back to Blog

Related posts

Read more »