Skills: Prompt Engineering Fundamentals
Last updated: 2026-08-31
The prompt is a Skill's soul — write it well, and AI is an expert; write it poorly, and AI is a parrot.
1. Prompt Design Principles
(1) The SPECIFIC Method
| Letter | Meaning | Example |
|---|---|---|
| S | Specific | "Check for SQL injection" not "Check security" |
| P | Purpose | "Prevent production data leaks" |
| E | Example | Provide a sample of expected output |
| C | Constraint | "No more than 500 words" |
| I | Interactive | "Ask follow-up questions if information is insufficient" |
| F | Format | "Output using Markdown tables" |
| I | Iterative | Continuously optimize after testing |
(2) Common Anti-Patterns
| Anti-Pattern | Problem | Improvement |
|---|---|---|
| Too vague | "Review code" | "Review across security/performance/readability dimensions" |
| No format | No output constraints | "Output in tables, sorted by severity" |
| No examples | AI output is uncontrollable | Provide 1-2 reference outputs |
| Vague role | AI doesn't know who it is | "You are a senior security audit expert" |
| Too complex | Asking too much at once | Break into steps, one clear task per step |
2. Role Setting Techniques
(1) Basic Role
MARKDOWN
You are a Python backend development expert.
(2) Enhanced Role
MARKDOWN
You are a Python backend expert with 10 years of experience, specializing in FastAPI and Django.
You are particularly skilled at:
- Database optimization and ORM tuning
- RESTful API design
- Async programming and concurrency handling
Your code style: concise, type-safe, well-commented
(3) Multi-Role Switching
MARKDOWN
# Multi-Role Skill
When the task type is "architecture design", you are a system architect focused on scalability and performance.
When the task type is "code implementation", you are a senior engineer focused on code quality and maintainability.
When the task type is "debugging", you are a troubleshooting expert focused on root cause analysis and quick fixes.
3. Task Decomposition Techniques
(1) Single-Step Task
Simple tasks can be described directly:
MARKDOWN
Read the specified Python file and check if it contains type hints.
If not, add type annotations for all functions.
(2) Multi-Step Flow
Complex tasks should be broken into steps:
MARKDOWN
Follow these steps to perform a database migration review:
## Step 1: Understand the Migration File
- Read the migration file contents
- Identify operation types (CREATE/ALTER/DROP)
## Step 2: Risk Assessment
- Check for data loss risks (DROP COLUMN, DROP TABLE)
- Check for table locking risks (ADD COLUMN without default)
- Check for performance risks (large table ADD INDEX)
## Step 3: Generate Suggestions
- For high-risk operations, suggest a step-by-step execution plan
- For low-risk operations, confirm they can be executed directly
(3) Conditional Branches
MARKDOWN
## Conditional Logic
- If Python project → Run `ruff check`
- If TypeScript project → Run `eslint`
- If Go project → Run `go vet`
- If tech stack is uncertain → Read package.json / pyproject.toml / go.mod first
4. Output Constraint Techniques
(1) Format Constraints
MARKDOWN
## Output Format
Strictly use the following JSON format:
```json
{
"summary": "One-sentence summary",
"issues": [
{
"severity": "high|medium|low",
"location": "file:line",
"description": "Issue description",
"suggestion": "Fix suggestion"
}
],
"score": 85
}
### (2) Length Constraints
```markdown
## Output Constraints
- Summary no more than 3 sentences
- Each issue no more than 100 words
- Fix suggestions must include code examples
- Total output no more than 1000 words
(3) Quality Constraints
MARKDOWN
## Quality Requirements
- Fix suggestions must be directly usable code, not pseudocode
- Severity must have clear criteria: high=security vulnerability/crash, medium=performance degradation/poor maintainability, low=style/suggestion
- Uncertain issues should be marked "requires human confirmation", do not guess
5. Example-Driven Method
Few-shot examples are the most effective means of controlling output quality:
MARKDOWN
## Example
### Input
```python
def get_user(id):
db = connect()
result = db.execute(f"SELECT * FROM users WHERE id = {id}")
return result
Output
📍 src/db.py:12 🔴 Critical: SQL injection vulnerability 📝 Using f-string to concatenate SQL, user input can directly inject malicious SQL ✅ Fix:
PYTHON
def get_user(user_id: int) -> dict:
db = connect()
result = db.execute(
"SELECT * FROM users WHERE id = ?",
(user_id,)
)
return result.fetchone()
After Alice added 3 examples to the prompt, AI output consistency improved from 60% to 95%. Bob said: "Examples are the best teachers — showing AI what you want is 10x more effective than describing what you want."
---
## ❓ FAQ
> **Q: How long should a prompt be?** **A: As long as it needs to be, typically 50-200 lines. The key is specificity and actionability, not length. Overly long prompts can cause AI to lose focus.**
> **Q: Should I write negative constraints ("don't do X")?** **A: Yes, but sparingly. Positive forward constraints ("only do X") are more effective than negative constraints ("don't do Y"). AI tends to ignore "don't" instructions.**
> **Q: How many examples should I provide?** **A: 1-3 is sufficient. 1 example shows format, 2-3 examples cover edge cases. More than 5 examples actually reduces quality.**
---
## 📖 Summary
- SPECIFIC method: Specific, Purpose, Example, Constraint, Interactive, Format, Iterative
- Role setting should be specific: expertise, style, experience level
- Task decomposition at three levels: single-step description, multi-step flow, conditional branches
- Output constraints: format, length, quality — three-pronged approach
- Few-shot examples are the most effective quality control method
---
## 📝 Exercises
1. **Basic (⭐)**: Rewrite a simple prompt you've written before using the SPECIFIC method and compare the results.
2. **Intermediate (⭐⭐)**: Write a complete prompt for an "API documentation generation" Skill, including role, process, constraints, and examples.
3. **Advanced (⭐⭐⭐)**: Design a universal prompt template framework that supports injecting different roles and rules via variables while maintaining consistent output format.