Prompt Engineering Expert
Examples beat adjectives; structure beats length. Tell the model who it is, what success looks like, and the exact output shape — then iterate against fixed test cases, changing one thing at a time.
When to Use
- Writing or improving a system/user prompt.
- Inconsistent, off-format, verbose, or low-quality model output.
- Needing structured output (JSON/schema), extraction, classification, or agents.
- Reducing hallucination or steering tone/length/reasoning.
When NOT to Use
- Retrieval/context assembly →
rag-expert.
- Quantitative eval/regression harness →
llm-testing-expert.
- Model training/fine-tuning →
deep-learning-expert.
- Anthropic SDK wiring + caching →
claude-api (built-in).
Core Principles
1. Structure the prompt
- State role, task, and success criteria explicitly. Durable rules → system prompt; the variable task/data → user turn.
- Separate sections with clear delimiters (markdown headings or XML-like tags
<context>…</context>) so instructions, data, and examples don't blur.
- Be specific about constraints: length, tone, audience, and what to do on ambiguity or missing info. Prefer positive instructions ("respond in valid JSON") over a pile of "don't".
2. Steer with examples & reasoning
- Few-shot: 2–5 representative, diverse examples that demonstrate the exact format and tricky edge cases. Examples teach format faster than descriptions.
- For reasoning-heavy tasks, let the model think before answering (chain-of-thought / a scratchpad), but keep the final output concise — or separate reasoning from the user-visible answer.
- Put the most important instruction near the start or end; long middles get "lost".
3. Reliable structured output
- For machine consumption, define a strict schema and use the provider's structured-output/JSON mode or tool-calling. Show one example of the exact shape.
- Provide a fallback so the model doesn't invent values: "if a field is unknown, use null; do not guess."
4. Iterate like an engineer
- Build a small fixed test set including hard/adversarial cases. Change one variable at a time, compare outputs, and version prompts. Don't trust a single lucky run.
- Watch for prompt injection when user content is included; keep instructions and untrusted data clearly separated and don't let data override rules.
Common Mistakes
- Vague asks ("make it good") → specify criteria, format, length.
- Conflicting/buried instructions → consolidate; structure with delimiters.
- No examples for format-sensitive tasks → add few-shot.
- Forcing CoT into the user-facing answer → separate or hide reasoning.
- Over-stuffing the prompt → signal drops; trim to what changes behavior.
- Free-text parsing of "JSON-ish" output → use real structured-output mode + a schema.
- Tuning on one example → use a test set; one input overfits.
Examples
Structured extraction with schema + fallback
System: You extract structured data. Output ONLY valid JSON matching the schema.
Schema: { "name": string, "amount": number, "currency": string|null }
Rules: If a field is absent in the text, use null. Do not guess or add fields.
User:
<text>
Invoice from Acme Corp for $1,250.00, net 30.
</text>
Expected: { "name": "Acme Corp", "amount": 1250.0, "currency": "USD" }
Few-shot classifier (format by example)
Classify sentiment as positive | neutral | negative.
"Loved it" -> positive
"It arrived" -> neutral
"Broke in a day" -> negative
"Does the job, nothing special" ->
See Also
rag-expert — grounding prompts with retrieved, cited context.
llm-testing-expert — evaluating prompt changes objectively.
claude-api (built-in) — Anthropic SDK, tool use, and prompt caching.
1---2name: prompt-engineering-expert3description: "Expert prompt engineering: prompt structure, few-shot, chain-of-thought, structured output, and iteration. Trigger keywords: prompt, prompt engineering, system prompt, few-shot, chain-of-thought, output format, JSON schema, structured output, instructions, role, examples, eval. Use for writing, debugging, or optimizing prompts for LLMs."4metadata:5 source: https://skillmd.com/skills/miaoge-ge/prompt-engineering-expert6---78# Prompt Engineering Expert910> Examples beat adjectives; structure beats length. Tell the model who it is, what success looks like, and the exact output shape — then iterate against fixed test cases, changing one thing at a time.1112## When to Use13- Writing or improving a system/user prompt.14- Inconsistent, off-format, verbose, or low-quality model output.15- Needing structured output (JSON/schema), extraction, classification, or agents.16- Reducing hallucination or steering tone/length/reasoning.1718## When NOT to Use19- Retrieval/context assembly → `rag-expert`.20- Quantitative eval/regression harness → `llm-testing-expert`.21- Model training/fine-tuning → `deep-learning-expert`.22- Anthropic SDK wiring + caching → `claude-api` (built-in).2324## Core Principles2526### 1. Structure the prompt27- State **role, task, and success criteria** explicitly. Durable rules → system prompt; the variable task/data → user turn.28- Separate sections with clear delimiters (markdown headings or XML-like tags `<context>…</context>`) so instructions, data, and examples don't blur.29- Be specific about constraints: length, tone, audience, and what to do on ambiguity or missing info. Prefer positive instructions ("respond in valid JSON") over a pile of "don't".3031### 2. Steer with examples & reasoning32- **Few-shot**: 2–5 representative, diverse examples that demonstrate the exact format and tricky edge cases. Examples teach format faster than descriptions.33- For reasoning-heavy tasks, let the model think before answering (chain-of-thought / a scratchpad), but keep the **final** output concise — or separate reasoning from the user-visible answer.34- Put the most important instruction near the start or end; long middles get "lost".3536### 3. Reliable structured output37- For machine consumption, define a strict schema and use the provider's structured-output/JSON mode or tool-calling. Show **one** example of the exact shape.38- Provide a fallback so the model doesn't invent values: "if a field is unknown, use null; do not guess."3940### 4. Iterate like an engineer41- Build a small fixed test set including hard/adversarial cases. Change **one variable at a time**, compare outputs, and **version** prompts. Don't trust a single lucky run.42- Watch for prompt injection when user content is included; keep instructions and untrusted data clearly separated and don't let data override rules.4344## Common Mistakes45- **Vague asks** ("make it good") → specify criteria, format, length.46- **Conflicting/buried instructions** → consolidate; structure with delimiters.47- **No examples for format-sensitive tasks** → add few-shot.48- **Forcing CoT into the user-facing answer** → separate or hide reasoning.49- **Over-stuffing** the prompt → signal drops; trim to what changes behavior.50- **Free-text parsing** of "JSON-ish" output → use real structured-output mode + a schema.51- **Tuning on one example** → use a test set; one input overfits.5253## Examples5455**Structured extraction with schema + fallback**56```text57System: You extract structured data. Output ONLY valid JSON matching the schema.58Schema: { "name": string, "amount": number, "currency": string|null }59Rules: If a field is absent in the text, use null. Do not guess or add fields.6061User:62<text>63Invoice from Acme Corp for $1,250.00, net 30.64</text>65```66Expected: `{ "name": "Acme Corp", "amount": 1250.0, "currency": "USD" }`6768**Few-shot classifier (format by example)**69```text70Classify sentiment as positive | neutral | negative.71"Loved it" -> positive72"It arrived" -> neutral73"Broke in a day" -> negative74"Does the job, nothing special" ->75```7677## See Also78- `rag-expert` — grounding prompts with retrieved, cited context.79- `llm-testing-expert` — evaluating prompt changes objectively.80- `claude-api` (built-in) — Anthropic SDK, tool use, and prompt caching.