prompt-engineering
Engineer 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, Anthropic, and open-source models with multi-language examples (Python/TypeScript).
What this skill does
# Prompt Engineering
Design and optimize prompts for large language models (LLMs) to achieve reliable, high-quality outputs across diverse tasks.
## Purpose
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.
## When to Use This Skill
**Trigger this skill when:**
- Building LLM-powered applications requiring consistent outputs
- Model outputs are unreliable, inconsistent, or hallucinating
- Need structured data (JSON) from natural language inputs
- Implementing multi-step reasoning tasks (math, logic, analysis)
- Creating AI agents that use tools and external APIs
- Optimizing prompt costs or latency in production systems
- Migrating prompts across different model providers
- Establishing prompt versioning and testing workflows
**Common requests:**
- "How do I make Claude/GPT follow instructions reliably?"
- "My JSON parsing keeps failing - how to get valid outputs?"
- "Need to build a RAG system for question-answering"
- "How to reduce hallucination in model responses?"
- "What's the best way to implement multi-step workflows?"
## Quick Start
**Zero-Shot Prompt (Python + OpenAI):**
```python
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Summarize this article in 3 sentences: [text]"}
],
temperature=0 # Deterministic output
)
print(response.choices[0].message.content)
```
**Structured Output (TypeScript + Vercel AI SDK):**
```typescript
import { generateObject } from 'ai';
import { openai } from '@ai-sdk/openai';
import { z } from 'zod';
const schema = z.object({
name: z.string(),
sentiment: z.enum(['positive', 'negative', 'neutral']),
});
const { object } = await generateObject({
model: openai('gpt-4'),
schema,
prompt: 'Extract sentiment from: "This product is amazing!"',
});
```
## Prompting Technique Decision Framework
**Choose the right technique based on task requirements:**
| Goal | Technique | Token Cost | Reliability | Use Case |
|------|-----------|------------|-------------|----------|
| **Simple, well-defined task** | Zero-Shot | ⭐⭐⭐⭐⭐ Minimal | ⭐⭐⭐ Medium | Translation, simple summarization |
| **Specific format/style** | Few-Shot | ⭐⭐⭐ Medium | ⭐⭐⭐⭐ High | Classification, entity extraction |
| **Complex reasoning** | Chain-of-Thought | ⭐⭐ Higher | ⭐⭐⭐⭐⭐ Very High | Math, logic, multi-hop QA |
| **Structured data output** | JSON Mode / Tools | ⭐⭐⭐⭐ Low-Med | ⭐⭐⭐⭐⭐ Very High | API responses, data extraction |
| **Multi-step workflows** | Prompt Chaining | ⭐⭐⭐ Medium | ⭐⭐⭐⭐ High | Pipelines, complex tasks |
| **Knowledge retrieval** | RAG | ⭐⭐ Higher | ⭐⭐⭐⭐ High | QA over documents |
| **Agent behaviors** | ReAct (Tool Use) | ⭐ Highest | ⭐⭐⭐ Medium | Multi-tool, complex tasks |
**Decision tree:**
```
START
├─ Need structured JSON? → Use JSON Mode / Tool Calling (references/structured-outputs.md)
├─ Complex reasoning required? → Use Chain-of-Thought (references/chain-of-thought.md)
├─ Specific format/style needed? → Use Few-Shot Learning (references/few-shot-learning.md)
├─ Knowledge from documents? → Use RAG (references/rag-patterns.md)
├─ Multi-step workflow? → Use Prompt Chaining (references/prompt-chaining.md)
├─ Agent with tools? → Use Tool Use / ReAct (references/tool-use-guide.md)
└─ Simple task → Use Zero-Shot (references/zero-shot-patterns.md)
```
## Core Prompting Patterns
### 1. Zero-Shot Prompting
**Pattern:** Clear instruction + optional context + input + output format specification
**When to use:** Simple, well-defined tasks with clear expected outputs (summarization, translation, basic classification).
**Best practices:**
- Be specific about constraints and requirements
- Use imperative voice ("Summarize...", not "Can you summarize...")
- Specify output format upfront
- Set `temperature=0` for deterministic outputs
**Example:**
```python
prompt = """
Summarize the following customer review in 2 sentences, focusing on key concerns:
Review: [customer feedback text]
Summary:
"""
```
See `references/zero-shot-patterns.md` for comprehensive examples and anti-patterns.
### 2. Chain-of-Thought (CoT)
**Pattern:** Task + "Let's think step by step" + reasoning steps → answer
**When to use:** Complex reasoning tasks (math problems, multi-hop logic, analysis requiring intermediate steps).
**Research foundation:** Wei et al. (2022) demonstrated 20-50% accuracy improvements on reasoning benchmarks.
**Zero-shot CoT:**
```python
prompt = """
Solve this problem step by step:
A train leaves Station A at 2 PM going 60 mph.
Another leaves Station B at 3 PM going 80 mph.
Stations are 300 miles apart. When do they meet?
Let's think through this step by step:
"""
```
**Few-shot CoT:** Provide 2-3 examples showing reasoning steps before the actual task.
See `references/chain-of-thought.md` for advanced patterns (Tree-of-Thoughts, self-consistency).
### 3. Few-Shot Learning
**Pattern:** Task description + 2-5 examples (input → output) + actual task
**When to use:** Need specific formatting, style, or classification patterns not easily described.
**Sweet spot:** 2-5 examples (quality > quantity)
**Example structure:**
```python
prompt = """
Classify sentiment of movie reviews.
Examples:
Review: "Absolutely fantastic! Loved every minute."
Sentiment: positive
Review: "Waste of time. Terrible acting."
Sentiment: negative
Review: "It was okay, nothing special."
Sentiment: neutral
Review: "{new_review}"
Sentiment:
"""
```
**Best practices:**
- Use diverse, representative examples
- Maintain consistent formatting
- Randomize example order to avoid position bias
- Label edge cases explicitly
See `references/few-shot-learning.md` for selection strategies and common pitfalls.
### 4. Structured Output Generation
**Modern approach (2025):** Use native JSON modes and tool calling instead of text parsing.
**OpenAI JSON Mode:**
```python
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4",
messages=[
{"role": "system", "content": "Extract user data as JSON."},
{"role": "user", "content": "From bio: 'Sarah, 28, [email protected]'"}
],
response_format={"type": "json_object"}
)
```
**Anthropic Tool Use (for structured outputs):**
```python
import anthropic
client = anthropic.Anthropic()
tools = [{
"name": "record_data",
"description": "Record structured user information",
"input_schema": {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "integer"}
},
"required": ["name", "age"]
}
}]
message = client.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=1024,
tools=tools,
messages=[{"role": "user", "content": "Extract: 'Sarah, 28'"}]
)
```
**TypeScript with Zod validation:**
```typescript
import { generateObject } from 'ai';
import { z } from 'zod';
const schema = z.object({
name: z.string(),
age: z.number(),
});
const { object } = await generateObject({
model: openai('gpt-4'),
schema,
prompt: 'Extract: "Sarah, 28"',
});
```
See `references/structured-outputs.md` for validation patterns and error handling.
### 5. System Prompts and Personas
**Pattern:** Define consistent behavior, role, constraints, and output format.
**Structure:**
```
1. Role/Persona
2. Capabilities and knowledge domain
3. Behavior guidelines
4. Output format constraints
5. Safety/ethical boundaries
```
**Example:**
```python
syRelated in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.