@ckelsoe/prompt-architect 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +20 -0
- package/.claude-plugin/plugin.json +18 -0
- package/CHANGELOG.md +264 -0
- package/LICENSE +21 -0
- package/MIGRATION.md +66 -0
- package/README.md +1184 -0
- package/adapters/README.md +267 -0
- package/adapters/for-cursor.mdc +138 -0
- package/adapters/for-gemini-cli.md +70 -0
- package/adapters/for-github-copilot.md +141 -0
- package/adapters/for-openai-codex-cli.md +158 -0
- package/adapters/for-windsurf.md +136 -0
- package/adapters/system-prompt.md +243 -0
- package/package.json +135 -0
- package/scripts/install.js +490 -0
- package/scripts/test.js +213 -0
- package/scripts/validate-skill.js +350 -0
- package/skills/prompt-architect/SKILL.md +331 -0
- package/skills/prompt-architect/assets/templates/ape_template.txt +5 -0
- package/skills/prompt-architect/assets/templates/bab_template.txt +15 -0
- package/skills/prompt-architect/assets/templates/broke_template.txt +15 -0
- package/skills/prompt-architect/assets/templates/cai-critique-revise_template.txt +18 -0
- package/skills/prompt-architect/assets/templates/care_template.txt +16 -0
- package/skills/prompt-architect/assets/templates/chain-of-density_template.txt +46 -0
- package/skills/prompt-architect/assets/templates/chain-of-thought_template.txt +49 -0
- package/skills/prompt-architect/assets/templates/co-star_template.txt +17 -0
- package/skills/prompt-architect/assets/templates/crispe_template.txt +14 -0
- package/skills/prompt-architect/assets/templates/ctf_template.txt +15 -0
- package/skills/prompt-architect/assets/templates/devils-advocate_template.txt +25 -0
- package/skills/prompt-architect/assets/templates/hybrid_template.txt +101 -0
- package/skills/prompt-architect/assets/templates/least-to-most_template.txt +16 -0
- package/skills/prompt-architect/assets/templates/plan-and-solve_template.txt +7 -0
- package/skills/prompt-architect/assets/templates/pre-mortem_template.txt +27 -0
- package/skills/prompt-architect/assets/templates/race_template.txt +19 -0
- package/skills/prompt-architect/assets/templates/rcot_template.txt +31 -0
- package/skills/prompt-architect/assets/templates/react_template.txt +27 -0
- package/skills/prompt-architect/assets/templates/reverse-role_template.txt +11 -0
- package/skills/prompt-architect/assets/templates/rise-ie_template.txt +23 -0
- package/skills/prompt-architect/assets/templates/rise-ix_template.txt +28 -0
- package/skills/prompt-architect/assets/templates/risen_template.txt +21 -0
- package/skills/prompt-architect/assets/templates/rpef_template.txt +26 -0
- package/skills/prompt-architect/assets/templates/rtf_template.txt +13 -0
- package/skills/prompt-architect/assets/templates/self-refine_template.txt +16 -0
- package/skills/prompt-architect/assets/templates/skeleton-of-thought_template.txt +15 -0
- package/skills/prompt-architect/assets/templates/step-back_template.txt +10 -0
- package/skills/prompt-architect/assets/templates/tidd-ec_template.txt +45 -0
- package/skills/prompt-architect/assets/templates/tree-of-thought_template.txt +30 -0
- package/skills/prompt-architect/references/frameworks/ape.md +200 -0
- package/skills/prompt-architect/references/frameworks/bab.md +242 -0
- package/skills/prompt-architect/references/frameworks/broke.md +242 -0
- package/skills/prompt-architect/references/frameworks/cai-critique-revise.md +230 -0
- package/skills/prompt-architect/references/frameworks/care.md +235 -0
- package/skills/prompt-architect/references/frameworks/chain-of-density.md +479 -0
- package/skills/prompt-architect/references/frameworks/chain-of-thought.md +424 -0
- package/skills/prompt-architect/references/frameworks/co-star.md +256 -0
- package/skills/prompt-architect/references/frameworks/crispe.md +253 -0
- package/skills/prompt-architect/references/frameworks/ctf.md +207 -0
- package/skills/prompt-architect/references/frameworks/devils-advocate.md +206 -0
- package/skills/prompt-architect/references/frameworks/least-to-most.md +226 -0
- package/skills/prompt-architect/references/frameworks/plan-and-solve.md +210 -0
- package/skills/prompt-architect/references/frameworks/pre-mortem.md +197 -0
- package/skills/prompt-architect/references/frameworks/race.md +243 -0
- package/skills/prompt-architect/references/frameworks/rcot.md +203 -0
- package/skills/prompt-architect/references/frameworks/react.md +304 -0
- package/skills/prompt-architect/references/frameworks/reverse-role.md +189 -0
- package/skills/prompt-architect/references/frameworks/rise.md +555 -0
- package/skills/prompt-architect/references/frameworks/risen.md +297 -0
- package/skills/prompt-architect/references/frameworks/rpef.md +195 -0
- package/skills/prompt-architect/references/frameworks/rtf.md +358 -0
- package/skills/prompt-architect/references/frameworks/self-refine.md +205 -0
- package/skills/prompt-architect/references/frameworks/skeleton-of-thought.md +186 -0
- package/skills/prompt-architect/references/frameworks/step-back.md +206 -0
- package/skills/prompt-architect/references/frameworks/tidd-ec.md +470 -0
- package/skills/prompt-architect/references/frameworks/tree-of-thought.md +260 -0
- package/skills/prompt-architect/scripts/framework_analyzer.py +807 -0
- package/skills/prompt-architect/scripts/prompt_evaluator.py +336 -0
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
# RTF Framework
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
RTF is the simplest prompting framework, focusing on Role, Task, and Format. It's ideal for straightforward, well-defined tasks where minimal context is needed and the primary concern is output formatting.
|
|
6
|
+
|
|
7
|
+
## Components
|
|
8
|
+
|
|
9
|
+
### R - Role
|
|
10
|
+
**Purpose:** Define the expertise or perspective needed.
|
|
11
|
+
|
|
12
|
+
**Questions to Ask:**
|
|
13
|
+
- What expertise is required?
|
|
14
|
+
- What viewpoint matters?
|
|
15
|
+
|
|
16
|
+
**Examples:**
|
|
17
|
+
- "You are a technical writer..."
|
|
18
|
+
- "Act as a Python expert..."
|
|
19
|
+
- "You're a hiring manager..."
|
|
20
|
+
|
|
21
|
+
### T - Task
|
|
22
|
+
**Purpose:** State what needs to be done clearly and concisely.
|
|
23
|
+
|
|
24
|
+
**Questions to Ask:**
|
|
25
|
+
- What exactly needs to be done?
|
|
26
|
+
- What's the deliverable?
|
|
27
|
+
- What's the core action?
|
|
28
|
+
|
|
29
|
+
**Examples:**
|
|
30
|
+
- "Write a function that sorts a list..."
|
|
31
|
+
- "Create a job description for..."
|
|
32
|
+
- "Explain how authentication works..."
|
|
33
|
+
|
|
34
|
+
### F - Format
|
|
35
|
+
**Purpose:** Specify how the output should be structured.
|
|
36
|
+
|
|
37
|
+
**Questions to Ask:**
|
|
38
|
+
- What format should output take?
|
|
39
|
+
- How should it be structured?
|
|
40
|
+
- What's the preferred presentation?
|
|
41
|
+
- Any specific formatting requirements?
|
|
42
|
+
|
|
43
|
+
**Examples:**
|
|
44
|
+
- "Provide as a markdown table..."
|
|
45
|
+
- "Format as JSON with fields..."
|
|
46
|
+
- "Write as a bullet list with..."
|
|
47
|
+
|
|
48
|
+
## Template Structure
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
ROLE: [Expertise or perspective]
|
|
52
|
+
|
|
53
|
+
TASK: [What needs to be done]
|
|
54
|
+
|
|
55
|
+
FORMAT: [How output should be structured]
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Complete Examples
|
|
59
|
+
|
|
60
|
+
### Example 1: Code Generation
|
|
61
|
+
|
|
62
|
+
**Before RTF:**
|
|
63
|
+
"Write a sorting function."
|
|
64
|
+
|
|
65
|
+
**After RTF:**
|
|
66
|
+
```
|
|
67
|
+
ROLE: You are a Python developer who writes clean, efficient code.
|
|
68
|
+
|
|
69
|
+
TASK: Write a function that sorts a list of dictionaries by a specified key, with support for ascending/descending order.
|
|
70
|
+
|
|
71
|
+
FORMAT: Provide the solution as:
|
|
72
|
+
1. Function signature with type hints
|
|
73
|
+
2. Docstring with examples
|
|
74
|
+
3. Implementation
|
|
75
|
+
4. 2-3 usage examples
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Example 2: Content Creation
|
|
79
|
+
|
|
80
|
+
**Before RTF:**
|
|
81
|
+
"Write about API security."
|
|
82
|
+
|
|
83
|
+
**After RTF:**
|
|
84
|
+
```
|
|
85
|
+
ROLE: You are a technical documentation specialist.
|
|
86
|
+
|
|
87
|
+
TASK: Create a quick reference guide for API authentication best practices, covering OAuth 2.0, JWT, and API keys.
|
|
88
|
+
|
|
89
|
+
FORMAT: Structured as:
|
|
90
|
+
- Title
|
|
91
|
+
- One-paragraph overview
|
|
92
|
+
- Three sections (one per auth method) with:
|
|
93
|
+
* When to use
|
|
94
|
+
* Pros and cons (bullet points)
|
|
95
|
+
* Implementation example
|
|
96
|
+
- Resources section with links
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Example 3: Data Presentation
|
|
100
|
+
|
|
101
|
+
**Before RTF:**
|
|
102
|
+
"Show me the comparison."
|
|
103
|
+
|
|
104
|
+
**After RTF:**
|
|
105
|
+
```
|
|
106
|
+
ROLE: You are a data analyst presenting to executives.
|
|
107
|
+
|
|
108
|
+
TASK: Compare three cloud providers (AWS, Azure, GCP) across cost, performance, and features for a mid-size company.
|
|
109
|
+
|
|
110
|
+
FORMAT: Provide as:
|
|
111
|
+
- Markdown table with providers as columns
|
|
112
|
+
- Rows: Cost (tier 1-3), Performance metrics, Key features, Pros, Cons
|
|
113
|
+
- Below table: 2-3 sentence recommendation
|
|
114
|
+
- Keep total output under 300 words
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Best Use Cases
|
|
118
|
+
|
|
119
|
+
1. **Quick Tasks**
|
|
120
|
+
- Simple explanations
|
|
121
|
+
- Short code snippets
|
|
122
|
+
- Brief comparisons
|
|
123
|
+
- Format conversions
|
|
124
|
+
|
|
125
|
+
2. **Format-Critical Tasks**
|
|
126
|
+
- When output structure is primary concern
|
|
127
|
+
- Template filling
|
|
128
|
+
- Structured data generation
|
|
129
|
+
- Report formatting
|
|
130
|
+
|
|
131
|
+
3. **Well-Defined Problems**
|
|
132
|
+
- Requirements are clear
|
|
133
|
+
- No ambiguity
|
|
134
|
+
- Standard approach exists
|
|
135
|
+
- Minimal context needed
|
|
136
|
+
|
|
137
|
+
4. **One-Off Requests**
|
|
138
|
+
- Not part of larger workflow
|
|
139
|
+
- Standalone task
|
|
140
|
+
- Doesn't need extensive setup
|
|
141
|
+
|
|
142
|
+
## Selection Criteria
|
|
143
|
+
|
|
144
|
+
**Choose RTF when:**
|
|
145
|
+
- ✅ Task is simple and well-defined
|
|
146
|
+
- ✅ Minimal context required
|
|
147
|
+
- ✅ Output format is primary concern
|
|
148
|
+
- ✅ Quick, focused execution needed
|
|
149
|
+
- ✅ No complex methodology required
|
|
150
|
+
- ✅ One-off or standalone task
|
|
151
|
+
|
|
152
|
+
**Avoid RTF when:**
|
|
153
|
+
- ❌ Complex multi-step process (use RISEN)
|
|
154
|
+
- ❌ Rich context needed (use CO-STAR)
|
|
155
|
+
- ❌ Audience/tone matters (use CO-STAR)
|
|
156
|
+
- ❌ Specific methodology required (use RISEN)
|
|
157
|
+
- ❌ Input transformation needed (use RISE)
|
|
158
|
+
|
|
159
|
+
## Common Mistakes
|
|
160
|
+
|
|
161
|
+
1. **Insufficient Task Description**
|
|
162
|
+
- Be specific about what's needed
|
|
163
|
+
- Include key requirements
|
|
164
|
+
- Define scope clearly
|
|
165
|
+
|
|
166
|
+
2. **Vague Format Requirements**
|
|
167
|
+
- Specify exact structure
|
|
168
|
+
- Mention required sections
|
|
169
|
+
- Define length/detail level
|
|
170
|
+
|
|
171
|
+
3. **Missing Role Context**
|
|
172
|
+
- Even simple tasks benefit from role
|
|
173
|
+
- Expertise level affects output
|
|
174
|
+
- Don't skip role definition
|
|
175
|
+
|
|
176
|
+
4. **Using RTF for Complex Tasks**
|
|
177
|
+
- If you need more than 3-4 sentences per component
|
|
178
|
+
- Switch to more comprehensive framework
|
|
179
|
+
|
|
180
|
+
## RTF Variations
|
|
181
|
+
|
|
182
|
+
### Minimal RTF
|
|
183
|
+
For very simple tasks:
|
|
184
|
+
```
|
|
185
|
+
As a [ROLE], [TASK] in [FORMAT].
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Example:
|
|
189
|
+
```
|
|
190
|
+
As a Python developer, write a function to validate email addresses in a code block with docstring.
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Extended RTF
|
|
194
|
+
When slightly more detail needed:
|
|
195
|
+
```
|
|
196
|
+
ROLE: [Expertise]
|
|
197
|
+
|
|
198
|
+
TASK: [What needs doing]
|
|
199
|
+
|
|
200
|
+
REQUIREMENTS:
|
|
201
|
+
- [Key requirement 1]
|
|
202
|
+
- [Key requirement 2]
|
|
203
|
+
|
|
204
|
+
FORMAT: [Output structure]
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### RTF with Examples
|
|
208
|
+
When showing examples helps:
|
|
209
|
+
```
|
|
210
|
+
ROLE: [Expertise]
|
|
211
|
+
|
|
212
|
+
TASK: [What needs doing]
|
|
213
|
+
|
|
214
|
+
EXAMPLES OF GOOD OUTPUT:
|
|
215
|
+
[Show 1-2 examples]
|
|
216
|
+
|
|
217
|
+
FORMAT: [Follow this structure]
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## When to Upgrade from RTF
|
|
221
|
+
|
|
222
|
+
**Upgrade to RISE if:**
|
|
223
|
+
- Need to specify input characteristics
|
|
224
|
+
- Processing steps matter
|
|
225
|
+
- Input → output transformation
|
|
226
|
+
|
|
227
|
+
**Upgrade to RISEN if:**
|
|
228
|
+
- Multiple steps required
|
|
229
|
+
- Need constraints/boundaries
|
|
230
|
+
- Methodology matters
|
|
231
|
+
- Success criteria complex
|
|
232
|
+
|
|
233
|
+
**Upgrade to CO-STAR if:**
|
|
234
|
+
- Audience considerations important
|
|
235
|
+
- Tone/style matter
|
|
236
|
+
- Rich context needed
|
|
237
|
+
- Content creation task
|
|
238
|
+
|
|
239
|
+
## Quick Reference
|
|
240
|
+
|
|
241
|
+
| Component | Focus | Key Question |
|
|
242
|
+
|-----------|-------|--------------|
|
|
243
|
+
| Role | Expertise | "Who should do this?" |
|
|
244
|
+
| Task | Action | "What needs to be done?" |
|
|
245
|
+
| Format | Structure | "How should it look?" |
|
|
246
|
+
|
|
247
|
+
## Format Specification Best Practices
|
|
248
|
+
|
|
249
|
+
### Good Format Specifications:
|
|
250
|
+
```
|
|
251
|
+
FORMAT:
|
|
252
|
+
Return as JSON with structure:
|
|
253
|
+
{
|
|
254
|
+
"summary": "1-2 sentence overview",
|
|
255
|
+
"items": [
|
|
256
|
+
{
|
|
257
|
+
"name": "string",
|
|
258
|
+
"priority": "high|medium|low",
|
|
259
|
+
"details": "string"
|
|
260
|
+
}
|
|
261
|
+
],
|
|
262
|
+
"total_count": number
|
|
263
|
+
}
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
```
|
|
267
|
+
FORMAT:
|
|
268
|
+
Markdown document with:
|
|
269
|
+
- H1 title
|
|
270
|
+
- Brief intro paragraph
|
|
271
|
+
- 3-5 H2 sections, each with:
|
|
272
|
+
* 2-3 paragraphs
|
|
273
|
+
* Bullet points for key takeaways
|
|
274
|
+
- Conclusion paragraph
|
|
275
|
+
- Total length: 500-700 words
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### Poor Format Specifications:
|
|
279
|
+
```
|
|
280
|
+
FORMAT: Make it nice
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
```
|
|
284
|
+
FORMAT: JSON or something
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
## Real-World Examples
|
|
288
|
+
|
|
289
|
+
### API Documentation
|
|
290
|
+
```
|
|
291
|
+
ROLE: Senior API documentation writer
|
|
292
|
+
|
|
293
|
+
TASK: Document the POST /users endpoint that creates a new user account with email, password, and optional profile data.
|
|
294
|
+
|
|
295
|
+
FORMAT:
|
|
296
|
+
Structure as:
|
|
297
|
+
- Endpoint details (method, path, auth required)
|
|
298
|
+
- Request body parameters (table: name, type, required, description)
|
|
299
|
+
- Response codes (200, 400, 409 with meanings)
|
|
300
|
+
- Example request (curl)
|
|
301
|
+
- Example response (JSON)
|
|
302
|
+
- Notes section for special behaviors
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
### Code Review Comment
|
|
306
|
+
```
|
|
307
|
+
ROLE: Experienced code reviewer
|
|
308
|
+
|
|
309
|
+
TASK: Review this function for security vulnerabilities and performance issues. Identify specific problems and suggest fixes.
|
|
310
|
+
|
|
311
|
+
FORMAT:
|
|
312
|
+
For each issue found:
|
|
313
|
+
🔴 ISSUE: [Brief title]
|
|
314
|
+
LINE: [Line number]
|
|
315
|
+
PROBLEM: [What's wrong]
|
|
316
|
+
FIX: [How to fix it]
|
|
317
|
+
SEVERITY: [High/Medium/Low]
|
|
318
|
+
|
|
319
|
+
End with overall assessment (2-3 sentences).
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
### Meeting Summary
|
|
323
|
+
```
|
|
324
|
+
ROLE: Executive assistant
|
|
325
|
+
|
|
326
|
+
TASK: Summarize this meeting transcript, focusing on decisions made and action items.
|
|
327
|
+
|
|
328
|
+
FORMAT:
|
|
329
|
+
Meeting Summary: [Title]
|
|
330
|
+
Date: [Date]
|
|
331
|
+
|
|
332
|
+
KEY DECISIONS:
|
|
333
|
+
- [Decision 1]
|
|
334
|
+
- [Decision 2]
|
|
335
|
+
|
|
336
|
+
ACTION ITEMS:
|
|
337
|
+
- [ ] [Task] - Assigned to [Person] - Due: [Date]
|
|
338
|
+
|
|
339
|
+
DISCUSSION POINTS:
|
|
340
|
+
- [Topic 1]: [Brief summary]
|
|
341
|
+
|
|
342
|
+
NEXT STEPS:
|
|
343
|
+
[What happens next]
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
## Assessment Checklist
|
|
347
|
+
|
|
348
|
+
When applying RTF, verify:
|
|
349
|
+
- [ ] Role defines clear expertise
|
|
350
|
+
- [ ] Task is specific and unambiguous
|
|
351
|
+
- [ ] Task scope is well-defined
|
|
352
|
+
- [ ] Format requirements are detailed
|
|
353
|
+
- [ ] Format is appropriate for task
|
|
354
|
+
- [ ] All three components work together
|
|
355
|
+
- [ ] Task isn't too complex for RTF
|
|
356
|
+
- [ ] No need for richer framework
|
|
357
|
+
- [ ] Output structure is clear
|
|
358
|
+
- [ ] Length/detail level specified
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# Self-Refine Framework
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Self-Refine is an iterative output improvement framework where a single model acts as its own generator, critic, and refiner — with no external training, no additional models, and no labeled data required. The core loop: generate an initial output → produce specific, actionable feedback → refine using that feedback → repeat until a stopping criterion is met.
|
|
6
|
+
|
|
7
|
+
**Research basis:** "Self-Refine: Iterative Refinement with Self-Feedback" (Madaan et al., arXiv 2303.17651, NeurIPS 2023). Tested across 7 task types — improvement of 5-40% over single-pass generation from GPT-3.5 and GPT-4. Humans preferred Self-Refined outputs in blind evaluation. Project site: selfrefine.info.
|
|
8
|
+
|
|
9
|
+
## The Core Loop
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
GENERATE → FEEDBACK → REFINE → [repeat] → STOP
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Each phase:
|
|
16
|
+
1. **Generate**: Produce an initial output (can be your first draft or AI-generated)
|
|
17
|
+
2. **Feedback**: Analyze the output for specific, actionable weaknesses across defined dimensions
|
|
18
|
+
3. **Refine**: Rewrite addressing every feedback point — with the feedback visible as context
|
|
19
|
+
4. **Stop**: When quality threshold met, max iterations reached, or feedback says "looks good"
|
|
20
|
+
|
|
21
|
+
**Key insight:** Maintaining a history of previous outputs + feedback in context prevents regression and helps the model track progress across iterations.
|
|
22
|
+
|
|
23
|
+
## Components
|
|
24
|
+
|
|
25
|
+
### Initial Output
|
|
26
|
+
**Purpose:** The starting point. Can be a first AI generation or something you've already written that needs improvement.
|
|
27
|
+
|
|
28
|
+
### Feedback Dimensions
|
|
29
|
+
**Purpose:** The specific aspects to evaluate. Defining these explicitly produces much better critiques than asking for generic feedback.
|
|
30
|
+
|
|
31
|
+
**Common dimensions by task type:**
|
|
32
|
+
- **Code**: correctness, efficiency, readability, edge cases, error handling
|
|
33
|
+
- **Writing**: clarity, structure, tone, specificity, conciseness, audience fit
|
|
34
|
+
- **Reasoning**: logical validity, completeness, unsupported claims, missed considerations
|
|
35
|
+
- **Plans/strategies**: feasibility, completeness, risks, measurability
|
|
36
|
+
|
|
37
|
+
### Refinement Instruction
|
|
38
|
+
**Purpose:** Directs the model to rewrite addressing every feedback point, using the critique as a direct specification.
|
|
39
|
+
|
|
40
|
+
### Stop Condition
|
|
41
|
+
**Purpose:** When to stop iterating. Options:
|
|
42
|
+
- Fixed iterations (e.g., "run 2 refinement cycles")
|
|
43
|
+
- Quality signal ("stop when feedback has no major issues")
|
|
44
|
+
- Manual review (you decide when it's good enough)
|
|
45
|
+
|
|
46
|
+
## Template Structure
|
|
47
|
+
|
|
48
|
+
### Single Cycle (most common)
|
|
49
|
+
```
|
|
50
|
+
INITIAL OUTPUT:
|
|
51
|
+
[Paste the output to improve, or ask the AI to generate a first draft]
|
|
52
|
+
|
|
53
|
+
FEEDBACK DIMENSIONS:
|
|
54
|
+
Review the output above for:
|
|
55
|
+
1. [Dimension 1 — e.g., "Clarity: Is every sentence clear and unambiguous?"]
|
|
56
|
+
2. [Dimension 2 — e.g., "Completeness: What important points are missing?"]
|
|
57
|
+
3. [Dimension 3 — e.g., "Tone: Is the voice appropriate for the audience?"]
|
|
58
|
+
4. [Dimension 4 — add as needed]
|
|
59
|
+
|
|
60
|
+
For each dimension: identify specific problems with quoted examples,
|
|
61
|
+
explain why each is a problem, and suggest concrete improvements.
|
|
62
|
+
|
|
63
|
+
REFINEMENT:
|
|
64
|
+
Now rewrite the output addressing every point of your feedback.
|
|
65
|
+
Show the refined version only (no commentary).
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Multi-Cycle with History
|
|
69
|
+
```
|
|
70
|
+
ITERATION 1:
|
|
71
|
+
[Generate initial output or paste existing]
|
|
72
|
+
|
|
73
|
+
ITERATION 1 FEEDBACK:
|
|
74
|
+
Analyze for [dimensions]. Be specific and actionable.
|
|
75
|
+
|
|
76
|
+
ITERATION 2:
|
|
77
|
+
Rewrite addressing all feedback above.
|
|
78
|
+
[AI produces refined version]
|
|
79
|
+
|
|
80
|
+
ITERATION 2 FEEDBACK:
|
|
81
|
+
Analyze the refined version for any remaining issues.
|
|
82
|
+
|
|
83
|
+
ITERATION 3 (if needed):
|
|
84
|
+
Rewrite addressing remaining issues.
|
|
85
|
+
|
|
86
|
+
STOP when feedback says "no major issues remaining."
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Self-Refine as a Single Compound Prompt
|
|
90
|
+
```
|
|
91
|
+
TASK: [What you want to produce]
|
|
92
|
+
|
|
93
|
+
GENERATE: Write an initial [output type] for the above.
|
|
94
|
+
|
|
95
|
+
FEEDBACK: Review your output for: [dimension 1], [dimension 2], [dimension 3].
|
|
96
|
+
List specific issues with quoted examples and concrete suggestions.
|
|
97
|
+
|
|
98
|
+
REFINE: Rewrite addressing all feedback. Show only the final refined version.
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Complete Examples
|
|
102
|
+
|
|
103
|
+
### Example 1: Code Review and Improvement
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
INITIAL OUTPUT:
|
|
107
|
+
def get_user_data(user_id):
|
|
108
|
+
db = connect_to_database()
|
|
109
|
+
result = db.query(f"SELECT * FROM users WHERE id = {user_id}")
|
|
110
|
+
return result
|
|
111
|
+
|
|
112
|
+
FEEDBACK DIMENSIONS:
|
|
113
|
+
Review for:
|
|
114
|
+
1. Security: Any injection vulnerabilities or unsafe patterns?
|
|
115
|
+
2. Error handling: What happens if the DB is unavailable or user doesn't exist?
|
|
116
|
+
3. Resource management: Are connections properly managed?
|
|
117
|
+
4. Code quality: Any Python best practices violations?
|
|
118
|
+
|
|
119
|
+
REFINEMENT:
|
|
120
|
+
Rewrite the function addressing all feedback points.
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Example 2: Writing Improvement
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
INITIAL OUTPUT:
|
|
127
|
+
[Paste a paragraph or email draft]
|
|
128
|
+
|
|
129
|
+
FEEDBACK DIMENSIONS:
|
|
130
|
+
Review for:
|
|
131
|
+
1. Clarity: Any sentences that are ambiguous or require re-reading?
|
|
132
|
+
2. Conciseness: What can be cut without losing meaning?
|
|
133
|
+
3. Opening: Does the first sentence earn the reader's attention?
|
|
134
|
+
4. Call to action: Is the desired reader action explicit and easy to take?
|
|
135
|
+
|
|
136
|
+
REFINEMENT:
|
|
137
|
+
Rewrite addressing every point. Match the original length or shorter.
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Example 3: Strategic Plan
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
INITIAL OUTPUT:
|
|
144
|
+
[Paste a strategy or plan]
|
|
145
|
+
|
|
146
|
+
FEEDBACK DIMENSIONS:
|
|
147
|
+
Review for:
|
|
148
|
+
1. Completeness: What important scenarios or stakeholders are not addressed?
|
|
149
|
+
2. Feasibility: Which actions assume resources or capabilities we may not have?
|
|
150
|
+
3. Measurability: Which outcomes have no defined success metric?
|
|
151
|
+
4. Risk: What's the biggest single point of failure?
|
|
152
|
+
|
|
153
|
+
REFINEMENT:
|
|
154
|
+
Revise the plan addressing all feedback. Add a risk mitigation note for the
|
|
155
|
+
biggest single point of failure identified.
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Best Use Cases
|
|
159
|
+
|
|
160
|
+
1. **Any Output Quality Improvement**
|
|
161
|
+
- Code, writing, plans, analysis, summaries
|
|
162
|
+
- When the first draft is never the final draft
|
|
163
|
+
|
|
164
|
+
2. **Domain-Specific Quality Gates**
|
|
165
|
+
- Code correctness + security
|
|
166
|
+
- Medical/legal content accuracy
|
|
167
|
+
- Brand voice compliance
|
|
168
|
+
|
|
169
|
+
3. **Iterative Document Refinement**
|
|
170
|
+
- Proposals, reports, documentation
|
|
171
|
+
- Any output where multiple review dimensions apply
|
|
172
|
+
|
|
173
|
+
4. **Self-QA Before Submitting**
|
|
174
|
+
- Run Self-Refine before using any AI output in high-stakes contexts
|
|
175
|
+
|
|
176
|
+
## Selection Criteria
|
|
177
|
+
|
|
178
|
+
**Choose Self-Refine when:**
|
|
179
|
+
- ✅ You have an output that needs improvement
|
|
180
|
+
- ✅ Multiple quality dimensions apply
|
|
181
|
+
- ✅ The first pass is rarely final
|
|
182
|
+
- ✅ You want systematic critique, not just vague "make it better"
|
|
183
|
+
|
|
184
|
+
**Avoid when:**
|
|
185
|
+
- ❌ You need a specific type of critique → use CAI Critique-Revise (principle-based) or Devil's Advocate (opposing argument)
|
|
186
|
+
- ❌ Task is brand new (nothing to refine yet) → generate first, then Self-Refine
|
|
187
|
+
- ❌ Simple task → direct prompt is faster
|
|
188
|
+
|
|
189
|
+
## Self-Refine vs. Similar Frameworks
|
|
190
|
+
|
|
191
|
+
| | Self-Refine | CAI Critique-Revise | BAB | Chain of Density |
|
|
192
|
+
|---|---|---|---|---|
|
|
193
|
+
| Direction | Any output → improvement | Output vs. explicit principle | Before state → after state | Content → denser compression |
|
|
194
|
+
| Critique type | Multi-dimensional quality | Principle-aligned alignment | Transformation rules | Density/information |
|
|
195
|
+
| Iterations | Configurable loop | One cycle (or more) | Single transform | N passes |
|
|
196
|
+
| Best for | General quality improvement | Alignment/compliance | Rewriting existing content | Summarization |
|
|
197
|
+
|
|
198
|
+
## Quick Reference
|
|
199
|
+
|
|
200
|
+
| Phase | Purpose | Key Question |
|
|
201
|
+
|-------|---------|--------------|
|
|
202
|
+
| Generate | Initial output | "What's a first pass?" |
|
|
203
|
+
| Feedback | Specific critique | "What's wrong and why?" |
|
|
204
|
+
| Refine | Improved version | "Fix every problem found" |
|
|
205
|
+
| Stop | Termination | "Is it good enough?" |
|