prompt-few-shot
Use when the user asks about few-shot or one-shot prompts, writing few-shot examples for a classification prompt, in-context examples, dynamic example…
от j4flmao★ 47 звёзд на GitHub
Установить prompt-few-shot в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Few-Shot Prompting
Purpose
Demonstrations in the prompt show the model the task format, label space, and style without changing its weights (in-context learning). They are the fastest fix for format drift and ambiguous instructions, but they cost tokens on every call and introduce biases (ordering, majority label, copying surface features). Choose, order, and format them deliberately and verify with evals.
Agent Protocol
Trigger
"few-shot", "one-shot", "in-context learning", "examples in prompt", "demonstrations", "dynamic examples", "example selection", "output format keeps breaking".
Input Context
- Task, instructions, and current failure examples.
- Pool of labeled examples (and whether inputs vary widely).
- Token/latency budget; whether provider prompt caching is used.
Output Artifact
Prompt template with example block, selection strategy (static or retrieved), and an eval comparing 0/k-shot variants.
Response Format
Shots: {k} {static|retrieved by similarity} Format: {tagged blocks|chat turns}
Coverage: {labels/edge cases represented} Order: {randomized|similar-last}
Placement: {after instructions, before input} Cacheable prefix: {yes/no}
Eval: zero-shot vs {k}-shot on {n} items: {metric}
Completion Criteria
- Examples match the real input distribution and output format exactly.
- Label/edge-case coverage balanced; no accidental majority bias.
- Examples clearly delimited from the live input.
- Measured gain over zero-shot with clear instructions.
What the Research Says (and Doesn't)
- Few-shot ability emerges with scale (Brown et al., 2020, GPT-3).
- Format, input distribution, and label space in demonstrations matter a lot; exact label correctness mattered less than expected in some classification settings (Min et al., 2022). Do not rely on that: wrong labels still hurt on many tasks.
- Performance is sensitive to example order (Lu et al., 2022) and biased toward frequent and recent labels (Zhao et al., 2021).
- Selecting examples semantically similar to the input usually beats random examples (Liu et al., 2022).
- Explanations of in-context learning as implicit gradient descent are research hypotheses for simplified settings, not established behaviour of production models.
Design Rules
- Instructions first, examples second: examples illustrate; they do not replace a clear task statement.
- Exact format parity: examples use the same delimiters, field names, and output schema you parse.
- Diversity and coverage: include edge cases and every label; avoid near-duplicates.
- Balance: roughly equal labels unless you deliberately want a prior.
- Delimit: wrap in tags (
<example>,<input>,<output>) so the model never confuses examples with the real input. - Few, high quality: 2-8 examples typically; more only if evals show gains.
- Avoid leaking test items into the example pool.
Template
You classify support tickets into exactly one category:
billing, bug, feature_request, account_access.
Return JSON: {"category": "...", "confidence": "high|low"}.
<examples>
<example>
<input>I was charged twice for March.</input>
<output>{"category": "billing", "confidence": "high"}</output>
</example>
<example>
<input>The export button does nothing on Safari.</input>
<output>{"category": "bug", "confidence": "high"}</output>
</example>
<example>
<input>Can't log in and also want dark mode.</input>
<output>{"category": "account_access", "confidence": "low"}</output>
</example>
</examples>
<input>{{ticket_text}}</input>
Dynamic (Retrieved) Few-Shot
from __future__ import annotations
import random
import numpy as np
def select_examples(query_vec: np.ndarray, pool_vecs: np.ndarray, pool: list[dict],
k: int = 4, per_label_cap: int = 2, seed: int = 0) -> list[dict]:
"""Nearest examples by cosine similarity, capped per label to avoid majority bias."""
if len(pool) != len(pool_vecs):
raise ValueError("pool and pool_vecs length mismatch")
sims = pool_vecs @ query_vec / (np.linalg.norm(pool_vecs, axis=1) * np.linalg.norm(query_vec) + 1e-9)
chosen, per_label = [], {}
for idx in np.argsort(-sims):
ex = pool[int(idx)]
if per_label.get(ex["label"], 0) >= per_label_cap:
continue
chosen.append(ex)
per_label[ex["label"]] = per_label.get(ex["label"], 0) + 1
if len(chosen) == k:
break
random.Random(seed).shuffle(chosen) # reduce recency bias toward one label
return chosen
Trade-off: retrieved examples change per request, which breaks prompt-prefix caching. Keep a static, cacheable block (instructions + core examples) first and append a small dynamic block after it if both are needed.
Cost and Context
- Every example is re-sent on every call; long example blocks raise latency and cost and dilute attention on long inputs.
- Provider prompt caching and serving-engine p
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- references/context-window-management.md
- references/evaluation-and-testing-strategies.md
- references/hallucination-and-error-handling.md
- references/prompt-deployment-pipelines.md
- references/prompt-injection-prevention.md
- references/prompt-library-organization.md
- references/prompt-performance-optimization.md
FAQ
Что делает скилл prompt-few-shot?
Use when the user asks about few-shot or one-shot prompts, writing few-shot examples for a classification prompt, in-context examples, dynamic example selection or a model that ignores the output format. Produces a delimited example block, selection strategy and a zero-shot vs k-shot eval. Not for reasoning prompts (use prompt-chain-of-thought) or fine-tuning (use llm-finetuning).
Как установить скилл prompt-few-shot?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл prompt-few-shot запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
AnthropicGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
academy-guide
AnthropicStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
internal-comms
AnthropicA set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
skill-development
AnthropicThis skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…