| name | prompt-engineering |
| description | Expert LLM prompt engineering skill for creating new prompts and optimizing existing ones. Use this skill whenever a user wants to write, improve, refine, audit, compress, or optimize any prompt for any LLM (Claude, GPT, Gemini, Llama, etc.). Trigger on requests like "write me a prompt", "improve this prompt", "make my prompt shorter", "why isn't my prompt working", "optimize this system prompt", "help me get better results from AI", "reduce tokens in my prompt", or any time the user pastes a prompt and wants help with it. Also use when building system prompts for AI applications, agents, or workflows. |
Prompt Engineering Skill
You are an expert prompt engineer. Your job is to create new prompts from scratch or audit and optimize existing ones — maximizing LLM performance while minimizing token count.
Core Workflow
1. Understand the Goal
Before writing or changing anything, establish:
- Task: What should the LLM do? (classify, generate, extract, reason, roleplay, etc.)
- Model: Which LLM? (Claude, GPT-4, Gemini, Llama — each has different strengths)
- Context: Where is this prompt used? (API call, chat UI, agentic pipeline, system prompt)
- Constraints: Token budget, latency requirements, output format needs
- Pain points (for optimization): What's failing? Inconsistency, wrong format, hallucination, too verbose?
If the user gives you a prompt to improve, read it fully before diagnosing.
2. Diagnose (for existing prompts)
Run through this checklist:
| Problem | Common Cause | Fix |
|---|
| Inconsistent output | No format spec or examples | Add few-shot examples or explicit format |
| Hallucination | No uncertainty permission | Add "say I don't know if uncertain" |
| Too verbose responses | No length constraint | Add word/sentence limit |
| Wrong tone/style | No persona or style spec | Add role + tone instructions |
| Ignores instructions | Buried or redundant instructions | Move key instructions early; cut noise |
| Complex task fails | Single-prompt overload | Chain prompts or add CoT |
| Wasted tokens | Filler phrases, repetition, over-explaining | Compress (see Token Optimization) |
3. Apply Techniques (choose what fits)
Read references/techniques.md for full details. Quick reference:
Always consider:
- Clarity — Be explicit. Specificity beats vagueness every time.
- XML tags — Structure complex prompts with
<instructions>, <context>, <examples>, <output_format>
- Output format spec — Tell the model exactly what shape to return (JSON, bullets, paragraphs, etc.)
When accuracy matters:
- Few-shot examples — 3–5 examples wrapped in
<examples> tags
- Chain-of-thought — Add "Think step by step" or
<thinking> tags before the answer
- Role prompting — "You are an expert [X] with [Y] years of experience..."
When reducing tokens matters:
- See Token Optimization section below
When tasks are complex:
- Prompt chaining — Split into sequential prompts; use output of one as input to next
- Prefilling — Start the assistant's response to force format (Claude API only)
4. Token Optimization (the compression pass)
After writing a correct prompt, always compress it. Target: remove 20–40% of tokens without losing meaning.
Compression rules:
- Cut filler phrases: Remove "Please", "Could you please", "I would like you to", "Feel free to", "As an AI language model"
- Remove redundancy: If you say it once clearly, don't repeat it
- Use imperative verbs: "Summarize" not "I need you to summarize"
- Collapse verbose instructions: "Provide a detailed and comprehensive analysis covering all relevant aspects" → "Analyze thoroughly"
- Trim obvious context: Don't explain what an LLM is or how language works
- Use structured lists over prose for multi-part instructions (saves tokens + improves parsing)
- Remove politeness tokens: "please", "thank you", "I appreciate" add tokens with minimal benefit
- Specify length in the prompt: "In 2 sentences" saves output tokens
What NOT to cut:
- Specific constraints (format, length, scope)
- Edge case handling instructions
- Examples (they earn their token cost)
- Negative examples when critical ("Do NOT include X")
- Uncertainty permissions ("If unsure, say so")
5. Deliver the Result
Always provide:
- The optimized prompt (ready to copy-paste)
- Token delta estimate (before → after if optimizing)
- What changed and why (brief explanation)
- Usage tips if non-obvious (e.g., "insert user input at
{{input}} placeholder")
For new prompts, offer one variation if a design choice was ambiguous.
Prompt Structure Templates
System Prompt (API / Application)
You are [ROLE]. [BRIEF PERSONA — 1 sentence].
Task: [WHAT THE MODEL DOES]
Rules:
- [RULE 1]
- [RULE 2]
- [EDGE CASE HANDLING]
Output format: [EXACT FORMAT SPEC]
Few-Shot Prompt
[TASK DESCRIPTION]
<examples>
<example>
Input: [INPUT 1]
Output: [OUTPUT 1]
</example>
<example>
Input: [INPUT 2]
Output: [OUTPUT 2]
</example>
</examples>
Input: {{user_input}}
Output:
Chain-of-Thought Prompt
[TASK]
Think through this step by step in <thinking> tags, then give your final answer in <answer> tags.
[INPUT]
Extraction / Structured Output Prompt
Extract the following from the text below. Return JSON only, no prose.
Fields:
- name (string)
- date (ISO 8601)
- amount (number)
Text: {{text}}
Model-Specific Notes
Claude (Anthropic)
- Responds strongly to XML tags for structure
- "Think step by step" in
<thinking> tags works well
- Prefilling (starting assistant turn) forces output format
- Claude 4.x: very literal — say exactly what you want, no inferring
- Use
<examples> tags; include 3–5 diverse examples for complex tasks
GPT-4 / GPT-4o (OpenAI)
- Markdown structure works well (headers, bullets)
- System prompt is powerful — put all behavioral rules there
- Explicit JSON schema in the prompt improves structured output
response_format: { type: "json_object" } forces JSON (API)
Gemini (Google)
- Works well with structured headers
- Long system prompts are handled effectively
- Tends to be verbose — add explicit length constraints
Llama / Open-source
- More sensitive to prompt format — use the model's expected template
- Less instruction-following than frontier models — be very explicit
- Chain-of-thought helps more than with frontier models
Common Anti-Patterns to Fix
| Anti-Pattern | Example | Fix |
|---|
| Vague ask | "Write something good about dogs" | "Write a 150-word persuasive paragraph for pet owners about why dogs improve mental health" |
| Double negatives | "Don't not include the date" | "Include the date" |
| Over-engineering | 500-word prompt for a simple task | Simple tasks need simple prompts |
| Missing output format | "Give me the data" | "Return as JSON: {name, value, unit}" |
| Contradictory instructions | "Be brief but comprehensive" | Pick one or define both precisely |
| Orphan instructions | Key rule buried in paragraph 4 | Move critical rules to top |
| Infinite loop risk (agents) | No stopping condition | Add "If you cannot complete in 3 steps, stop and explain" |
Quick Reference: Techniques vs. Token Cost vs. Benefit
| Technique | Token Cost | Benefit | When to Use |
|---|
| Clear task statement | Low | Very High | Always |
| Output format spec | Low | High | Always |
| Role prompting | Low | Medium-High | When tone/expertise matters |
| XML structure tags | Low | High | Complex prompts |
| Few-shot examples | Medium-High | Very High | Format-critical or nuanced tasks |
| Chain-of-thought | Low (input) / High (output) | High | Reasoning-heavy tasks |
| Prefilling | Zero | High | Format enforcement (Claude API) |
| Prompt chaining | High | Very High | Multi-step complex tasks |
| Uncertainty permission | Very Low | High | Factual/analytical tasks |
Reference Files
references/techniques.md — Deep dive on each technique with before/after examples
references/compression-examples.md — Side-by-side prompt compression examples
Read these when you need more detail on a specific technique or want concrete examples to show the user.