Prompt Engineer
Overview
This skill covers systematic design and iteration of prompts for large language models (LLMs). It applies proven techniques — zero-shot, few-shot learning, chain-of-thought reasoning, role prompting, structured output constraints, system prompt design, and multi-step prompt chaining — to improve accuracy, consistency, and reliability of LLM outputs. The skill is applicable to any LLM API (OpenAI, Anthropic, Gemini, Mistral, open-source models) and covers both single-turn and multi-turn conversation design, as well as production-grade prompt templates with variable injection.
When to Use
- A prompt produces inconsistent, vague, or off-format outputs and needs iteration
- Designing prompts that must return structured JSON, XML, Markdown, or CSV output
- Building few-shot examples to guide classification, extraction, or transformation tasks
- Creating system prompts that establish persona, tone, constraints, or output rules
- Chaining multiple prompts together for complex multi-step reasoning tasks
- Reducing hallucination by adding grounding instructions, citations requirements, or self-checks
- Optimizing a prompt for a specific model (GPT-4, Claude, Llama, etc.) given its strengths
- Converting a vague user request into a precise, production-ready prompt template
When NOT to Use
- Fine-tuning or training a model on new data (use model training skills)
- Evaluating model quality across a benchmark suite (use eval-designer skill)
- Writing application code that calls the LLM API (use a coding skill)
- Comparing different LLMs for a use case (use model-comparator skill)
- RAG pipeline design (retrieval-augmented generation requires its own architecture skill)
Quick Reference
| Task |
Approach |
| Get consistent structured output |
Add explicit format spec + JSON schema example in the prompt |
| Improve reasoning accuracy |
Use chain-of-thought: "Think step by step before answering" |
| Classify text reliably |
Provide 2–3 labeled few-shot examples per class |
| Set model persona and constraints |
Write a detailed system prompt before the user turn |
| Handle long complex tasks |
Break into a prompt chain with intermediate outputs |
| Reduce hallucinations |
Instruct model to cite sources or say "I don't know" explicitly |
| Make outputs deterministic |
Lower temperature + explicit format constraints |
Instructions
Define the task precisely — Write a one-sentence task definition: what the model must do, what the input is, and what the output must look like. Vague tasks produce vague outputs. Example: "Extract all company names and their associated revenue figures from the following earnings call transcript and return them as a JSON array."
Choose the prompting technique — Select based on task complexity:
- Zero-shot: Simple tasks with clear instructions. No examples needed.
- Few-shot: Classification, formatting, or style tasks. Provide 2–5 labeled examples.
- Chain-of-thought (CoT): Math, logic, multi-step reasoning. Add "Think step by step."
- Role prompting: Tasks requiring expertise or persona. "You are a senior tax attorney…"
- Self-consistency: Run the same CoT prompt N times and majority-vote the answer.
- Prompt chaining: Decompose a complex task into sequential prompts where each feeds the next.
Write the system prompt — For APIs that support system prompts (OpenAI, Anthropic), put persistent instructions here: role, output format, constraints, what to do when uncertain. Keep it under 500 tokens unless the task genuinely requires more context.
Structure the user prompt — Use clear delimiters to separate instructions from input data. Use XML tags (<document>, <query>), triple backticks, or --- separators. Place instructions before the data, not after.
Specify output format explicitly — Tell the model exactly what format to use. If JSON, provide the schema or a filled example. If Markdown, show the heading structure. If a list, show how items should be formatted. Include a negative example if there is a common wrong format to avoid.
Add few-shot examples — For classification or extraction tasks, include 2–5 examples in the prompt. Format them identically to the real input/output pair. Choose examples that cover edge cases and are representative of the real distribution.
Iterate and test — Test on at least 10 representative inputs. Track: did the model follow the format? Did it hallucinate? Was the reasoning correct? Identify failure patterns and add instructions or examples to address them.
Version and document the prompt — Save prompts in a template file with variable placeholders ({{input}}). Document what model version it was tested on, what temperature, and what the expected pass rate is.
Optimize for the target model — Different models respond differently: Claude prefers XML tags and explicit role instructions; GPT-4 responds well to numbered instructions; open-source models often need more explicit format constraints. Test the same prompt on the target model even if it worked on another.
Add safety and fallback instructions — Include: what to do if the input is out of scope, how to handle ambiguous inputs, whether to ask for clarification or make a best-effort attempt, and how to indicate low confidence.
Examples
Example 1: Improving a Vague Prompt to Get Structured JSON Output
Input:
Original vague prompt: "Summarize this customer review and tell me if it's positive or negative."
Output:
Improved prompt (system + user):
SYSTEM:
You are a sentiment analysis assistant. You always respond with valid JSON only — no prose, no markdown fences. If you cannot determine sentiment, set "sentiment" to "unknown" and explain in "reason".
USER:
Analyze the following customer review. Return a JSON object with exactly these fields:
{
"sentiment": "positive" | "negative" | "neutral" | "unknown",
"confidence": 0.0–1.0,
"key_themes": ["theme1", "theme2"],
"summary": "one sentence summary",
"reason": "brief explanation of sentiment classification"
}
Review:
<review>
{{customer_review_text}}
</review>
Why this works:
- System prompt enforces JSON-only output at the model level
- Explicit schema with types eliminates ambiguity
- XML tag delimiter prevents the model from treating the review text as instructions
"unknown" fallback prevents hallucinated confident answers
confidence field enables downstream filtering of low-quality classifications
Example 2: Few-Shot Chain-of-Thought Prompt for Legal Clause Classification
Input:
Task: Classify contract clauses as "liability-limiting", "indemnification", "IP-assignment", or "other".
The model keeps misclassifying indemnification clauses as liability-limiting.
Output:
Few-shot CoT system prompt:
SYSTEM:
You are a contract analysis assistant specializing in clause classification. Think through each clause step by step before classifying. Respond only in the format shown in the examples.
USER:
Classify each contract clause. Think step by step, then provide your classification.
---
EXAMPLE 1:
Clause: "Neither party shall be liable for indirect, incidental, or consequential damages arising out of this agreement."
Reasoning: This clause restricts what types of damages can be claimed. It limits liability exposure — it does not require one party to protect another. This is a liability cap, not an indemnification.
Classification: liability-limiting
---
EXAMPLE 2:
Clause: "Vendor shall indemnify, defend, and hold harmless Client from any third-party claims arising from Vendor's breach of this agreement."
Reasoning: This clause requires the Vendor to actively protect the Client from external claims. It creates an obligation to defend and compensate — this is indemnification, not merely limiting damages.
Classification: indemnification
---
EXAMPLE 3:
Clause: "All work product created by Contractor under this agreement is assigned to Client upon creation."
Reasoning: This clause transfers ownership of created works. It concerns who owns intellectual property, not liability or indemnification.
Classification: IP-assignment
---
Now classify this clause:
Clause: "{{clause_text}}"
Reasoning:
Why this works:
- Chain-of-thought examples show the model the reasoning pattern to distinguish similar categories
- The two easily-confused categories (liability vs indemnification) each get an explicit contrasting example
- Format template forces reasoning before classification, reducing snap-judgment errors
Reasoning: at the end primes the model to complete the reasoning before the answer
Best Practices
- Always test prompts on at least 10 real inputs before declaring them production-ready
- Version prompts in code just like application code — breaking changes in prompts are real bugs
- Use the lowest effective temperature: 0.0 for deterministic extraction, 0.7–1.0 for creative tasks
- Prefer XML tags over triple backticks as delimiters — they're less likely to appear in real input
- Put the most important instructions at the beginning AND end of the prompt (primacy + recency effect)
- When using few-shot examples, ensure they cover the edge cases you care about most
- Keep system prompts focused — every sentence should earn its token budget
- Use "You must" and "Always" for hard constraints; use "prefer" or "try to" for soft preferences
Common Mistakes
- Giving vague instructions like "be helpful and accurate" without specifying what accuracy means
- Not specifying what to do when the model is uncertain — it will hallucinate a confident answer
- Using too many few-shot examples (>10) which can cause the model to pattern-match instead of reason
- Forgetting to test the prompt on the actual target model — prompts are not portable across models
- Putting instructions after the input data — models weight early context more heavily
- Asking multiple distinct tasks in one prompt — split into separate prompts or clearly numbered steps
- Assuming the same prompt works at different temperatures — always co-tune prompt and temperature
Tips & Tricks
- Add "Do not add any text before or after the JSON" to enforce clean parseable JSON output
- Use "If you are unsure, say 'I don't know' rather than guessing" to reduce hallucination
- For long documents, use "Here is the most relevant section:" before the content to focus attention
- Chain-of-thought is most effective in the middle of a response — put format instructions last
- "Let's think step by step" reliably improves math and logic; for simpler tasks it wastes tokens
- Test prompt robustness by deliberately injecting adversarial inputs (e.g., "ignore previous instructions")
- Use Anthropic's Constitutional AI principles or OpenAI's system prompt best practices as references
Related Skills
1---2name: prompt-engineer3description: Use this skill when crafting, iterating, or optimizing prompts for LLMs including zero-shot, few-shot, chain-of-thought, role prompting, structured output, and prompt chaining. Not for fine-tuning or training models. Not for evaluating model quality across benchmarks.4license: MIT5---67# Prompt Engineer89## Overview10This skill covers systematic design and iteration of prompts for large language models (LLMs). It applies proven techniques — zero-shot, few-shot learning, chain-of-thought reasoning, role prompting, structured output constraints, system prompt design, and multi-step prompt chaining — to improve accuracy, consistency, and reliability of LLM outputs. The skill is applicable to any LLM API (OpenAI, Anthropic, Gemini, Mistral, open-source models) and covers both single-turn and multi-turn conversation design, as well as production-grade prompt templates with variable injection.1112## When to Use13- A prompt produces inconsistent, vague, or off-format outputs and needs iteration14- Designing prompts that must return structured JSON, XML, Markdown, or CSV output15- Building few-shot examples to guide classification, extraction, or transformation tasks16- Creating system prompts that establish persona, tone, constraints, or output rules17- Chaining multiple prompts together for complex multi-step reasoning tasks18- Reducing hallucination by adding grounding instructions, citations requirements, or self-checks19- Optimizing a prompt for a specific model (GPT-4, Claude, Llama, etc.) given its strengths20- Converting a vague user request into a precise, production-ready prompt template2122## When NOT to Use23- Fine-tuning or training a model on new data (use model training skills)24- Evaluating model quality across a benchmark suite (use eval-designer skill)25- Writing application code that calls the LLM API (use a coding skill)26- Comparing different LLMs for a use case (use model-comparator skill)27- RAG pipeline design (retrieval-augmented generation requires its own architecture skill)2829## Quick Reference30| Task | Approach |31|------|----------|32| Get consistent structured output | Add explicit format spec + JSON schema example in the prompt |33| Improve reasoning accuracy | Use chain-of-thought: "Think step by step before answering" |34| Classify text reliably | Provide 2–3 labeled few-shot examples per class |35| Set model persona and constraints | Write a detailed system prompt before the user turn |36| Handle long complex tasks | Break into a prompt chain with intermediate outputs |37| Reduce hallucinations | Instruct model to cite sources or say "I don't know" explicitly |38| Make outputs deterministic | Lower temperature + explicit format constraints |3940## Instructions41421. **Define the task precisely** — Write a one-sentence task definition: what the model must do, what the input is, and what the output must look like. Vague tasks produce vague outputs. Example: "Extract all company names and their associated revenue figures from the following earnings call transcript and return them as a JSON array."43442. **Choose the prompting technique** — Select based on task complexity:45 - **Zero-shot**: Simple tasks with clear instructions. No examples needed.46 - **Few-shot**: Classification, formatting, or style tasks. Provide 2–5 labeled examples.47 - **Chain-of-thought (CoT)**: Math, logic, multi-step reasoning. Add "Think step by step."48 - **Role prompting**: Tasks requiring expertise or persona. "You are a senior tax attorney…"49 - **Self-consistency**: Run the same CoT prompt N times and majority-vote the answer.50 - **Prompt chaining**: Decompose a complex task into sequential prompts where each feeds the next.51523. **Write the system prompt** — For APIs that support system prompts (OpenAI, Anthropic), put persistent instructions here: role, output format, constraints, what to do when uncertain. Keep it under 500 tokens unless the task genuinely requires more context.53544. **Structure the user prompt** — Use clear delimiters to separate instructions from input data. Use XML tags (`<document>`, `<query>`), triple backticks, or `---` separators. Place instructions before the data, not after.55565. **Specify output format explicitly** — Tell the model exactly what format to use. If JSON, provide the schema or a filled example. If Markdown, show the heading structure. If a list, show how items should be formatted. Include a negative example if there is a common wrong format to avoid.57586. **Add few-shot examples** — For classification or extraction tasks, include 2–5 examples in the prompt. Format them identically to the real input/output pair. Choose examples that cover edge cases and are representative of the real distribution.59607. **Iterate and test** — Test on at least 10 representative inputs. Track: did the model follow the format? Did it hallucinate? Was the reasoning correct? Identify failure patterns and add instructions or examples to address them.61628. **Version and document the prompt** — Save prompts in a template file with variable placeholders (`{{input}}`). Document what model version it was tested on, what temperature, and what the expected pass rate is.63649. **Optimize for the target model** — Different models respond differently: Claude prefers XML tags and explicit role instructions; GPT-4 responds well to numbered instructions; open-source models often need more explicit format constraints. Test the same prompt on the target model even if it worked on another.656610. **Add safety and fallback instructions** — Include: what to do if the input is out of scope, how to handle ambiguous inputs, whether to ask for clarification or make a best-effort attempt, and how to indicate low confidence.6768## Examples6970### Example 1: Improving a Vague Prompt to Get Structured JSON Output71**Input:**72```73Original vague prompt: "Summarize this customer review and tell me if it's positive or negative."74```7576**Output:**7778**Improved prompt (system + user):**79```80SYSTEM:81You are a sentiment analysis assistant. You always respond with valid JSON only — no prose, no markdown fences. If you cannot determine sentiment, set "sentiment" to "unknown" and explain in "reason".8283USER:84Analyze the following customer review. Return a JSON object with exactly these fields:85{86 "sentiment": "positive" | "negative" | "neutral" | "unknown",87 "confidence": 0.0–1.0,88 "key_themes": ["theme1", "theme2"],89 "summary": "one sentence summary",90 "reason": "brief explanation of sentiment classification"91}9293Review:94<review>95{{customer_review_text}}96</review>97```9899**Why this works:**100- System prompt enforces JSON-only output at the model level101- Explicit schema with types eliminates ambiguity102- XML tag delimiter prevents the model from treating the review text as instructions103- `"unknown"` fallback prevents hallucinated confident answers104- `confidence` field enables downstream filtering of low-quality classifications105106### Example 2: Few-Shot Chain-of-Thought Prompt for Legal Clause Classification107**Input:**108```109Task: Classify contract clauses as "liability-limiting", "indemnification", "IP-assignment", or "other".110The model keeps misclassifying indemnification clauses as liability-limiting.111```112113**Output:**114115**Few-shot CoT system prompt:**116```117SYSTEM:118You are a contract analysis assistant specializing in clause classification. Think through each clause step by step before classifying. Respond only in the format shown in the examples.119120USER:121Classify each contract clause. Think step by step, then provide your classification.122123---124EXAMPLE 1:125Clause: "Neither party shall be liable for indirect, incidental, or consequential damages arising out of this agreement."126Reasoning: This clause restricts what types of damages can be claimed. It limits liability exposure — it does not require one party to protect another. This is a liability cap, not an indemnification.127Classification: liability-limiting128129---130EXAMPLE 2:131Clause: "Vendor shall indemnify, defend, and hold harmless Client from any third-party claims arising from Vendor's breach of this agreement."132Reasoning: This clause requires the Vendor to actively protect the Client from external claims. It creates an obligation to defend and compensate — this is indemnification, not merely limiting damages.133Classification: indemnification134135---136EXAMPLE 3:137Clause: "All work product created by Contractor under this agreement is assigned to Client upon creation."138Reasoning: This clause transfers ownership of created works. It concerns who owns intellectual property, not liability or indemnification.139Classification: IP-assignment140141---142Now classify this clause:143Clause: "{{clause_text}}"144Reasoning:145```146147**Why this works:**148- Chain-of-thought examples show the model the reasoning pattern to distinguish similar categories149- The two easily-confused categories (liability vs indemnification) each get an explicit contrasting example150- Format template forces reasoning before classification, reducing snap-judgment errors151- `Reasoning:` at the end primes the model to complete the reasoning before the answer152153## Best Practices154- Always test prompts on at least 10 real inputs before declaring them production-ready155- Version prompts in code just like application code — breaking changes in prompts are real bugs156- Use the lowest effective temperature: 0.0 for deterministic extraction, 0.7–1.0 for creative tasks157- Prefer XML tags over triple backticks as delimiters — they're less likely to appear in real input158- Put the most important instructions at the beginning AND end of the prompt (primacy + recency effect)159- When using few-shot examples, ensure they cover the edge cases you care about most160- Keep system prompts focused — every sentence should earn its token budget161- Use "You must" and "Always" for hard constraints; use "prefer" or "try to" for soft preferences162163## Common Mistakes164- Giving vague instructions like "be helpful and accurate" without specifying what accuracy means165- Not specifying what to do when the model is uncertain — it will hallucinate a confident answer166- Using too many few-shot examples (>10) which can cause the model to pattern-match instead of reason167- Forgetting to test the prompt on the actual target model — prompts are not portable across models168- Putting instructions after the input data — models weight early context more heavily169- Asking multiple distinct tasks in one prompt — split into separate prompts or clearly numbered steps170- Assuming the same prompt works at different temperatures — always co-tune prompt and temperature171172## Tips & Tricks173- Add "Do not add any text before or after the JSON" to enforce clean parseable JSON output174- Use "If you are unsure, say 'I don't know' rather than guessing" to reduce hallucination175- For long documents, use "Here is the most relevant section:" before the content to focus attention176- Chain-of-thought is most effective in the middle of a response — put format instructions last177- "Let's think step by step" reliably improves math and logic; for simpler tasks it wastes tokens178- Test prompt robustness by deliberately injecting adversarial inputs (e.g., "ignore previous instructions")179- Use Anthropic's Constitutional AI principles or OpenAI's system prompt best practices as references180181## Related Skills182- [dataset-curator](../dataset-curator/SKILL.md)183- [eval-designer](../eval-designer/SKILL.md)184- [model-comparator](../model-comparator/SKILL.md)