Prompt Engineering năm 2026: Nghệ thuật nói chuyện với AI
ISC Team
ISC Vibe Marketplace
Khi AI đã có thể viết code tốt hơn nhiều developer, kỹ năng quan trọng nhất không còn là "biết viết code" — mà là "biết hướng dẫn AI viết code đúng". Đây là Prompt Engineering, và năm 2026, nó đã trở thành core skill của mọi developer.
Ba Trụ Cột Của Prompt Engineering Hiệu Quả
Few-Shot Prompting → Cho ví dụ để AI học pattern
Chain-of-Thought → Yêu cầu AI giải thích reasoning
Structured Context → Tổ chức thông tin có hệ thốngTrụ Cột 1: Few-Shot Prompting
LLMs học rất hiệu quả từ ví dụ trong prompt. Thay vì chỉ mô tả những gì bạn muốn, hãy show examples.
Zero-Shot (Kém hiệu quả)
"Viết TypeScript function để validate email address"Kết quả: Regex cơ bản, có thể thiếu edge cases, không match style dự án.
Few-Shot (Hiệu quả hơn nhiều)
"Viết TypeScript email validator. Đây là các validators tương tự:
const validatePhone = (phone: string): boolean => {
const pattern = /^1?[0-9]{10}$/;
return pattern.test(phone.replace(/[^0-9]/g, ''));
};
const validateZip = (zip: string): boolean => {
const pattern = /^d{5}(-d{4})?$/;
return pattern.test(zip);
};
Giờ viết email validator theo pattern tương tự."Kết quả: Function follow đúng style, có error handling, match codebase pattern.
Rule of thumb: 3-5 examples cho tasks phức tạp. Examples nên đa dạng để cover nhiều edge cases.
Trụ Cột 2: Chain-of-Thought (CoT)
Yêu cầu AI giải thích reasoning từng bước trước khi đưa ra giải pháp. Điều này ngăn AI đưa ra shortcuts và surface-level answers.
Không có CoT
"Review authentication function này cho security issues.
[code snippet]"Với CoT
"Review authentication function này step-by-step:
1. Phân tích input validation
2. Kiểm tra password handling (hashing, salt)
3. Xem xét session management
4. Check error messages — có leak info không?
5. Timing attacks vulnerabilities?
[code snippet]"Kết quả: Analysis sâu hơn, catch được timing attacks, weak hashing, session fixation.
CoT Formula
"Hãy suy nghĩ qua các bước sau:
1. [Aspect cần xem xét đầu tiên]
2. [Second aspect]
3. [Third aspect]
4. [Verification bước cuối]
Sau đó đưa ra solution."Trụ Cột 3: Structured Context
Tổ chức thông tin rõ ràng giúp AI hiểu đúng requirements.
Unstructured (Dễ hiểu sai)
"Build API quản lý users với auth và validation, handle updates,
check permissions, validate email, support pagination, error handling."Structured (Rõ ràng, ít ambiguity)
"Build User Profile API:
## Endpoints
- GET /api/users/:id — Fetch profile
- PATCH /api/users/:id — Update profile
- GET /api/users/:id/posts — Paginated posts
## Validation
- Email: RFC 5322 compliant
- Name: 1-100 characters
- Bio: max 500 characters
## Authentication
- Tất cả endpoints require Bearer token
- User chỉ có thể sửa profile của mình
## Error Responses
- 400: Validation failed
- 401: Unauthorized
- 404: Not found
## Response Format
{ success: boolean, data: T | null, error: string | null }"CLAUDE.md: Lưu Prompt Patterns
Thay vì lặp lại prompt patterns mỗi lần, lưu vào CLAUDE.md:
# Prompting Patterns
## Code Review Checklist
Khi review code, check theo thứ tự:
1. Security: Auth, injection, sensitive data
2. Performance: N+1 queries, re-renders
3. Testing: Coverage, edge cases
4. Accessibility: Keyboard nav, screen readers
## API Design Template
Khi thiết kế API, cung cấp:
- HTTP method + route
- Request params (query, body schema)
- Response schema (success + error)
- Auth requirements
- Rate limiting
## Refactoring Brief
Khi yêu cầu refactor:
1. Mục tiêu: readability / performance / maintainability
2. Constraints: no breaking changes? backward compatible?
3. Performance target nếu optimization-focused2026 Trends: Agentic Prompting
Multi-step Workflows Trong 1 Prompt
# Cũ (đơn lẻ)
"Implement login form"
# Mới (agentic)
"Implement login form. Khi xong:
1. Review code cho security issues
2. Viết unit tests (min 80% coverage)
3. Tạo PR với description đầy đủ
4. Hỏi approval trước khi push"
Role-Based Prompting
"Bạn là security engineer chuyên về authentication.
Review code này với góc nhìn của attacker.
Tìm vulnerabilities mà developer thường bỏ qua."Structured Output
"Trả về kết quả dạng JSON:
{
'issues': [
{
'severity': 'high|medium|low',
'description': '...',
'fix': '...',
'line': number
}
],
'score': number,
'summary': '...'
}"Anti-Patterns Cần Tránh
| Tệ | Tốt |
|---|---|
| "Make the code better" | "Reduce memory usage bằng streaming thay vì load toàn bộ file" |
| "Validate user input" | "Validate email theo RFC 5322, phone theo E.164. Đây là examples: [...]" |
| "Fix the bug" + 50KB code | "Bug trong auth flow. Đây là 3 files liên quan + error message. Fix token validation" |
| "Write tests" | "Viết unit tests: 5 happy paths, 5 edge cases, 3 error cases. Dùng jest + testing-library" |
Kết Luận
Prompt Engineering không phải "nói chuyện với AI" — đó là engineering discipline. Few-shot examples cho AI thấy pattern, CoT cho AI không bỏ qua steps quan trọng, structured context eliminate ambiguity. Master 3 trụ cột này, và output từ Claude Code sẽ thay đổi hoàn toàn.