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.
| Technique | When to Use | Token Cost | Quality | Complexity |
|---|---|---|---|---|
| Wrong Format | Output tidak match struktur yang diminta | Low | Low | Low |
| Incomplete Answer | Output hanya cover sebagian requirement | Medium | Low | Medium |
| Factually Incorrect | Output mengandung informasi salah | Medium | Low | High |
| Inconsistent Output | Output berbeda untuk input serupa | Medium | Low | High |
| Too Verbose | Output terlalu panjang, banyak filler | High | Medium | Low |
Step 2: Isolate the Root Cause
Gunakan elimination method untuk menemukan penyebab.
Checklist diagnosis:
-
Apakah instruksi jelas?
- Coba baca ulang prompt Anda. Apakah orang lain bisa mengerti maksudnya?
- Apakah ada kata yang ambiguous? (contoh: "bagus", "lengkap", "detail")
-
Apakah konteks cukup?
- Apakah AI punya semua informasi yang dibutuhkan untuk menjawab?
- Apakah ada asumsi implisit yang tidak Anda sebutkan?
-
Apakah format output spesifik?
- Apakah Anda menyebutkan format yang diinginkan? (tabel, JSON, bullet points)
- Apakah Anda memberi contoh output?
-
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 tokensBandingkan React dan Vue untuk project sayaAfter
32 tokensBandingkan 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 tokensJelaskan cara deploy Next.js app, setup database, dan konfigurasi CI/CDAfter
48 tokensJawab 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:
-
Provide source material
Berdasarkan dokumentasi berikut: [paste docs] Jelaskan cara menggunakan feature X. -
Ask for citations
Jelaskan Y. Sertakan sumber untuk setiap klaim. Jika tidak yakin, katakan "Saya tidak punya informasi terbaru tentang ini." -
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 tokensBuatkan commit message untuk perubahan ini: [code diff]After
45 tokensBuatkan 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 tokensJelaskan apa itu REST APIAfter
28 tokensJelaskan 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:
- Model limitation โ task terlalu kompleks untuk model size
- Conflicting constraints โ requirement saling bertentangan
- Insufficient context โ butuh informasi yang tidak tersedia
- Wrong tool โ task lebih cocok untuk traditional programming
Summary
Debugging framework:
- Classify problem โ wrong format, incomplete, incorrect, inconsistent, verbose
- Isolate root cause โ clarity, context, format, constraint
- Apply targeted fix โ sesuaikan dengan jenis masalah
- Iterate incrementally โ ubah satu variable per iterasi
- 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.