safeword 0.6.4 → 0.6.5
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/dist/{check-ICZISZ3R.js → check-OYYSYHFP.js} +3 -3
- package/dist/{chunk-JGXYBPNM.js → chunk-LNSEDZIW.js} +2 -2
- package/dist/{chunk-E5ZC6R5H.js → chunk-ZS3Z3Q37.js} +24 -15
- package/dist/chunk-ZS3Z3Q37.js.map +1 -0
- package/dist/cli.js +6 -6
- package/dist/{diff-FOJDBKKF.js → diff-325TIZ63.js} +3 -3
- package/dist/{reset-JU2E65XN.js → reset-ZGJIKMUW.js} +3 -3
- package/dist/{setup-UKMYK5TE.js → setup-GAMXTFM2.js} +3 -3
- package/dist/{sync-5MOXVTH4.js → sync-BFMXZEHM.js} +2 -2
- package/dist/{upgrade-NSLDFWNR.js → upgrade-X4GREJXN.js} +3 -3
- package/package.json +15 -14
- package/templates/SAFEWORD.md +101 -669
- package/templates/guides/architecture-guide.md +1 -1
- package/templates/guides/cli-reference.md +35 -0
- package/templates/guides/code-philosophy.md +22 -19
- package/templates/guides/context-files-guide.md +2 -2
- package/templates/guides/data-architecture-guide.md +1 -1
- package/templates/guides/design-doc-guide.md +1 -1
- package/templates/guides/{testing-methodology.md → development-workflow.md} +1 -1
- package/templates/guides/learning-extraction.md +1 -1
- package/templates/guides/{llm-instruction-design.md → llm-guide.md} +93 -29
- package/templates/guides/tdd-best-practices.md +2 -2
- package/templates/guides/test-definitions-guide.md +1 -1
- package/templates/guides/user-story-guide.md +1 -1
- package/templates/guides/zombie-process-cleanup.md +1 -1
- package/dist/chunk-E5ZC6R5H.js.map +0 -1
- package/templates/guides/llm-prompting.md +0 -102
- /package/dist/{check-ICZISZ3R.js.map → check-OYYSYHFP.js.map} +0 -0
- /package/dist/{chunk-JGXYBPNM.js.map → chunk-LNSEDZIW.js.map} +0 -0
- /package/dist/{diff-FOJDBKKF.js.map → diff-325TIZ63.js.map} +0 -0
- /package/dist/{reset-JU2E65XN.js.map → reset-ZGJIKMUW.js.map} +0 -0
- /package/dist/{setup-UKMYK5TE.js.map → setup-GAMXTFM2.js.map} +0 -0
- /package/dist/{sync-5MOXVTH4.js.map → sync-BFMXZEHM.js.map} +0 -0
- /package/dist/{upgrade-NSLDFWNR.js.map → upgrade-X4GREJXN.js.map} +0 -0
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
# LLM Prompting Best Practices
|
|
2
|
-
|
|
3
|
-
This guide covers two related topics:
|
|
4
|
-
|
|
5
|
-
**Part 1: Prompting LLMs** - How to structure prompts when actively using an LLM (API calls, chat interactions)
|
|
6
|
-
|
|
7
|
-
**Part 2: Writing Instructions for LLMs** - How to write documentation that LLMs will read and follow (SAFEWORD.md, CLAUDE.md, testing guides, coding standards)
|
|
8
|
-
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
## Part 1: Prompting LLMs
|
|
12
|
-
|
|
13
|
-
### Prompt Engineering Principles
|
|
14
|
-
|
|
15
|
-
**Concrete Examples Over Abstract Rules:**
|
|
16
|
-
|
|
17
|
-
- ✅ Good: Show "❌ BAD" vs "✅ GOOD" code examples
|
|
18
|
-
- ❌ Bad: "Follow best practices" (too vague)
|
|
19
|
-
|
|
20
|
-
**"Why" Over "What":**
|
|
21
|
-
|
|
22
|
-
- Explain architectural trade-offs and reasoning
|
|
23
|
-
- Include specific numbers (90% cost reduction, 3x faster)
|
|
24
|
-
- Document gotchas with explanations
|
|
25
|
-
|
|
26
|
-
**Structured Outputs:**
|
|
27
|
-
|
|
28
|
-
- Use JSON mode for predictable LLM responses
|
|
29
|
-
- Define explicit schemas with validation
|
|
30
|
-
- Return structured data, not prose
|
|
31
|
-
|
|
32
|
-
```typescript
|
|
33
|
-
// ❌ BAD - Prose output
|
|
34
|
-
"The user wants to create a campaign named 'Shadows' with 4 players"
|
|
35
|
-
|
|
36
|
-
// ✅ GOOD - Structured JSON
|
|
37
|
-
{ "intent": "create_campaign", "name": "Shadows", "playerCount": 4 }
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
### Cost Optimization
|
|
41
|
-
|
|
42
|
-
**Prompt Caching (Critical for AI Agents):**
|
|
43
|
-
|
|
44
|
-
- Static rules → System prompt with cache_control: ephemeral (caches for ~5 min, auto-expires)
|
|
45
|
-
- Dynamic data (character state, user input) → User message (no caching)
|
|
46
|
-
- Example: 468-line prompt costs $0.10 without caching, $0.01 with (90% reduction)
|
|
47
|
-
- Cache invalidation: ANY change to cached blocks breaks ALL caches
|
|
48
|
-
- Rule: Change system prompts sparingly; accept one-time cache rebuild cost
|
|
49
|
-
|
|
50
|
-
**Message Architecture:**
|
|
51
|
-
|
|
52
|
-
```typescript
|
|
53
|
-
// ✅ GOOD - Cacheable system prompt
|
|
54
|
-
systemPrompt: [
|
|
55
|
-
{ text: STATIC_RULES, cache_control: { type: 'ephemeral' } },
|
|
56
|
-
{ text: STATIC_EXAMPLES, cache_control: { type: 'ephemeral' } },
|
|
57
|
-
];
|
|
58
|
-
userMessage: `Character: ${dynamicState}\nAction: ${userInput}`;
|
|
59
|
-
|
|
60
|
-
// ❌ BAD - Uncacheable (character state in system prompt)
|
|
61
|
-
systemPrompt: `Rules + Character: ${dynamicState}`;
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
### Testing AI Outputs
|
|
65
|
-
|
|
66
|
-
**LLM-as-Judge Pattern:**
|
|
67
|
-
|
|
68
|
-
- Use LLM to evaluate nuanced qualities (narrative tone, reasoning quality)
|
|
69
|
-
- Avoid brittle keyword matching for creative outputs
|
|
70
|
-
- Define rubrics: EXCELLENT / ACCEPTABLE / POOR with criteria
|
|
71
|
-
- Example: "Does the GM's response show collaborative tone?" vs checking for specific words
|
|
72
|
-
|
|
73
|
-
**Evaluation Framework:**
|
|
74
|
-
|
|
75
|
-
- Unit tests: Pure functions (parsing, validation)
|
|
76
|
-
- Integration tests: Agent + real LLM calls (schema compliance)
|
|
77
|
-
- LLM Evals: Judgment quality (position/effect reasoning, atmosphere)
|
|
78
|
-
- Cost awareness: 30 scenarios ≈ $0.15-0.30 per run with caching
|
|
79
|
-
|
|
80
|
-
---
|
|
81
|
-
|
|
82
|
-
## Part 2: Writing Instructions for LLMs
|
|
83
|
-
|
|
84
|
-
**Comprehensive framework:** See @.safeword/guides/llm-instruction-design.md
|
|
85
|
-
|
|
86
|
-
**Quick summary:** When creating documentation that LLMs will read and follow (SAFEWORD.md, CLAUDE.md, testing guides, coding standards), apply 13 core principles:
|
|
87
|
-
|
|
88
|
-
1. **MECE Principle** - Decision trees must be mutually exclusive and collectively exhaustive
|
|
89
|
-
2. **Explicit Over Implicit** - Define all terms, never assume LLMs know what you mean
|
|
90
|
-
3. **No Contradictions** - Different sections must align, LLMs don't reconcile conflicts
|
|
91
|
-
4. **Concrete Examples Over Abstract Rules** - Show, don't just tell (2-3 examples per rule)
|
|
92
|
-
5. **Edge Cases Must Be Explicit** - What seems obvious to humans often isn't to LLMs
|
|
93
|
-
6. **Actionable Over Vague** - Replace subjective terms with optimization rules + red flags
|
|
94
|
-
7. **Decision Trees: Sequential Over Parallel** - Ordered steps that stop at first match
|
|
95
|
-
8. **Tie-Breaking Rules** - Tell LLMs how to choose when multiple options apply
|
|
96
|
-
9. **Lookup Tables for Complex Decisions** - Provide reference tables for complex logic
|
|
97
|
-
10. **Avoid Caveats in Tables** - Keep patterns clean, parentheticals break LLM pattern matching
|
|
98
|
-
11. **Percentages: Context or None** - Include adjustment guidance or use principles instead
|
|
99
|
-
12. **Specificity in Questions** - Use precise technical terms, not general descriptions
|
|
100
|
-
13. **Re-evaluation Paths** - Provide concrete next steps when LLMs hit dead ends
|
|
101
|
-
|
|
102
|
-
**Also includes:** Anti-patterns to avoid, quality checklist, research-backed principles, and before/after examples.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|