← All skills
AI https://ai-skills-vault.pages.dev/skills/prompt-engineering-lab.md

Prompt Engineering Lab

Treat prompts like code: spec, schema, evals, versioning.

Download .md All skills
Install URLhttps://ai-skills-vault.pages.dev/skills/prompt-engineering-lab.md
Install prompt tap to copy
Read the skill at https://ai-skills-vault.pages.dev/skills/prompt-engineering-lab.md and install it as a skill in your agent. Follow it exactly, including its checklists. Then ask me the questions it requires and do the work.

A prompt is code. It needs a spec, tests, versioning and a rollback. Vibes-based prompting is why AI features fail in production.

When to use this skill

Stage 1 - Write the spec, not the prompt

Before prose, define:

  1. Task - one sentence, one verb. "Extract line items from an invoice." If it needs two verbs, it is two prompts.
  2. Input shape - exact fields, ranges, and what a malformed input looks like.
  3. Output shape - a JSON schema, not a description.
  4. Success criteria - what makes an output correct, and what makes it unacceptable.
  5. Failure mode - what the model should do when it cannot comply (refuse, ask, return null).
  6. Constraints - length, tone, forbidden content, required fields.

A prompt without a schema is a wish.

Stage 2 - Structure that reliably works

Order matters more than wording. Use this skeleton:

ROLE: one line, specific ("a senior accountant reviewing invoices").
TASK: one sentence, imperative.
INPUT: <data>{{...}}</data>   ← always delimited
RULES: 3-7 numbered constraints, most important first.
OUTPUT: exact JSON schema, with types and allowed values.
EXAMPLES: 1-3 input/output pairs, only if the format is subtle.
EDGE CASES: what to do when fields are missing, ambiguous or contradictory.

Rules of thumb:

Stage 3 - Output schemas

{"type":"object","required":["vendor","total","currency","line_items"],
 "properties":{"vendor":{"type":"string"},"total":{"type":"number"},
  "currency":{"type":"string","enum":["INR","USD","EUR"]},
  "line_items":{"type":"array","items":{"type":"object",
    "required":["description","amount"],
    "properties":{"description":{"type":"string"},"amount":{"type":"number"}}}}},
 "additionalProperties":false}

Use native structured output where the provider offers it. Always validate on receipt, and on failure retry once with the validator's error message appended - that single retry fixes most malformed outputs.

Stage 4 - Few-shot selection

Stage 5 - The eval set

  1. 30-100 cases minimum, drawn from real inputs where possible.
  2. Include: typical (60%), edge (25%), adversarial (15%).
  3. Each case has an expected output or an assertion function.
  4. Metrics per case: exact match, schema-valid, field-level accuracy, and a human-checked sample of 20.
  5. Freeze the set. Add new failures to it; never remove a case because the prompt now fails it.

Run the set on every prompt change and on every model upgrade. Print a diff table: case, old, new, verdict. Ship only if nothing regressed.

Stage 6 - Model and parameter choices

NeedChoice
Classification, extractionSmall fast model, temperature 0
Drafting, brainstormingMid model, temperature 0.7-1.0
Complex reasoningLarge model, low temperature, allow more tokens
High volume, low stakesSmall model + strict schema + human spot-check

Set max_tokens deliberately - it is your cost ceiling per call. Measure tokens per request and cost per 1,000 runs before launch, not after.

Stage 7 - Reliability hardening

Stage 8 - Versioning

Quality checklist

Copy-ready agent prompt

Read the skill at the URL above. I will describe an AI task. Write the Stage 1 spec first and get my sign-off. Then produce the structured prompt (role, task, delimited input, numbered rules, JSON schema, edge cases), a 30-case eval set with assertions, and a small script that runs the eval and prints a pass/fail table with per-case diffs. Include the injection-resistance lines in the system prompt.
Copied