Prompt engineering patterns

From event4u-app/agent-config · View interactive version

Prompt engineering patterns is an AI agent skill from the GitHub repository event4u-app/agent-config. Use when designing production-LLM prompts — few-shot, chain-of-thought, system prompts, templates, self-verification — distinct from prompt-optimizer and refine-prompt.

How to use this skill

Skill file

prompt-engineering-patterns

Production patterns for LLM prompts: few-shot, chain-of-thought, system-prompt design, templating, self-verification. Distinct surface from sibling skills:

When to use

Do NOT use when:

Decision framework

Step 1 — Pick the prompt level (progressive disclosure)

Start at Level 1; only escalate when measurement says you must.

Level 1  Direct instruction                    "Summarize this article."
Level 2  + constraints (length, format, focus) "...in 3 bullets, key findings only."
Level 3  + reasoning scaffold                  "Read first, identify findings, then summarize."
Level 4  + few-shot examples                   "Like these examples: ..."
Level 5  + self-verification step              "...then check answer against criteria; revise if fails."

Escalating without evidence is over-engineering. Each level adds tokens, latency, and a maintenance surface.

Step 2 — Structure the prompt

Fixed instruction hierarchy — every production prompt fills these slots in order:

[System context]   role, expertise, constraints, safety
[Task instruction] what to do, in one sentence
[Examples]         few-shot demonstrations (optional)
[Input data]       the user-supplied content
[Output format]    schema, length, citation rules

Stable slots (system, task, format) belong in cached prompt prefixes; volatile slots (examples, input) belong in the per-call portion.

Step 3 — Pick the few-shot strategy

Examples are uniform and small (< 20)         → embed all of them; deterministic.
Examples are large or diverse                 → semantic-similarity retrieval per call.
Edge cases dominate                           → diversity-sampled examples (cluster + pick one per cluster).
Token budget tight                            → fewer, higher-quality examples beats many mediocre.
Examples drift with the data                  → regenerate from a labeled corpus on a schedule, not hand-edited.

Bad examples are worse than no examples — the model imitates structure.

Step 4 — Add chain-of-thought ONLY when measured

CoT improves accuracy on multi-step reasoning, hurts on classification and lookup. Decision rule:

Task is multi-step / arithmetic / multi-hop   → add CoT (zero-shot "let's think step by step", or few-shot CoT).
Task is single-step extraction / classify     → CoT adds tokens without lift; skip.
You haven't measured                          → measure first, decide second.
Self-consistency needed (high-stakes answers) → sample N reasoning paths, majority vote.

Step 5 — Build error recovery into the prompt

Production prompts handle their own failure cases:

Step 6 — Treat prompts as code

Procedure: Apply to a new LLM feature

  1. Inspect the existing prompt (if any) and the eval set; verify a success metric exists (accuracy / consistency / latency / token cost) — refuse to design without it.
  2. Draft Level-1 prompt (Step 1) and measure on the eval set.
  3. Escalate one level at a time (Step 1) until metric is met or budget runs out.
  4. Lock the structure (Step 2), choose few-shot strategy (Step 3), decide CoT (Step 4).
  5. Add error-recovery clauses (Step 5).
  6. Commit prompt + eval results + chosen version (Step 6); cite this skill.

Output format

  1. Prompt-spec table: slot · content · stable-vs-volatile · cached-vs-per-call.
  2. Eval results table: prompt-version · metric · delta-vs-previous.
  3. Failure-mode list: trigger · prompt clause that handles it.

Gotcha

Do NOT

Auto-trigger keywords

Provenance

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.