Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 3.2 — Writing Clear Instructions
LLM Engineering · Example 1 of 1

Building a prompt from five named parts

The fake model only reacts to the audience and the format lines. A real model uses all of them.

A clear instruction names the task, the context, the audience, the output format and the constraints. Say what to do first; add what to avoid only when needed. Build the prompt from named parts in code.

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 build_prompt(task, context, audience) that returns lines Task: ..., Context: ..., Audience: ... joined by newlines, skipping any part that is an empty string.

02

Write word_limit_ok(reply, limit) and use it to test the prompt "Reply in at most 5 words" against the replies "Late, refund wanted" and "The parcel is late and the customer wants a refund".

Explain it without notes

01

Name the five parts of a clear instruction and say what each one prevents.

02

Why is "use at most 25 words" a better instruction than "don't be wordy"?

03

Why build prompts with a function that takes named parts instead of pasting strings together?

Building a prompt from five named parts
Sign in to run this example in your browser.

Expected output

== task only (20 words in the reply)
  > Task: Explain the shipping status
Shipments move through a multi-stage logistics network, and arrival times depend on carrier capacity, customs, weather and many other factors.
== with context and audience (14 words in the reply)
  > Task: Explain the shipping status
  > Context: The parcel left the depot on Monday and is due in 3 days
  > Audience: a new customer
Your parcel left our depot on Monday and should reach you within 3 days.
== full (16 words in the reply)
  > Task: Explain the shipping status
  > Context: The parcel left the depot on Monday and is due in 3 days
  > Audience: a new customer
  > Format: two bullet points
  > Rule: Give no exact delivery date
  > Rule: Use at most 25 words
- Your parcel left our depot on Monday.
- It should reach you within 3 days.