fundamentals ยท 7 menit baca

Debugging Bad Responses

Teknik sistematis untuk mendiagnosis dan memperbaiki output AI yang tidak sesuai

Introduction

AI memberikan jawaban yang salah, tidak lengkap, atau tidak sesuai format? Jangan langsung menyalahkan model. 90% masalah output berasal dari prompt yang ambiguous, konteks yang kurang, atau constraint yang tidak jelas.

Lesson ini mengajarkan systematic debugging approach untuk mengidentifikasi root cause dan memperbaiki prompt dengan cepat.

Debugging Framework

Step 1: Classify the Problem

Identifikasi jenis masalah sebelum mencari solusi.

TechniqueWhen to UseToken CostQualityComplexity
Wrong FormatOutput tidak match struktur yang dimintaLowLowLow
Incomplete AnswerOutput hanya cover sebagian requirementMediumLowMedium
Factually IncorrectOutput mengandung informasi salahMediumLowHigh
Inconsistent OutputOutput berbeda untuk input serupaMediumLowHigh
Too VerboseOutput terlalu panjang, banyak fillerHighMediumLow
Setiap jenis masalah punya root cause dan fix yang berbeda. Classify dulu sebelum debug.

Step 2: Isolate the Root Cause

Gunakan elimination method untuk menemukan penyebab.

Checklist diagnosis:

  1. Apakah instruksi jelas?

    • Coba baca ulang prompt Anda. Apakah orang lain bisa mengerti maksudnya?
    • Apakah ada kata yang ambiguous? (contoh: "bagus", "lengkap", "detail")
  2. Apakah konteks cukup?

    • Apakah AI punya semua informasi yang dibutuhkan untuk menjawab?
    • Apakah ada asumsi implisit yang tidak Anda sebutkan?
  3. Apakah format output spesifik?

    • Apakah Anda menyebutkan format yang diinginkan? (tabel, JSON, bullet points)
    • Apakah Anda memberi contoh output?
  4. Apakah ada constraint yang dilanggar?

    • Apakah Anda memberi batasan? (panjang, tone, scope)
    • Apakah constraint saling bertentangan?

Common Problems & Fixes

Problem 1: Wrong Format

Symptom: Output berupa paragraf, padahal Anda minta tabel.

Root cause: Format tidak dispesifikkan dengan jelas.

Before

18 tokens
Bandingkan React dan Vue untuk project saya

After

32 tokens
Bandingkan React vs Vue. Format: tabel markdown dengan kolom: Framework, Kelebihan, Kekurangan, Use Case. 4 baris.

Problem 2: Incomplete Answer

Symptom: Output hanya menjawab sebagian pertanyaan.

Root cause: Pertanyaan terlalu luas atau multi-part tidak terstruktur.

Before

25 tokens
Jelaskan cara deploy Next.js app, setup database, dan konfigurasi CI/CD

After

48 tokens
Jawab 3 pertanyaan ini secara terpisah:
1. Cara deploy Next.js ke Vercel
2. Setup PostgreSQL database di Supabase
3. Konfigurasi GitHub Actions untuk CI/CD
Format: numbered list dengan sub-steps.

Problem 3: Factually Incorrect

Symptom: Output mengandung informasi yang salah atau outdated.

Root cause: Model hallucination atau knowledge cutoff.

Fix strategies:

  1. Provide source material

    Berdasarkan dokumentasi berikut: [paste docs]
    Jelaskan cara menggunakan feature X.
    
  2. Ask for citations

    Jelaskan Y. Sertakan sumber untuk setiap klaim.
    Jika tidak yakin, katakan "Saya tidak punya informasi terbaru tentang ini."
    
  3. Verify with follow-up

    [After getting answer]
    Apakah informasi di atas masih accurate untuk [current year]?
    Highlight bagian yang mungkin sudah outdated.
    

Problem 4: Inconsistent Output

Symptom: Input serupa menghasilkan output berbeda.

Root cause: Prompt terlalu open-ended, tidak ada constraint.

Before

22 tokens
Buatkan commit message untuk perubahan ini: [code diff]

After

45 tokens
Buatkan commit message conventional format.
Template: type(scope): description
Type options: feat, fix, docs, refactor
Max 50 chars untuk subject line
Perubahan: [code diff]

Problem 5: Too Verbose

Symptom: Output 500 kata, padahal Anda butuh 100 kata.

Root cause: Tidak ada length constraint.

Before

15 tokens
Jelaskan apa itu REST API

After

28 tokens
Jelaskan REST API dalam 3 kalimat. Target: developer yang sudah tahu HTTP. Skip intro dan history.

Teknik compression:

  • Tambahkan word/sentence limit: "Maksimal 100 kata", "3-5 kalimat"
  • Specify audience: "Target: senior developer" (skip basic explanations)
  • Exclude sections: "Skip examples", "No code samples"

Advanced Debugging Techniques

Technique 1: Incremental Refinement

Jangan langsung rewrite seluruh prompt. Ubah satu variable per iterasi.

Iteration example:

Iteration 1: Prompt dasar
โ†’ Problem: format salah
Iteration 2: + tambah format constraint
โ†’ Problem: terlalu verbose
Iteration 3: + tambah length limit
โ†’ Problem: missing context
Iteration 4: + tambah tech stack info
โ†’ Success!

Technique 2: Prompt Decomposition

Jika prompt kompleks terus gagal, pecah menjadi multiple prompts.

Before (single prompt):

Analyze this code, find bugs, suggest fixes, and rewrite it with best practices.

After (decomposed):

Prompt 1: Analyze code โ†’ identify bugs
Prompt 2: For each bug โ†’ suggest fix
Prompt 3: Apply fixes โ†’ rewrite code
Prompt 4: Review rewritten code โ†’ apply best practices

Technique 3: Add Verification Step

Minta AI verify outputnya sendiri.

Pattern:

[Your main prompt]

After generating the answer, verify:
1. Does it match the requested format?
2. Did it address all parts of the question?
3. Are there any obvious errors?

If verification fails, regenerate.

Debugging Checklist

Gunakan checklist ini setiap kali output tidak sesuai:

Format Issues:

  • Apakah format output dispesifikkan? (JSON, tabel, bullet points)
  • Apakah ada contoh format yang diberikan?
  • Apakah struktur output dijelaskan dengan detail?

Content Issues:

  • Apakah semua bagian pertanyaan addressed?
  • Apakah konteks yang relevan sudah diberikan?
  • Apakah ada ambiguitas dalam instruksi?

Quality Issues:

  • Apakah ada length constraint?
  • Apakah target audience dispesifikkan?
  • Apakah tone/style dijelaskan?

Consistency Issues:

  • Apakah ada template atau pattern yang harus diikuti?
  • Apakah ada constraint yang memaksa consistency?
  • Apakah few-shot examples diberikan?

When to Give Up on a Prompt

Tidak semua prompt bisa difix. Tanda-tanda prompt tidak feasible:

  1. Model limitation โ€” task terlalu kompleks untuk model size
  2. Conflicting constraints โ€” requirement saling bertentangan
  3. Insufficient context โ€” butuh informasi yang tidak tersedia
  4. Wrong tool โ€” task lebih cocok untuk traditional programming

Summary

Debugging framework:

  1. Classify problem โ€” wrong format, incomplete, incorrect, inconsistent, verbose
  2. Isolate root cause โ€” clarity, context, format, constraint
  3. Apply targeted fix โ€” sesuaikan dengan jenis masalah
  4. Iterate incrementally โ€” ubah satu variable per iterasi
  5. Use checklist โ€” systematic verification sebelum declare "fixed"

Common fixes:

  • Wrong format โ†’ add explicit format constraint
  • Incomplete โ†’ break down multi-part questions
  • Incorrect โ†’ provide source material, ask for citations
  • Inconsistent โ†’ add template/pattern constraint
  • Verbose โ†’ add length limit, specify audience

Debugging adalah skill. Semakin sering practice, semakin cepat Anda identify root cause dan apply fix yang tepat.

Related Topics