เอาจริงๆ ปัญหาที่ปวดหัวสุดของการใช้ AI เขียนโค้ด สำหรับผมไม่ใช่มันเขียนไม่เก่งนะครับ แต่มันคืออาการ “มั่ว” หน้าตาเฉยต่างหาก คือน้อง agent ตอบมาแบบมั่นใจเต็มร้อย แต่ฟังก์ชันที่อ้างถึงดันไม่มีอยู่จริง พอเชื่อตามก็เสียเวลาตามแก้ทีหลัง ส่วนตัวผมเลยนั่งเขียนกฎชุดนึงใส่ไว้ใน CLAUDE.md ตัวกลาง (จะไปใส่ใน AGENTS.md หรือ .cursorrules ก็ได้นะครับ ไฟล์ไหนก็ได้ที่ agent อ่าน) เพื่อกันน้องมั่ว นี่คือ กฎที่ผมใช้ 5 ข้อ ครับ
-
อนุญาตให้บอกว่า “ไม่รู้” ได้ ไม่ต้องมั่ว — ผมเขียนบอกน้องตรงๆ เลยว่าถ้าไม่รู้ ให้พูดว่า “I don’t know” ได้เลย ไม่ต้องฝืนตอบ เหตุผลคือโมเดลมักจะรู้สึกว่าต้องตอบให้ได้เสมอ เลยเดาออกมา การเปิดทางให้ยอมรับว่าไม่รู้ ช่วยตัดแรงกดดันตรงนั้นออกไป และดีกว่าคำตอบมั่วๆ ที่พาเราหลงทางเยอะครับ
-
อย่าเดา API หรือ behavior ของ library — ให้ verify กับของจริง ถ้าไม่แน่ใจว่าฟังก์ชันมีจริงไหม รับ argument อะไร คืนค่าแบบไหน ให้ไปเปิด source หรือ docs ดูก่อน อย่านึกเอาเอง เพราะส่วนใหญ่ที่ hallucinate กันก็คือชื่อ method กับ signature ที่ฟังดูสมเหตุสมผลแต่ไม่มีอยู่จริงนี่แหละ
-
อ่านไฟล์จริงก่อน อย่าสมมติว่าโค้ดข้างในเป็นยังไง ก่อนจะแก้อะไร ให้เปิดไฟล์ที่เกี่ยวข้องอ่านจริงๆ ก่อน อย่าเดาจากชื่อไฟล์หรือ pattern ทั่วไป กฎข้อนี้ช่วยเยอะมากในโปรเจกต์ที่มีโครงสร้างเฉพาะตัว เพราะน้องจะแก้บนของจริง ไม่ใช่บนภาพในหัวที่มันคิดเอาเอง
-
ไม่แน่ใจ ให้ flag ว่าไม่แน่ใจ อย่า bluff ถ้าตรงไหนเป็นการเดาหรือมั่นใจไม่เต็มร้อย ให้บอกตรงๆ เลยว่าอันนี้ยังไม่ชัวร์ อย่าทำเสียงมั่นใจเท่ากันหมดทุกคำตอบ เพราะปัญหาใหญ่ของ hallucination ไม่ใช่แค่มันผิด แต่คือมันผิดด้วยน้ำเสียงที่มั่นใจจนเราไม่ทันเอะใจ การ flag ความไม่แน่ใจไว้ ทำให้เรารู้ว่าควรไปเช็คตรงไหนต่อ
-
อ้างอิงแหล่งที่มา — ถ้าไม่มีที่มา ก็ห้ามเคลม (Cite the source — no source, no claim) ถ้าจะบอกว่าอะไรทำงานยังไง ต้อง cite ได้ว่าอ่านมาจากไฟล์ไหน บรรทัดไหน หรือ docs หน้าไหน ข้อนี้เป็นเหมือนด่านสุดท้าย เพราะการบังคับให้ชี้แหล่งทุกครั้ง มันตัดทางการมั่วไปโดยอัตโนมัติ ถ้าน้องชี้ที่มาไม่ได้ แปลว่าอันนั้นยังไม่ควรเอามาเป็นข้อสรุป
เอาไปปรับใช้กันได้นะครับ ส่วนตัวผมลองแล้วน้องมั่วน้อยลงเยอะจริงๆ
ยาวไปไม่อ่าน สรุปก็คือ:
- เปิดทางให้ agent พูดว่า “ไม่รู้” ได้ ไม่ต้องฝืนตอบ
- อย่าเดา API/library ให้ verify กับ source หรือ docs ก่อน
- อ่านไฟล์จริงก่อนแก้ อย่าสมมติเอาเอง
- ไม่ชัวร์ตรงไหน ให้ flag ไว้ อย่า bluff ด้วยน้ำเสียงมั่นใจ
- ทุกข้อสรุปต้อง cite ที่มาได้ ไม่มีที่มา = ห้ามเคลม
Honestly, the most painful part of using AI to code, for me, isn’t that it writes bad code — it’s that it makes things up with a straight face. The agent answers with full confidence, but the function it references doesn’t actually exist. You trust it, then you waste time cleaning up afterward. So I wrote a small ruleset into my global CLAUDE.md (you can drop it in AGENTS.md or .cursorrules too — any file the agent reads) to keep it honest. Here are the 5 rules I use:
-
Allow it to say “I don’t know” — no bluffing — I literally tell the agent that if it doesn’t know, it can just say “I don’t know” instead of forcing an answer. The reason: models tend to feel they must always produce an answer, so they guess. Giving them permission to admit they don’t know removes that pressure, and it beats a made-up answer that sends me down the wrong path.
-
Don’t guess APIs or library behavior — verify against the real thing. If you’re not sure a function exists, what arguments it takes, or what it returns, open the source or the docs and check first. Don’t assume. Most hallucinations are exactly this: method names and signatures that sound reasonable but don’t exist.
-
Read the actual file before assuming what the code does inside. Before changing anything, open the relevant files and actually read them. Don’t guess from the filename or a generic pattern. This one helps a lot in projects with their own peculiar structure, because the agent edits the real thing, not the picture it imagined in its head.
-
If you’re uncertain, flag it — don’t bluff. Wherever something is a guess or not fully confident, say so plainly. Don’t deliver every answer in the same confident tone. The big problem with hallucination isn’t just that it’s wrong — it’s that it’s wrong in a confident voice that slips past you. Flagging uncertainty tells me where to go double-check.
-
Cite the source — no source, no claim. If you’re going to state how something works, you have to cite where you read it: which file, which line, or which docs page. This is the final gate, because forcing a citation every time automatically cuts off the room to make things up. If the agent can’t point to a source, it shouldn’t be treated as a conclusion yet.
Feel free to adapt these. Since I added them, the hallucinations dropped a lot for real.
TL;DR:
- Let the agent say “I don’t know” instead of forcing an answer.
- Don’t guess APIs/libraries — verify against the source or docs first.
- Read the real file before editing; don’t assume.
- Flag anything uncertain — don’t bluff in a confident voice.
- Every claim must cite a source. No source, no claim.



