prompt-engineering
БесплатноБез исполняемых скриптовНе проверенPrompt engineering techniques for LLMs — zero-shot, few-shot, chain-of-thought, ReAct, and structured prompting. Use when designing prompts for AI features…
от TerminalSkills★ 221 звезда на GitHubОб этом скилле
Prompt Engineering
Overview
Prompt engineering is the practice of crafting inputs to language models to reliably produce desired outputs. Good prompts reduce hallucinations, increase consistency, and unlock model capabilities. This skill covers the key techniques: zero-shot, few-shot, chain-of-thought (CoT), Tree-of-Thought (ToT), ReAct, self-consistency, and meta-prompting.
Instructions
Core Techniques
Zero-Shot Prompting
No examples — rely on the model's training. Works well for clear, simple tasks.
prompt = """Classify the sentiment of the following review as POSITIVE, NEGATIVE, or NEUTRAL.
Review: "The delivery was fast but the packaging was damaged."
Sentiment:"""
Few-Shot Prompting
Provide 2–5 examples to guide the model's output format and style.
prompt = """Classify sentiment. Examples:
Review: "Amazing product, works perfectly!" → POSITIVE
Review: "Arrived broken, waste of money." → NEGATIVE
Review: "It's okay, nothing special." → NEUTRAL
Review: "The battery life is shorter than advertised."
Sentiment:"""
Tips:
- Use diverse, representative examples
- Keep examples consistent in format
- Anthropic's guide suggests 3–5 examples as a starting point; test whether more help or hurt on your own cases
- Put examples before the actual input
Chain-of-Thought (CoT)
Ask the model to reason step-by-step before answering. Often helps on math, logic and multi-step tasks; measure it on your own cases, because it costs more output tokens.
# Zero-shot CoT — just add "Let's think step by step"
prompt = """A store sells apples for $0.50 each and oranges for $0.75 each.
Alice buys 4 apples and 3 oranges. How much does she spend?
Let's think step by step."""
# Few-shot CoT — include reasoning in examples
prompt = """Q: Roger has 5 tennis balls. He buys 2 more cans of tennis balls.
Each can has 3 balls. How many tennis balls does he have now?
A: Roger starts with 5 balls. 2 cans × 3 balls = 6 balls. 5 + 6 = 11. The answer is 11.
Q: Alice has 10 apples. She gives 3 to Bob and 2 to Charlie. How many does she have?
A:"""
Tree-of-Thought (ToT)
Generate multiple reasoning paths, evaluate them, and pick the best. Useful for creative or open-ended problems.
prompt = """Think of 3 different approaches to solve this problem, evaluate each briefly,
then pick the best one and execute it.
Problem: Design a caching strategy for an API that has both frequently-accessed
stable data and rapidly-changing user-specific data.
Approach 1:
Approach 2:
Approach 3:
Best approach and implementation:"""
ReAct (Reason + Act)
Interleave reasoning (Thought) with actions (Action/Observation) in a loop. Foundation of tool-using agents.
system = """You solve tasks by alternating between Thought, Action, and Observation.
Available actions: search(query), calculate(expression), done(answer)
Format:
Thought: [your reasoning]
Action: [action to take]
Observation: [result of action]
... (repeat as needed)
Thought: I now have the answer.
Action: done([final answer])"""
user = "What is the square root of the population of Tokyo?"
Self-Consistency
Generate multiple independent answers, then pick the most common one. Improves reliability on reasoning tasks.
import asyncio
async def self_consistent_answer(question, n=5):
"""Generate N answers and pick by majority vote."""
prompts = [f"{question}\n\nThink step by step and give your final answer." for _ in range(n)]
answers = await asyncio.gather(*[call_llm(p) for p in prompts])
# Extract final answers and find most common
final_answers = [extract_answer(a) for a in answers]
return max(set(final_answers), key=final_answers.count)
Structured Prompting
XML Tags (Claude-Optimized)
Anthropic's prompting guide recommends wrapping each type of content (for example <instructions>, <context>, <input>) in its own tag so Claude does not misread a prompt that mixes instructions, context, examples and inputs. There are no required tag names.
prompt = """<task>
Extract all product names and prices from the following receipt text.
</task>
<format>
Return a JSON array: [{"name": "...", "price": 0.00}]
</format>
<receipt>
{receipt_text}
</receipt>
JSON output:"""
Role Assignment
system = """You are a senior Python engineer specializing in performance optimization.
You write clean, well-documented code with O(n) complexity analysis.
When reviewing code, always:
1. Identify bottlenecks
2. Suggest specific optimizations
3. Provide rewritten examples"""
Prompt Templates
Reusable Template Class
class PromptTemplate:
def __init__(self, template: str, required_vars: list[str]):
self.template = template
self.required_vars = required_vars
def format(self, **kwargs) -> str:
missing = [v for v in self.required_vars if v not in kwargs]
if mis
Установить prompt-engineering в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл prompt-engineering?
Prompt engineering techniques for LLMs — zero-shot, few-shot, chain-of-thought, ReAct, and structured prompting. Use when designing prompts for AI features, improving LLM output quality, building reliable AI pipelines, or getting consistent structured responses from language models.
Как установить скилл prompt-engineering?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл prompt-engineering запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic