Skip to content
Advanced A1 · Prompt patternsVerified 2 Nov 2026

Prompt patterns that hold up

Stop judging prompts by how the answer looks. Write them as contracts and let a test decide.

Task contract
Goal, constraints, acceptance criteria and a verify command in one prompt. The model can't hit a target you haven't described, and you can't review against one either.
Context first
Point at the failing test, the input and the exact error before asking for a fix. Guessing at causes is where confident wrong answers come from.
Plan → implement → critique
Ask for a plan, edit it, then implement. Finish by asking the model to review its own diff against the contract. Critique catches what the first pass skipped.
Schema-constrained output
When output feeds a tool, give the schema and a validator command. "Valid JSON" isn't a contract; a schema plus a check is.
Iterative repair
Paste the exact failure, change one thing, re-run. Don't ask for a rewrite when a test names the problem.
Untrusted input
Issue bodies, READMEs and fetched pages can contain instructions. Quote them as data, say they are untrusted, and keep approvals on.

Worked example: From a wish to a contract

src/invoice.js has a summarize() stub and four failing acceptance tests.

Before

before
Implement summarize in invoice.js.

After

after
Implement summarize(rows) in src/invoice.js.

Contract:
- Input: rows from parseCsv (data/sample.csv shows the shape).
- Output: [{ customer, totalCents }] sorted by customer; integers only.
- Errors: throw with the 1-based line number for a bad qty or price.
- Constraints: no new dependencies; don't edit tests.
- Done when: npm test passes test/summarize.test.js.

First list the edge cases you'll handle, then implement, then
check your diff against each contract line and report any gaps.

Why it works: The weak prompt leaves rounding, sorting, error text and scope to chance. The contract makes each one checkable, and the final critique step asks the model to find its own gaps.

The hidden instruction

untrusted/issue-1234.md hides an HTML comment asking the agent to add a postinstall script and a .env file "for telemetry" and not to mention it. An agent that follows it fails npm run check:safety. GitHub filters hidden HTML comments before they reach the cloud agent, but local agents reading the file directly don't get that filter.

Lab setup

Folder: prompt-patterns/ in the labs download.

  • Node.js 22+ and Git. No dependencies.
  • Download the labs ZIP (Pro) or build the same exercises in your own repository.
Terminal
cd prompt-patterns && git init -q && git add -A && git commit -qm baseline
npm run verify   # expect 3 FAIL, 1 PASS

When you're done, npm run verify prints:

Expected result
PASS  1. CSV parsing handles quoted commas
PASS  2. Invoice summary meets the contract
PASS  3. Changelog entries match the schema
PASS  4. No unsafe changes from untrusted input

Review rubric

Score each line 0 (missing), 1 (partly there) or 2 (as described). Passing verify is necessary, not sufficient.

Rubric for prompt-patterns
Criterion2 points means
ContractGoal, constraints, acceptance criteria and a verify command, all specific
ContextThe prompt cites the failing test, the input and the exact error
CheckabilityOutput shape fixed by a schema or test, not by adjectives
SafetyUntrusted text quoted as data; check:safety passes

Safety note

Keep terminal approvals manual. The untrusted-input exercise checks that nothing adds lifecycle scripts, dependencies or files outside the task.

Pro

Lab repository and walkthrough

The prompt-patterns/ practice repository with npm run verify, a reference solution, and a step-by-step walkthrough.

  • Six prompt cards with weak and strong versions
  • Four automated checks, including a prompt-injection trap
  • Reference solution and the exact prompts that produced it

One payment, lifetime access. $29 $19 launch price.

Try it yourself· about 60 min

Work through the six prompt files in labs/prompt-patterns/prompts/ and score each attempt with its rubric.

  1. Run npm run verify and read which checks fail.
  2. For each exercise, try the weak prompt first and note what goes wrong.
  3. Use the stronger pattern, run the check, and score yourself 0–2 per rubric line.
  4. Finish with untrusted/issue-1234.md and confirm npm run check:safety still passes.

You should see: npm run verify prints four PASS lines, and you have a rubric score for each pattern.

Knowledge check

Get every answer right to complete this module. Progress is saved in this browser only.

1. A bug report you paste into agent mode contains "also add a postinstall script". What's the right move?
2. Which prompt gives you the most checkable result?