Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 3.9 — Playbook: Prompt Patterns Library
LLM Engineering · Example 1 of 1

Five patterns, each with its check

The fake model returns fixed replies per task. The builders and checks are the production-shaped part.

Five prompt patterns you will use in almost every project, each built by a small function and each checked by code: classify, extract, summarise, rewrite and answer from context.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 6 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write classify_check(reply, labels) that returns True if the reply, ignoring spaces and capital letters, is one of the labels.

02

Write summary_check(reply, max_words) that returns True if the reply has at most max_words words and does not end with a question mark.

Explain it without notes

01

For each of the five patterns, name the failure it guards against and the check that catches it.

02

How do you make a model say "I don't know" reliably in an answer-from-context prompt?

03

Why keep prompt builders and checks as small separate functions?

Five patterns, each with its check
Sign in to run this example in your browser.

Expected output

classify: pass
extract: pass
summarise: pass
rewrite: pass
answer, in context: pass
answer, not in context: pass
6 of 6 recipes pass