Prompt Optimization Skill
Overview
Transform any request into an optimized, production-ready prompt for Claude 4.x that eliminates hallucinations and ensures first-response accuracy. Apply investigation-first protocols, extended thinking patterns, and anti-hallucination guards.
When to Use
Trigger this skill when:
-
User requests prompt improvement or optimization
-
Prompt contains "optimize", "improve my prompt", "make this better"
-
Vague requests need clarification and structure
-
Existing prompts show hallucination issues
-
User mentions "investigation first", "anti-hallucination", "production-ready"
Quick Start
Basic Optimization
User: "optimize: [paste prompt]" → Analyze structure → Apply Claude 4.x patterns → Return production version
Eliminate Hallucinations
User: "fix hallucinations in: [prompt]" → Add investigation protocol → Insert verification checkpoints → Remove speculation triggers
Core Optimization Framework
6 Key Strategies
- Context & Motivation
Explain WHY, not just WHAT.
❌ WEAK: "Never use ellipses" ✅ STRONG: "Your response will be read by text-to-speech, so never use ellipses since TTS cannot pronounce them."
- Investigation-First
NEVER provide answers before investigating.
<investigation_required> When user asks: "Fix this bug"
❌ DON'T: Immediately suggest fixes ✅ DO:
-
Examine code structure
-
Identify error location
-
Trace execution path
-
Review logs
-
Form evidence-based hypothesis
-
THEN suggest solution </investigation_required>
-
Multishot Examples
Provide 2-3 examples covering different scenarios.
<multishot_pattern>
- Typical case (80% of scenarios)
- Edge case (unusual but valid)
- Error case (what NOT to do) </multishot_pattern>
- Explicit Output Format
Define EXACTLY what output should look like.
<output_format> Structure:
- Summary (2-3 sentences)
- Key Findings (bullets)
- Recommendations (numbered)
- Next Steps (actions)
Do NOT include opinions or speculation. </output_format>
- Extended Thinking
For complex tasks, enable step-by-step reasoning.
<thinking_protocol> Break down the problem:
-
What are we achieving?
-
What info do we have?
-
What steps are needed?
-
What could go wrong?
-
How do we verify? </thinking_protocol>
-
Anti-Hallucination Guards
<anti_hallucination> <rules>
- NEVER make up facts/statistics
- ALWAYS cite sources when available
- Use "I don't know" when uncertain
- Investigate before answering
- Verify against context </rules>
<when_uncertain> If info not in context:
- State what you DO know
- Explain what's missing
- Suggest how to find it
- DON'T guess </when_uncertain> </anti_hallucination>
Optimized Prompt Template
Use this structure:
<role> Specific expert role with domain knowledge </role>
<context> Why this task matters and background </context>
<investigation> What to check before responding:
- Information to gather
- Resources to consult
- Questions to clarify </investigation>
<thinking> Step-by-step approach:
- Analyze request
- Identify requirements
- Consider edge cases
- Plan response
- Verify assumptions </thinking>
<execution> How to perform the task:
- Steps to follow
- Tools/methods to use
- Quality checks </execution>
<output_format> Exact format for response </output_format>
<anti_hallucination> Never speculate. If uncertain, state clearly. </anti_hallucination>
<examples> <example type="typical">[Ex 1]</example> <example type="edge">[Ex 2]</example> <example type="error">[Ex 3]</example> </examples> </optimized_prompt_template>
Claude 4.x Features
Extended Thinking
Enable for complex reasoning tasks.
<extended_thinking> Use when task requires:
- Multi-step analysis
- Complex problem solving
- Long-horizon planning
Pattern: "Think step-by-step:
- [Step]
- [Step]
- [Verification]" </extended_thinking>
Parallel Tool Calling
Run multiple operations simultaneously.
<parallel_tools> ✅ DO: Call tools in parallel when independent ❌ DON'T: Sequential when unnecessary
Example: "Fetch user AND load settings AND check permissions" → All run simultaneously </parallel_tools>
Long-Horizon Tasks
Track progress across interactions.
<long_horizon> <state_management>
- Create progress.txt
- Log completed subtasks
- Note blockers
- Update after each step </state_management>
<continuation> When resuming:
- Read progress.txt
- Verify last state
- Continue next task
- Update progress </continuation> </long_horizon>
MCP Integration
<mcp_pattern> <discovery>
- Check MCP resources
- Identify relevant tools
- Load contextual prompts </discovery>
<execution> User asks about data:
- Search MCP resources
- Use MCP tools for real-time data
- Apply MCP formatting prompts
- Combine response </execution>
<example> "What's in Q4 sales report?" → MCP Resource: google_drive://Q4_Sales.xlsx → MCP Tool: parse_excel() → MCP Prompt: sales_summary_template → Return formatted analysis </example> </mcp_pattern>
Real-World Examples
Example 1: Vague → Structured
Before: "Help me build a website"
After: See website-build-example.md
Example 2: Bug Fix → Investigation-First
Before: "My app crashes on submit"
After: See bug-fix-example.md
Example 3: Data Analysis → Verification-First
Before: "Analyze this CSV"
After: See data-analysis-example.md
Advanced Patterns
Self-Verification
<self_verification> After generating response:
- Review vs requirements
- Check hallucinations
- Verify facts
- Confirm format
- Test edge cases
Issues found? Revise before delivery. </self_verification>
Progressive Refinement
<progressive_refinement> For complex prompts:
- Start basic
- Test samples
- Identify failures
- Add guards
- Retest
- Document
Iterate based on performance. </progressive_refinement>
Context Management
<context_optimization> For large prompts:
- Essential First: Core instructions at top
- Progressive Disclosure: Details on-demand
- References: Link vs including
- Examples Last: After instructions
If >2000 words:
- Split into skill + references/
- Use MCP for external resources </context_optimization>
Guidelines
Always Do:
✅ Investigate before answering ✅ Provide multiple examples ✅ Define clear output format ✅ Include anti-hallucination guards ✅ Explain WHY, not just WHAT ✅ Use XML for structure ✅ Test with edge cases
Never Do:
❌ Skip investigation ❌ Assume intent ❌ Single example only ❌ Ambiguous output format ❌ Ignore hallucination risks ❌ Vague instructions ❌ Deliver untested prompts
Red Flags (Fix These):
🚩 "Create something" (too vague) 🚩 No examples 🚩 Missing output format 🚩 No verification steps 🚩 Assumes context 🚩 No anti-hallucination guards 🚩 Single-shot examples
Output Template
Deliver this when optimizing:
Optimized Prompt
[Complete optimized prompt in XML format]
Optimization Summary
Changes Made:
- Added investigation protocol
- Included multishot examples
- Defined output format
- Added anti-hallucination guards
- [Others]
Expected Improvements:
- Hallucination reduction: ~X%
- First-response accuracy: ~Y%
- Clarity: High/Medium/Low
Testing Checklist:
- Typical case
- Edge case
- Error/invalid input
- Ambiguous request
- Missing info
Ready to use!
Quality Metrics
Metric Target
Hallucination Rate <5%
First-Response Success
90%
Iterations Needed 1-2
Clarity Score High
Additional Resources
For detailed examples and deep-dive topics:
-
See references/ directory for complete examples
-
Claude 4.x documentation
-
MCP specification
-
Anthropic prompt engineering guide
Version: 1.0.0 | Optimized for Claude 4.x