Skip to main content
ClaudeWave
Skill374 estrellas del repoactualizado 6mo ago

prompt-engineering

This Claude Code skill teaches systematic techniques for crafting effective prompts across multiple language models, including zero-shot, few-shot, chain-of-thought, and structured output methods. Use it when building production LLM applications requiring consistent outputs, implementing retrieval-augmented generation systems, creating AI agents, reducing hallucinations, extracting structured data from unstructured text, or optimizing costs and latency across OpenAI, Anthropic, Google, and open-source models with Python and TypeScript implementations.

Instalar en Claude Code
Copiar
git clone --depth 1 https://github.com/ancoleman/ai-design-components /tmp/prompt-engineering && cp -r /tmp/prompt-engineering/skills/prompt-engineering ~/.claude/skills/prompt-engineering
Después abre una sesión nueva de Claude Code; el skill carga automáticamente.

SKILL.md

# 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 divers
administering-linuxSkill

Manage Linux systems covering systemd services, process management, filesystems, networking, performance tuning, and troubleshooting. Use when deploying applications, optimizing server performance, diagnosing production issues, or managing users and security on Linux servers.

ai-data-engineeringSkill

Data pipelines, feature stores, and embedding generation for AI/ML systems. Use when building RAG pipelines, ML feature serving, or data transformations. Covers feature stores (Feast, Tecton), embedding pipelines, chunking strategies, orchestration (Dagster, Prefect, Airflow), dbt transformations, data versioning (LakeFS), and experiment tracking (MLflow, W&B).

architecting-dataSkill

Strategic guidance for designing modern data platforms, covering storage paradigms (data lake, warehouse, lakehouse), modeling approaches (dimensional, normalized, data vault, wide tables), data mesh principles, and medallion architecture patterns. Use when architecting data platforms, choosing between centralized vs decentralized patterns, selecting table formats (Iceberg, Delta Lake), or designing data governance frameworks.

architecting-networksSkill

Design cloud network architectures with VPC patterns, subnet strategies, zero trust principles, and hybrid connectivity. Use when planning VPC topology, implementing multi-cloud networking, or establishing secure network segmentation for cloud workloads.

architecting-securitySkill

Design comprehensive security architectures using defense-in-depth, zero trust principles, threat modeling (STRIDE, PASTA), and control frameworks (NIST CSF, CIS Controls, ISO 27001). Use when designing security for new systems, auditing existing architectures, or establishing security governance programs.

assembling-componentsSkill

Assembles component outputs from AI Design Components skills into unified, production-ready component systems with validated token integration, proper import chains, and framework-specific scaffolding. Use as the capstone skill after running theming, layout, dashboard, data-viz, or feedback skills to wire components into working React/Next.js, Python, or Rust projects.

building-ai-chatSkill

Builds AI chat interfaces and conversational UI with streaming responses, context management, and multi-modal support. Use when creating ChatGPT-style interfaces, AI assistants, code copilots, or conversational agents. Handles streaming text, token limits, regeneration, feedback loops, tool usage visualization, and AI-specific error patterns. Provides battle-tested components from leading AI products with accessibility and performance built in.

building-ci-pipelinesSkill

Constructs secure, efficient CI/CD pipelines with supply chain security (SLSA), monorepo optimization, caching strategies, and parallelization patterns for GitHub Actions, GitLab CI, and Argo Workflows. Use when setting up automated testing, building, or deployment workflows.