คู่มือ Prompt Engineering: เทคนิคดึงผลลัพธ์ที่ดีกว่าจาก AI Tools
เรียนรู้เทคนิคการเขียน Prompt ที่ช่วยให้ได้ผลลัพธ์จาก AI ที่ดีขึ้นอย่างสม่ำเสมอ — ตั้งแต่ zero-shot instructions ไปจนถึง chain-of-thought reasoning, role prompting และรูปแบบ structured output
คุณภาพของผลลัพธ์จาก AI ขึ้นอยู่กับคุณภาพของ input ที่คุณป้อนเข้าไปเกือบทั้งหมด คนสองคนที่ใช้โมเดลเดียวกันกับงานเดียวกันอาจได้ผลลัพธ์ที่แตกต่างกันอย่างสิ้นเชิง — คนหนึ่งได้คำตอบที่ผิวเผินและไม่ตรงประเด็น อีกคนกลับได้คำตอบที่แม่นยำและนำไปใช้ได้จริง — เพียงเพราะ Prompt ของพวกเขาต่างกัน Prompt engineering คือทักษะการสื่อสารกับระบบ AI อย่างชัดเจน เพื่อให้ได้ผลลัพธ์ที่ต้องการอย่างแท้จริง
ทำไม Prompt ถึงสำคัญมาก
Large language model คือระบบที่ทำนาย token ถัดไปจากการฝึกด้วยข้อความของมนุษย์จำนวนมหาศาล เมื่อคุณป้อน Prompt โมเดลจะทำหน้าที่เหมือนกำลังเขียนเอกสารต่อจากที่คุณเริ่มไว้ ถ้า Prompt ของคุณดูเหมือนจุดเริ่มต้นของคำตอบที่มีคุณภาพสูงและละเอียด คุณก็จะได้เนื้อหาต่อที่มีคุณภาพสูงและละเอียดเช่นกัน แต่ถ้า Prompt คลุมเครือ คำตอบก็จะคลุมเครือตามไปด้วย
ลองมองการเขียน Prompt ไม่ใช่การออกคำสั่ง แต่เป็นการสร้างบริบทที่เอื้อให้ได้คำตอบที่ดีที่สุดเท่าที่จะเป็นไปได้
โครงสร้างของ Prompt ที่มีประสิทธิภาพ
Prompt ที่ดีมักประกอบด้วยองค์ประกอบบางส่วนหรือทั้งหมดเหล่านี้:
- Role — AI ควรรับบทบาทเป็นใคร
- Task — คุณต้องการให้ทำอะไร
- Context — ข้อมูลพื้นฐานที่เกี่ยวข้อง
- Format — ผลลัพธ์ควรมีโครงสร้างอย่างไร
- Constraints — สิ่งที่ควรหลีกเลี่ยงหรือรวมไว้
- Examples — ตัวอย่าง input และ output (few-shot)
ไม่ใช่ทุก Prompt ที่ต้องมีครบทั้งหกข้อ แต่การเพิ่มข้อที่เกี่ยวข้องกับงานของคุณจะช่วยให้ผลลัพธ์ดีขึ้นอย่างเห็นได้ชัด
Zero-shot vs. Few-shot Prompting
Zero-shot
ถามตรงๆ โดยไม่มีตัวอย่าง:
Classify the sentiment of this review as Positive, Negative, or Neutral:
"The delivery was fast but the product arrived damaged."
ได้ผลดีกับงานที่โมเดลเคยเห็นหลายครั้งระหว่างการฝึก
Few-shot
ให้ตัวอย่างก่อนถึงงานจริง:
Classify the sentiment of each review:
Review: "Amazing quality, exactly as described!" → Positive
Review: "Took 3 weeks to arrive, very disappointed." → Negative
Review: "It's okay, does what it says." → Neutral
Review: "The delivery was fast but the product arrived damaged." →
Few-shot prompting ช่วยเพิ่มความแม่นยำได้อย่างมากสำหรับงานที่ต้องการความละเอียดอ่อนหรืองานเฉพาะทาง โดยปกติ 2–5 ตัวอย่างคือจำนวนที่เหมาะสม — ยิ่งมากไม่ได้หมายความว่าจะดีกว่าเสมอไป
Role Prompting
การกำหนดบทบาทให้ AI จะเปลี่ยน "มุมมอง" และเปิดใช้งานความรู้เฉพาะด้านที่เกี่ยวข้อง:
You are a senior security engineer with 15 years of experience reviewing
code for vulnerabilities. Be direct, technical, and prioritize the most
critical issues first.
Review this authentication function for security issues:
[code]
เทียบกับ
Review this code for security issues:
[code]
เวอร์ชันที่ใช้ role prompting มักให้ feedback ที่เฉพาะเจาะจง นำไปปฏิบัติได้จริง และอยู่ในระดับผู้เชี่ยวชาญมากกว่า
Chain-of-Thought Prompting
สำหรับงานที่ต้องใช้การให้เหตุผลซับซ้อน ให้ขอให้โมเดลแสดงขั้นตอนการคิด:
A company has 3 pricing tiers: Basic ($10/mo), Pro ($25/mo), Enterprise ($80/mo).
They currently have 500 Basic, 300 Pro, and 50 Enterprise customers.
If 10% of Basic customers upgrade to Pro and 5% of Pro customers upgrade to Enterprise,
what is the new monthly revenue?
Think through this step by step.
ประโยค "think through this step by step" (หรือ "let's think step by step") ช่วยเพิ่มความแม่นยำได้อย่างมากในงานคณิตศาสตร์ ตรรกะ และการให้เหตุผลหลายขั้นตอน โมเดลมีโอกาสน้อยลงที่จะกระโดดไปสู่คำตอบที่ผิด หากต้องให้เหตุผลผ่านขั้นตอนกลางก่อน
Structured Output Prompting
เมื่อต้องการ output ที่นำไปประมวลผลต่อได้ ให้ระบุรูปแบบอย่างชัดเจน:
Extract the following information from this job posting and return it as JSON:
Job posting:
[paste job posting here]
Required JSON format:
{
"title": "string",
"company": "string",
"location": "string",
"salary_range": "string or null",
"required_skills": ["string"],
"experience_years": "number or null",
"remote": "boolean"
}
สำหรับการใช้งานกับแอปพลิเคชัน ให้เพิ่ม: "Return only the JSON with no additional text or explanation."
ใช้ AI JSON Generator ของเราเพื่อสร้างข้อมูล JSON แบบ structured จากคำอธิบายภาษาธรรมชาติ
การควบคุม Persona และ Tone
ระบุกลุ่มผู้อ่านและโทนเสียงสำหรับเนื้อหาที่เป็นข้อเขียน:
Write a 3-paragraph explanation of how HTTPS works.
Audience: non-technical small business owners who want to understand
why their website needs an SSL certificate.
Tone: friendly and reassuring, avoid jargon, use analogies where helpful.
Avoid: technical terms without explanation, fear-mongering.
เทียบกับ
Explain how HTTPS works.
อันแรกให้เนื้อหาที่ใช้งานได้จริงสำหรับกลุ่มผู้อ่านที่ระบุไว้
การปรับปรุงแบบวนซ้ำ
มองการเขียน Prompt เป็นการสนทนา ไม่ใช่การทำธุรกรรมครั้งเดียวจบ:
- เริ่มกว้างๆ ก่อน แล้วดูว่าโมเดลให้อะไรออกมา
- ระบุสิ่งที่ขาดหายหรือผิดพลาด
- เพิ่ม constraints เพื่อแก้ปัญหาเฉพาะจุด
- ทำซ้ำ จนกว่า output จะตรงกับความต้องการ
Round 1: "Write a cover letter for a software engineer position."
→ Too generic, doesn't mention my specific experience
Round 2: "Rewrite this as a more concise 3-paragraph version.
Emphasize my 5 years of React experience and my work on high-traffic applications.
Don't use the phrase 'I am writing to express my interest'."
→ Much better
แต่ละรอบควรแก้ปัญหาเฉพาะเจาะจง การให้ feedback แบบคลุมเครือ ("ทำให้ดีขึ้น") จะให้ผลการปรับปรุงเพียงเล็กน้อยเท่านั้น
Constraints และคำสั่งเชิงลบ
บอกโมเดลว่าไม่ควรทำอะไร:
Write a product description for this coffee maker.
- Keep it under 100 words
- Don't use the words "revolutionary," "game-changing," or "innovative"
- Don't use exclamation marks
- Focus on practical benefits, not features
การกำหนด constraints เชิงลบมักให้ผลลัพธ์ที่เป็นธรรมชาติมากขึ้น และลดการใช้ภาษาสไตล์การตลาดที่เกินเหตุ
Prompting สำหรับงาน Code
สำหรับการสร้างและตรวจสอบ code ความเฉพาะเจาะจงให้ผลตอบแทนที่คุ้มค่า:
# Vague (produces generic code)
Write a function to validate email addresses in TypeScript.
# Better
Write a TypeScript function that validates email addresses.
Requirements:
- Uses a regex that handles common edge cases (subdomains, + addressing, etc.)
- Returns { valid: boolean; reason?: string }
- Handles null/undefined input gracefully
- Include JSDoc comments
- Add 5 unit test cases covering edge cases
ใช้ AI Code Explainer ของเราเพื่อรับคำอธิบาย code ที่ละเอียดในส่วนที่คุณไม่เข้าใจ — แค่วาง function ใดก็ได้และรับคำอธิบายแบบ line-by-line
ข้อผิดพลาดที่พบบ่อยในการเขียน Prompt
| ข้อผิดพลาด | ปัญหา | วิธีแก้ |
|---|---|---|
| คลุมเครือเกินไป | โมเดลเดาเจตนาของคุณ | ระบุ task, format และกลุ่มผู้อ่านให้ชัดเจน |
| สมมติว่าโมเดลรู้บริบท | โมเดลไม่รู้จัก codebase หรือ product ของคุณ | ใส่บริบทที่เกี่ยวข้องลงใน Prompt |
| ใช้ single-shot กับงานซับซ้อน | ข้อผิดพลาดสะสมทบทวี | แบ่งเป็น subtask หรือใช้ chain-of-thought |
| ไม่ระบุรูปแบบ output | โครงสร้าง output ไม่สม่ำเสมอ | ระบุรูปแบบที่ต้องการอย่างชัดเจน |
| คำนำยาวเกินไป | งานหลักถูกฝังอยู่ข้างใน | วางคำสั่งที่สำคัญที่สุดไว้ต้นหรือท้าย Prompt |
| ไม่มีตัวอย่างสำหรับงานใหม่ | โมเดลจับรูปแบบไม่ถูก | เพิ่มตัวอย่าง input/output ที่ต้องการ 2–3 ตัวอย่าง |
Framework ด่วนสำหรับเขียน Prompt ที่ดีขึ้น
ก่อนส่ง Prompt ให้ถามตัวเองว่า:
- ใคร คือ AI ควรเป็น? (role)
- อะไร คือสิ่งที่ต้องการอย่างแน่ชัด? (task)
- อะไร คือบริบทที่โมเดลต้องรู้? (background)
- อย่างไร ควรตอบกลับ? (format, length, tone)
- อะไร ที่ควรหลีกเลี่ยง? (constraints)
- ให้ตัวอย่างได้ไหม? (few-shot)
Prompt engineering เป็นทักษะที่เรียนรู้ได้และนำไปใช้ได้หลากหลาย หลักการเดียวกันนี้ใช้ได้ไม่ว่าจะเป็น AI Grammar Checker, AI Email Writer, coding assistants หรือ AI tool อื่นใด Prompt ที่ดีกว่า ผลลัพธ์ที่ดีกว่า — ทุกครั้ง