← ClaudeAtlas

few-shot-exampleslisted

Best practices for designing few-shot (input→output) examples in prompts for AI and agentic applications. Use when writing or reviewing prompts that need consistent formatting, structured/JSON output, classification, extraction, edge-case handling, or hallucination reduction; or when the user mentions few-shot, multishot, in-context examples, or "show the model an example".
magnusrodseth/dotfiles · ★ 0 · AI & Automation · score 62
Install: claude install-skill magnusrodseth/dotfiles
# Few-Shot Examples Few-shot examples are concrete input→output pairs embedded in a prompt to guide the model by demonstration instead of description. They are the most reliable lever for output *format* and *edge-case behavior*, and the primary defense against hallucinated values. ## When to use them Reach for few-shot examples when the task needs any of: 1. **Consistent formatting** — lock output to one structure across every call. 2. **Ambiguous / edge-case handling** — show how to handle the cases prose underspecifies (nulls, empties, conflicting inputs). 3. **Generalization** — demonstrate the pattern so the model applies it to novel inputs. Prefer examples over longer prose instructions for these. Examples *show*; criteria *tell*. Use both together. ## Core rules - **Wrap each example in XML tags.** Use `<example>` with nested `<input>` / `<output>`. This makes boundaries unambiguous and matches Claude's prompt-structuring conventions. - **Vary the inputs, fix the output shape.** To teach normalization, map *different* input formats to the *same* canonical output (e.g. several date formats → one ISO-8601 string). - **Always include a missing-data example.** Demonstrate that `null`/empty in → `null`/`partial_record` out is *correct*. This removes the model's incentive to fabricate. (See [REFERENCE.md](REFERENCE.md) for the canonical null-handling example.) - **2–5 examples is usually enough.** Cover the common case plus the edge cases that matter; more examples co