$npx -y skills add itsmostafa/llm-engineering-skills --skill prompt-engineeringCrafting effective prompts for LLMs. Use when designing prompts, improving output quality, structuring complex instructions, or debugging poor model responses.
| 1 | # Prompt Engineering |
| 2 | |
| 3 | Prompt engineering is the practice of designing inputs that guide LLMs to produce desired outputs. Effective prompts reduce errors, improve consistency, and unlock model capabilities. |
| 4 | |
| 5 | ## Table of Contents |
| 6 | |
| 7 | - [Core Principles](#core-principles) |
| 8 | - [Be Clear and Direct](#be-clear-and-direct) |
| 9 | - [Use Examples (Multishot)](#use-examples-multishot) |
| 10 | - [Reasoning Guidance](#reasoning-guidance) |
| 11 | - [XML Tags](#xml-tags) |
| 12 | - [Role Prompting](#role-prompting) |
| 13 | - [Long Context](#long-context) |
| 14 | - [Output Control](#output-control) |
| 15 | - [Self-Verification](#self-verification) |
| 16 | - [Best Practices](#best-practices) |
| 17 | - [References](#references) |
| 18 | |
| 19 | ## Core Principles |
| 20 | |
| 21 | **Golden rule**: Show your prompt to a colleague with minimal context. If they're confused, the model will be too. |
| 22 | |
| 23 | 1. **Be explicit** - State exactly what you want; never assume the model knows your preferences |
| 24 | 2. **Provide context** - Include what the output is for, who the audience is, and what success looks like |
| 25 | 3. **Use structure** - Sequential steps, XML tags, and clear formatting reduce ambiguity |
| 26 | 4. **Show examples** - Demonstrations outperform descriptions for complex formats |
| 27 | |
| 28 | ## Be Clear and Direct |
| 29 | |
| 30 | Treat the model as a capable but context-free collaborator. Specify: |
| 31 | - What the task results will be used for |
| 32 | - What audience the output is meant for |
| 33 | - What a successful completion looks like |
| 34 | |
| 35 | ### Vague vs Specific |
| 36 | |
| 37 | ``` |
| 38 | # Vague |
| 39 | Analyze this data and give insights. |
| 40 | |
| 41 | # Specific |
| 42 | Analyze this Q2 sales data for our board presentation. |
| 43 | 1. Identify the top 3 revenue trends |
| 44 | 2. Flag any anomalies exceeding 15% variance |
| 45 | 3. Recommend 2-3 actionable next steps |
| 46 | Format as bullet points, max 200 words. |
| 47 | ``` |
| 48 | |
| 49 | ### Sequential Steps |
| 50 | |
| 51 | Use numbered lists for multi-step tasks: |
| 52 | |
| 53 | ``` |
| 54 | Your task is to anonymize customer feedback. |
| 55 | |
| 56 | Instructions: |
| 57 | 1. Replace customer names with "CUSTOMER_[ID]" |
| 58 | 2. Replace emails with "EMAIL_[ID]@example.com" |
| 59 | 3. Redact phone numbers as "PHONE_[ID]" |
| 60 | 4. Leave product names intact |
| 61 | 5. Output only processed messages, separated by "---" |
| 62 | ``` |
| 63 | |
| 64 | ## Use Examples (Multishot) |
| 65 | |
| 66 | Provide 3-5 diverse examples to demonstrate expected behavior. Examples reduce misinterpretation and enforce consistent formatting. |
| 67 | |
| 68 | ### Structure |
| 69 | |
| 70 | ``` |
| 71 | Categorize customer feedback by issue type and sentiment. |
| 72 | |
| 73 | <examples> |
| 74 | <example> |
| 75 | Input: The dashboard loads slowly and the export button is hidden. |
| 76 | Category: UI/UX, Performance |
| 77 | Sentiment: Negative |
| 78 | Priority: High |
| 79 | </example> |
| 80 | |
| 81 | <example> |
| 82 | Input: Love the Salesforce integration! Would be great to add Hubspot. |
| 83 | Category: Integration, Feature Request |
| 84 | Sentiment: Positive |
| 85 | Priority: Medium |
| 86 | </example> |
| 87 | </examples> |
| 88 | |
| 89 | Now categorize: {{FEEDBACK}} |
| 90 | ``` |
| 91 | |
| 92 | ### Tips |
| 93 | |
| 94 | - Make examples **relevant** to actual use cases |
| 95 | - Include **edge cases** and potential challenges |
| 96 | - Vary examples to prevent unintended pattern matching |
| 97 | - Wrap in `<example>` tags for clarity |
| 98 | |
| 99 | ## Reasoning Guidance |
| 100 | |
| 101 | For complex tasks, guide the model to reason before answering, but ask for concise conclusions or verifiable work rather than unrestricted hidden chain-of-thought. |
| 102 | |
| 103 | ### Basic |
| 104 | |
| 105 | ``` |
| 106 | Determine the best investment option for this client. Think step-by-step. |
| 107 | ``` |
| 108 | |
| 109 | ### Guided |
| 110 | |
| 111 | Specify what steps to consider: |
| 112 | |
| 113 | ``` |
| 114 | Think before answering: |
| 115 | 1. Consider the client's risk tolerance given their 5-year timeline |
| 116 | 2. Calculate potential returns for each option |
| 117 | 3. Factor in market volatility history |
| 118 | 4. Then provide your recommendation |
| 119 | ``` |
| 120 | |
| 121 | ### Structured (Recommended) |
| 122 | |
| 123 | Separate private analysis instructions from the required answer format: |
| 124 | |
| 125 | ``` |
| 126 | Analyze this contract for legal risks. |
| 127 | |
| 128 | Before answering, check: |
| 129 | - Indemnification implications |
| 130 | - Liability exposure |
| 131 | - IP ownership concerns |
| 132 | |
| 133 | Then provide: |
| 134 | <answer> |
| 135 | - Top risks |
| 136 | - Recommended edits |
| 137 | - Open questions |
| 138 | </answer> |
| 139 | ``` |
| 140 | |
| 141 | When you need auditability, ask for brief supporting rationale, calculations, cited evidence, or a checklist of checks performed. Do not require full chain-of-thought unless the target model or product explicitly supports exposing it. |
| 142 | |
| 143 | ## XML Tags |
| 144 | |
| 145 | Use XML tags to separate prompt components. This prevents instruction/content confusion and improves parseability. |
| 146 | |
| 147 | ### Common Tags |
| 148 | |
| 149 | ``` |
| 150 | <instructions>Task steps and requirements</instructions> |
| 151 | <context>Background information</context> |
| 152 | <document>Source material to process</document> |
| 153 | <example>Demonstration of expected behavior</example> |
| 154 | <constraints>Boundaries and limitations</constraints> |
| 155 | <output_format>Expected response structure</output_format> |
| 156 | ``` |
| 157 | |
| 158 | ### Nested Structure |
| 159 | |
| 160 | ``` |
| 161 | <documents> |
| 162 | <document index="1"> |
| 163 | <source>annual_report_2023.pdf</source> |
| 164 | <content>{{REPORT_CONTENT}}</content> |
| 165 | </document> |
| 166 | <document index="2"> |
| 167 | <source>competitor_analysis.xlsx</source> |
| 168 | <content>{{ANALYSIS_CONTENT}}</content> |
| 169 | </document> |
| 170 | </documents> |
| 171 | |
| 172 | <instructions> |
| 173 | Compare revenue trends across bo |