$npx -y skills add ancoleman/ai-design-components --skill prompt-engineeringEngineer effective LLM prompts using zero-shot, few-shot, chain-of-thought, and structured output techniques. Use when building LLM applications requiring reliable outputs, implementing RAG systems, creating AI agents, or optimizing prompt quality and cost. Covers OpenAI, Anthrop
| 1 | # Prompt Engineering |
| 2 | |
| 3 | Design and optimize prompts for large language models (LLMs) to achieve reliable, high-quality outputs across diverse tasks. |
| 4 | |
| 5 | ## Purpose |
| 6 | |
| 7 | This skill provides systematic techniques for crafting prompts that consistently elicit desired behaviors from LLMs. Rather than trial-and-error prompt iteration, apply proven patterns (zero-shot, few-shot, chain-of-thought, structured outputs) to improve accuracy, reduce costs, and build production-ready LLM applications. Covers multi-model deployment (OpenAI GPT, Anthropic Claude, Google Gemini, open-source models) with Python and TypeScript examples. |
| 8 | |
| 9 | ## When to Use This Skill |
| 10 | |
| 11 | **Trigger this skill when:** |
| 12 | - Building LLM-powered applications requiring consistent outputs |
| 13 | - Model outputs are unreliable, inconsistent, or hallucinating |
| 14 | - Need structured data (JSON) from natural language inputs |
| 15 | - Implementing multi-step reasoning tasks (math, logic, analysis) |
| 16 | - Creating AI agents that use tools and external APIs |
| 17 | - Optimizing prompt costs or latency in production systems |
| 18 | - Migrating prompts across different model providers |
| 19 | - Establishing prompt versioning and testing workflows |
| 20 | |
| 21 | **Common requests:** |
| 22 | - "How do I make Claude/GPT follow instructions reliably?" |
| 23 | - "My JSON parsing keeps failing - how to get valid outputs?" |
| 24 | - "Need to build a RAG system for question-answering" |
| 25 | - "How to reduce hallucination in model responses?" |
| 26 | - "What's the best way to implement multi-step workflows?" |
| 27 | |
| 28 | ## Quick Start |
| 29 | |
| 30 | **Zero-Shot Prompt (Python + OpenAI):** |
| 31 | ```python |
| 32 | from openai import OpenAI |
| 33 | client = OpenAI() |
| 34 | |
| 35 | response = client.chat.completions.create( |
| 36 | model="gpt-4", |
| 37 | messages=[ |
| 38 | {"role": "system", "content": "You are a helpful assistant."}, |
| 39 | {"role": "user", "content": "Summarize this article in 3 sentences: [text]"} |
| 40 | ], |
| 41 | temperature=0 # Deterministic output |
| 42 | ) |
| 43 | print(response.choices[0].message.content) |
| 44 | ``` |
| 45 | |
| 46 | **Structured Output (TypeScript + Vercel AI SDK):** |
| 47 | ```typescript |
| 48 | import { generateObject } from 'ai'; |
| 49 | import { openai } from '@ai-sdk/openai'; |
| 50 | import { z } from 'zod'; |
| 51 | |
| 52 | const schema = z.object({ |
| 53 | name: z.string(), |
| 54 | sentiment: z.enum(['positive', 'negative', 'neutral']), |
| 55 | }); |
| 56 | |
| 57 | const { object } = await generateObject({ |
| 58 | model: openai('gpt-4'), |
| 59 | schema, |
| 60 | prompt: 'Extract sentiment from: "This product is amazing!"', |
| 61 | }); |
| 62 | ``` |
| 63 | |
| 64 | ## Prompting Technique Decision Framework |
| 65 | |
| 66 | **Choose the right technique based on task requirements:** |
| 67 | |
| 68 | | Goal | Technique | Token Cost | Reliability | Use Case | |
| 69 | |------|-----------|------------|-------------|----------| |
| 70 | | **Simple, well-defined task** | Zero-Shot | ⭐⭐⭐⭐⭐ Minimal | ⭐⭐⭐ Medium | Translation, simple summarization | |
| 71 | | **Specific format/style** | Few-Shot | ⭐⭐⭐ Medium | ⭐⭐⭐⭐ High | Classification, entity extraction | |
| 72 | | **Complex reasoning** | Chain-of-Thought | ⭐⭐ Higher | ⭐⭐⭐⭐⭐ Very High | Math, logic, multi-hop QA | |
| 73 | | **Structured data output** | JSON Mode / Tools | ⭐⭐⭐⭐ Low-Med | ⭐⭐⭐⭐⭐ Very High | API responses, data extraction | |
| 74 | | **Multi-step workflows** | Prompt Chaining | ⭐⭐⭐ Medium | ⭐⭐⭐⭐ High | Pipelines, complex tasks | |
| 75 | | **Knowledge retrieval** | RAG | ⭐⭐ Higher | ⭐⭐⭐⭐ High | QA over documents | |
| 76 | | **Agent behaviors** | ReAct (Tool Use) | ⭐ Highest | ⭐⭐⭐ Medium | Multi-tool, complex tasks | |
| 77 | |
| 78 | **Decision tree:** |
| 79 | ``` |
| 80 | START |
| 81 | ├─ Need structured JSON? → Use JSON Mode / Tool Calling (references/structured-outputs.md) |
| 82 | ├─ Complex reasoning required? → Use Chain-of-Thought (references/chain-of-thought.md) |
| 83 | ├─ Specific format/style needed? → Use Few-Shot Learning (references/few-shot-learning.md) |
| 84 | ├─ Knowledge from documents? → Use RAG (references/rag-patterns.md) |
| 85 | ├─ Multi-step workflow? → Use Prompt Chaining (references/prompt-chaining.md) |
| 86 | ├─ Agent with tools? → Use Tool Use / ReAct (references/tool-use-guide.md) |
| 87 | └─ Simple task → Use Zero-Shot (references/zero-shot-patterns.md) |
| 88 | ``` |
| 89 | |
| 90 | ## Core Prompting Patterns |
| 91 | |
| 92 | ### 1. Zero-Shot Prompting |
| 93 | |
| 94 | **Pattern:** Clear instruction + optional context + input + output format specification |
| 95 | |
| 96 | **When to use:** Simple, well-defined tasks with clear expected outputs (summarization, translation, basic classification). |
| 97 | |
| 98 | **Best practices:** |
| 99 | - Be specific about constraints and requirements |
| 100 | - Use imperative voice ("Summarize...", not "Can you summarize...") |
| 101 | - Specify output format upfront |
| 102 | - Set `temperature=0` for deterministic outputs |
| 103 | |
| 104 | **Example:** |
| 105 | ```python |
| 106 | prompt = """ |
| 107 | Summarize the following customer review in 2 sentences, focusing on key concerns: |
| 108 | |
| 109 | Review: [customer feedback text] |
| 110 | |
| 111 | Summary: |
| 112 | """ |
| 113 | ``` |
| 114 | |
| 115 | See `references/zero-shot-patterns.md` for comprehensive examples and anti-patterns. |
| 116 | |
| 117 | ## |