Phát hiện Hallucination
Module 8.1: Phát hiện Hallucination
Phần tiêu đề “Module 8.1: Phát hiện Hallucination”Thời gian học: ~30 phút
Yêu cầu trước: Module 7.5 (Công Cụ Điều Phối)
Kết quả: Sau module này, bạn sẽ nhận ra hallucination pattern, biết verification technique, và build habit catch hallucination sớm.
1. WHY — Tại Sao Cần Hiểu
Phần tiêu đề “1. WHY — Tại Sao Cần Hiểu”Claude tự tin bảo bạn: “Dùng npm install super-validator rồi gọi superValidator.validateEmail()”. Bạn implement. Build fail. 30 phút debug. Kết quả? Package không tồn tại.
Hoặc tệ hơn: Claude suggest một Node.js API method nghe đúng lắm. Dev chạy okay. Production crash. Method đó không có thật.
Claude không signal uncertainty. Câu trả lời sai nghe equally confident như câu đúng. Hallucination detection là job của BẠN, không phải Claude.
2. CONCEPT — Ý Tưởng Cốt Lõi
Phần tiêu đề “2. CONCEPT — Ý Tưởng Cốt Lõi”Hallucination Là Gì?
Phần tiêu đề “Hallucination Là Gì?”Hallucination = AI generate thông tin nghe hợp lý nhưng sai. Không phải Claude “nói dối” — nó thật sự “nghĩ” đúng. Xảy ra vì LLM predict likely token dựa trên pattern, không verify fact real-time.
Ví von: Claude như bạn học giỏi nhớ nhiều nhưng đôi khi nhớ nhầm. Nó tự tin nói “hàm này tên X” như đang nói đúng. Không cố ý sai — chỉ nhớ nhầm.
Hallucination Categories
Phần tiêu đề “Hallucination Categories”| Category | Example | Risk |
|---|---|---|
| Package names | npm install validatorjs (thật: validator) | High |
| API methods | array.flatten() (thật: array.flat()) | High |
| CLI flags | claude --verbose (có thể không tồn tại) | Medium |
| File paths | src/utils/helpers.ts (không tồn tại) | Medium |
| Version-specific | ”Node 18 thêm feature X” (sai version) | High |
| Config syntax | tsconfig option không tồn tại | High |
Tại Sao Claude Hallucinate?
Phần tiêu đề “Tại Sao Claude Hallucinate?”Training data có nhiều thứ similar. Claude interpolate giữa các pattern. Nó không có internet để verify real-time. Kết quả: tên nghe đúng, nhưng sai.
Trust But Verify
Phần tiêu đề “Trust But Verify”Trust reasoning và approach của Claude — nó excellent ở đây. Verify specific fact: tên package, tên method, path, syntax, version.
Nguyên tắc: Càng specific claim → càng cần verify.
Red Flags
Phần tiêu đề “Red Flags”Extra suspicious khi thấy:
- Package/method name nghe “perfect” cho use case của bạn
- Version number cụ thể (“added in v2.3.4”)
- File path Claude chưa từng read
- CLI flag chưa run
--helpxác nhận
graph LR A[Claude Output] --> B{Specific Claim?} B -->|Yes| C[VERIFY] B -->|No| D[Trust Reasoning] C --> E{Matches Source?} E -->|Yes| F[Use It] E -->|No| G[Ask Correction] G --> C
style C fill:#ffcc00 style F fill:#90EE903. DEMO — Từng Bước
Phần tiêu đề “3. DEMO — Từng Bước”Scenario: Bạn cần validate số điện thoại Việt Nam. Hỏi Claude về library.
Step 1: Nhận Suggestion
Phần tiêu đề “Step 1: Nhận Suggestion”Prompt:
Recommend library validate số điện thoại VNClaude trả lời:
Dùng package `vn-phone-validator`:npm install vn-phone-validator
import { validateVNPhone } from 'vn-phone-validator';validateVNPhone('0901234567');Red flag: Tên package quá “perfect” cho use case.
Step 2: Verify Package
Phần tiêu đề “Step 2: Verify Package”$ npm info vn-phone-validatorExpected output:
npm ERR! code E404npm ERR! 404 Not Found - GET https://registry.npmjs.org/vn-phone-validatorKết luận: HALLUCINATION! Package không tồn tại.
Step 3: Yêu Cầu Correction
Phần tiêu đề “Step 3: Yêu Cầu Correction”Prompt Claude:
Package vn-phone-validator không tồn tại (404 từ npm).Suggest real alternative. Tôi sẽ verify với npm info.Claude correct:
Xin lỗi! Dùng `libphonenumber-js` — library thật:npm install libphonenumber-jsStep 4: Verify Lại
Phần tiêu đề “Step 4: Verify Lại”$ npm info libphonenumber-jsOutput:
libphonenumber-js@1.10.xGoogle's libphonenumber compiled to JavaScript...Kết luận: EXISTS! Package thật.
Step 5: Verify API Trước Khi Dùng
Phần tiêu đề “Step 5: Verify API Trước Khi Dùng”$ cat node_modules/libphonenumber-js/README.md | head -100Hoặc yêu cầu Claude:
Read actual types/README của libphonenumber-js trước khi suggest APIWorkflow hoàn chỉnh: Suspect → Verify → Correct → Re-verify → Use
4. PRACTICE — Tự Thực Hành
Phần tiêu đề “4. PRACTICE — Tự Thực Hành”Bài 1: Hallucination Hunting
Phần tiêu đề “Bài 1: Hallucination Hunting”Goal: Phát triển “mắt nghi ngờ” với AI suggestion.
Instructions:
- Hỏi Claude suggest 3 packages cho một task (ví dụ: date formatting)
- Chạy
npm info <package>cho từng cái - Đếm bao nhiêu là hallucination
Expected result: Ít nhất 1 trong 3 có thể là hallucination.
💡 Hint
npm info moment # Popular, likely realnpm info date-helper-pro # Generic name, suspectnpm info dayjs # Popular, likely real✅ Solution
Verification process:
$ npm info moment# ✓ Real - 20M weekly downloads
$ npm info dayjs# ✓ Real - 16M weekly downloads
$ npm info date-fns# ✓ Real - 23M weekly downloadsNếu Claude suggest tên nghe “quá perfect” như super-date-formatter hoặc vn-date-utils, verify ngay — likely hallucination.
Bài 2: API Verification
Phần tiêu đề “Bài 2: API Verification”Goal: Verify API method trước khi implement.
Instructions:
- Hỏi Claude về Node.js API bạn chưa quen (ví dụ:
fs.promises) - Claude suggest method name
- Check official docs tại nodejs.org
- So sánh: Claude đúng hay sai?
Bài 3: Path Verification
Phần tiêu đề “Bài 3: Path Verification”Goal: Verify file path Claude mention.
Instructions:
- Hỏi Claude về structure của project bạn đang làm
- Claude mention một file path
- Run
ls <path>hoặcfind . -name "filename" - Có match không?
5. CHEAT SHEET
Phần tiêu đề “5. CHEAT SHEET”Verification Commands
Phần tiêu đề “Verification Commands”| Loại | Command | Ví dụ |
|---|---|---|
| npm package | npm info <package> | npm info lodash |
| Python package | pip show <package> | pip show requests |
| CLI flag | <command> --help | git --help |
| File path | ls <path> | ls src/utils/ |
| File tìm | find . -name "file" | find . -name "*.ts" |
| Man page | man <command> | man curl |
Red Flag Phrases
Phần tiêu đề “Red Flag Phrases”Khi Claude nói những câu này, VERIFY ngay:
- “You can use package X” →
npm info X - “Call X.method()” → Check official docs
- “File is at src/…” →
ls src/... - “Added in version X.Y.Z” → Check changelog
- “Flag —xyz does…” →
command --help
Verification Prompts
Phần tiêu đề “Verification Prompts”Yêu cầu Claude tự verify:
"Verify package exists trước khi suggest""Read actual types/README của package này""Run --help và show real flags""Check file exists trước khi reference"6. PITFALLS — Lỗi Thường Gặp
Phần tiêu đề “6. PITFALLS — Lỗi Thường Gặp”| ❌ Sai Lầm | ✅ Đúng Cách |
|---|---|
| Trust package name không npm verify | LUÔN npm info trước npm install |
| Assume API method đúng | Check types hoặc official docs |
| Trust file path Claude mention | Verify với ls hoặc find |
| Không question confident claim | Confidence ≠ correctness |
| Blame Claude khi hallucinate | Known limitation, build verification vào workflow |
| Chỉ verify khi fail | Verify TRƯỚC implement, không phải sau |
| Dùng Claude verify Claude | Dùng external source: npm, docs, filesystem |
7. REAL CASE — Câu Chuyện Thực Tế
Phần tiêu đề “7. REAL CASE — Câu Chuyện Thực Tế”Scenario: Team startup Việt Nam integrate VNPay payment.
Xảy ra: Dev hỏi Claude về VNPay library. Claude suggest:
npm install vnpay-nodejsimport VNPay from 'vnpay-nodejs';const url = VNPay.createPaymentUrl(params);Dev trust, implement 2 giờ. Build fail. Hóa ra:
- Package thật tên
vnpay(không có-nodejs) - Method thật là
buildPaymentUrl()(không phảicreatePaymentUrl)
Thêm 2 giờ debug. Tổng mất: 4 giờ.
Nên làm:
$ npm info vnpay-nodejs# npm ERR! 404 → HALLUCINATION!
$ npm search vnpay# Found: vnpay
$ npm info vnpay# ✓ Exists!
$ npm install vnpay$ cat node_modules/vnpay/README.md# Thấy actual API: buildPaymentUrl()Tiết kiệm: 3+ giờ với 30 giây verification.
Team rule sau đó: “Package mới? npm info trước. API mới? Read types trước. Không ngoại lệ.”
Insight: “5 giây npm info tiết kiệm hàng giờ debug hallucinated API. Verification là investment, không phải overhead.”
Tiếp theo: Module 8.2: Phát hiện & Phá vòng lặp →