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."4version: 1.0.05author: community6tags: [ai, prompt-engineering, llm, optimization]7license: MIT8metadata:9 source: https://skillmd.com/skills/xcrrr/prompt-engineer10---1112# Prompt Engineer1314## Overview15This 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.1617## When to Use18- A prompt produces inconsistent, vague, or off-format outputs and needs iteration19- Designing prompts that must return structured JSON, XML, Markdown, or CSV output20- Building few-shot examples to guide classification, extraction, or transformation tasks21- Creating system prompts that establish persona, tone, constraints, or output rules22- Chaining multiple prompts together for complex multi-step reasoning tasks23- Reducing hallucination by adding grounding instructions, citations requirements, or self-checks24- Optimizing a prompt for a specific model (GPT-4, Claude, Llama, etc.) given its strengths25- Converting a vague user request into a precise, production-ready prompt template2627## When NOT to Use28- Fine-tuning or training a model on new data (use model training skills)29- Evaluating model quality across a benchmark suite (use eval-designer skill)30- Writing application code that calls the LLM API (use a coding skill)31- Comparing different LLMs for a use case (use model-comparator skill)32- RAG pipeline design (retrieval-augmented generation requires its own architecture skill)3334## Quick Reference35| Task | Approach |36|------|----------|37| Get consistent structured output | Add explicit format spec + JSON schema example in the prompt |38| Improve reasoning accuracy | Use chain-of-thought: "Think step by step before answering" |39| Classify text reliably | Provide 2–3 labeled few-shot examples per class |40| Set model persona and constraints | Write a detailed system prompt before the user turn |41| Handle long complex tasks | Break into a prompt chain with intermediate outputs |42| Reduce hallucinations | Instruct model to cite sources or say "I don't know" explicitly |43| Make outputs deterministic | Lower temperature + explicit format constraints |4445## Instructions46471. **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."48492. **Choose the prompting technique** — Select based on task complexity:50 - **Zero-shot**: Simple tasks with clear instructions. No examples needed.51 - **Few-shot**: Classification, formatting, or style tasks. Provide 2–5 labeled examples.52 - **Chain-of-thought (CoT)**: Math, logic, multi-step reasoning. Add "Think step by step."53 - **Role prompting**: Tasks requiring expertise or persona. "You are a senior tax attorney…"54 - **Self-consistency**: Run the same CoT prompt N times and majority-vote the answer.55 - **Prompt chaining**: Decompose a complex task into sequential prompts where each feeds the next.56573. **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.58594. **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.60615. **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.62636. **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.64657. **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.66678. **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.68699. **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.707110. **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.7273## Examples7475### Example 1: Improving a Vague Prompt to Get Structured JSON Output76**Input:**77```78Original vague prompt: "Summarize this customer review and tell me if it's positive or negative."79```8081**Output:**8283**Improved prompt (system + user):**84```85SYSTEM:86You 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".8788USER:89Analyze the following customer review. Return a JSON object with exactly these fields:90{91 "sentiment": "positive" | "negative" | "neutral" | "unknown",92 "confidence": 0.0–1.0,93 "key_themes": ["theme1", "theme2"],94 "summary": "one sentence summary",95 "reason": "brief explanation of sentiment classification"96}9798Review:99<review>100{{customer_review_text}}101</review>102```103104**Why this works:**105- System prompt enforces JSON-only output at the model level106- Explicit schema with types eliminates ambiguity107- XML tag delimiter prevents the model from treating the review text as instructions108- `"unknown"` fallback prevents hallucinated confident answers109- `confidence` field enables downstream filtering of low-quality classifications110111### Example 2: Few-Shot Chain-of-Thought Prompt for Legal Clause Classification112**Input:**113```114Task: Classify contract clauses as "liability-limiting", "indemnification", "IP-assignment", or "other".115The model keeps misclassifying indemnification clauses as liability-limiting.116```117118**Output:**119120**Few-shot CoT system prompt:**121```122SYSTEM:123You 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.124125USER:126Classify each contract clause. Think step by step, then provide your classification.127128---129EXAMPLE 1:130Clause: "Neither party shall be liable for indirect, incidental, or consequential damages arising out of this agreement."131Reasoning: 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.132Classification: liability-limiting133134---135EXAMPLE 2:136Clause: "Vendor shall indemnify, defend, and hold harmless Client from any third-party claims arising from Vendor's breach of this agreement."137Reasoning: 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.138Classification: indemnification139140---141EXAMPLE 3:142Clause: "All work product created by Contractor under this agreement is assigned to Client upon creation."143Reasoning: This clause transfers ownership of created works. It concerns who owns intellectual property, not liability or indemnification.144Classification: IP-assignment145146---147Now classify this clause:148Clause: "{{clause_text}}"149Reasoning:150```151152**Why this works:**153- Chain-of-thought examples show the model the reasoning pattern to distinguish similar categories154- The two easily-confused categories (liability vs indemnification) each get an explicit contrasting example155- Format template forces reasoning before classification, reducing snap-judgment errors156- `Reasoning:` at the end primes the model to complete the reasoning before the answer157158## Best Practices159- Always test prompts on at least 10 real inputs before declaring them production-ready160- Version prompts in code just like application code — breaking changes in prompts are real bugs161- Use the lowest effective temperature: 0.0 for deterministic extraction, 0.7–1.0 for creative tasks162- Prefer XML tags over triple backticks as delimiters — they're less likely to appear in real input163- Put the most important instructions at the beginning AND end of the prompt (primacy + recency effect)164- When using few-shot examples, ensure they cover the edge cases you care about most165- Keep system prompts focused — every sentence should earn its token budget166- Use "You must" and "Always" for hard constraints; use "prefer" or "try to" for soft preferences167168## Common Mistakes169- Giving vague instructions like "be helpful and accurate" without specifying what accuracy means170- Not specifying what to do when the model is uncertain — it will hallucinate a confident answer171- Using too many few-shot examples (>10) which can cause the model to pattern-match instead of reason172- Forgetting to test the prompt on the actual target model — prompts are not portable across models173- Putting instructions after the input data — models weight early context more heavily174- Asking multiple distinct tasks in one prompt — split into separate prompts or clearly numbered steps175- Assuming the same prompt works at different temperatures — always co-tune prompt and temperature176177## Tips & Tricks178- Add "Do not add any text before or after the JSON" to enforce clean parseable JSON output179- Use "If you are unsure, say 'I don't know' rather than guessing" to reduce hallucination180- For long documents, use "Here is the most relevant section:" before the content to focus attention181- Chain-of-thought is most effective in the middle of a response — put format instructions last182- "Let's think step by step" reliably improves math and logic; for simpler tasks it wastes tokens183- Test prompt robustness by deliberately injecting adversarial inputs (e.g., "ignore previous instructions")184- Use Anthropic's Constitutional AI principles or OpenAI's system prompt best practices as references185186## Related Skills187- [dataset-curator](../dataset-curator/SKILL.md)188- [eval-designer](../eval-designer/SKILL.md)189- [model-comparator](../model-comparator/SKILL.md)