← Master Index
Vol. 13 Module 13.2 Lecture

Prompt Structure

Prompt Writing Craft

How This Lesson Fits the Module & Volume

Module 13.1 taught what prompting patterns exist—zero-shot, few-shot, system prompts, and evaluation. Module 13.2 teaches the craft of writing those prompts so teams can ship reliable behavior.

Prompt structure is the blueprint: role, task, context, constraints, and output contract arranged so a model (and a teammate) can parse intent in one pass. Every later lecture—clarity, ordering, templates, documentation—refines a piece of this skeleton.

Learning Objectives

By the end of this lesson, students should be able to:

  • Name the five production sections of a well-structured prompt.
  • Separate durable policy (system) from per-request work (user).
  • Rewrite a flat “wall of text” into labeled sections.
  • Choose headings, bullets, or XML/Markdown delimiters for scannability.
  • Explain why structure improves both model compliance and human review.
  • Link structure to later craft topics: ordering, templates, and docs.
Definition

Prompt structure is the deliberate layout of instructions, context, examples, and output rules into clear sections so the model can locate each requirement and so engineers can version, review, and reuse the prompt as a product artifact.

The Five-Section Skeleton

Production prompts rarely succeed as a single paragraph. Treat the prompt like an API contract with named fields:

1. Role / Policy

Who the assistant is and durable rules.

2. Task

The single job for this call.

3. Context

Facts, docs, or user data to use.

4. Constraints

Must / must-not, tone, safety.

5. Output

Format, schema, length, labels.

SectionLives best inChanges how often?
Role / policySystem promptRarely (product rules)
TaskUser message or template slotEvery request type
ContextUser message / RAG blockEvery request
ConstraintsSystem or shared templateOccasionally
Output contractTemplate + validation codePer feature

Before / After: Flat vs Structured

Before (weak): everything mashed together—hard for the model and for code review.

Write a helpful reply about the refund. Be nice. Use the policy if useful. Don't invent stuff. Keep it short maybe. Customer said: I want my money back for order 88421. Policy: refunds within 30 days if unused.

After (strong): labeled sections with one job each.

## Role You are a support agent for Acme Shop. Follow company policy only. ## Task Decide whether the customer qualifies for a refund and draft the reply. ## Context Customer message: "I want my money back for order 88421." Policy: Refunds within 30 days if the item is unused. ## Constraints - Do not invent order facts not provided. - If information is missing, ask one clarifying question. ## Output Return: 1) Decision: APPROVE | DENY | NEED_INFO 2) Customer-facing reply (max 80 words)

Structural Patterns Teams Use

Markdown headings

  • Fast for humans
  • Works in chat UIs
  • Easy to diff in git

XML tags

JSON contracts

Common Misconception

“Structure is just formatting—the model ignores headings.” Instruction-tuned models are trained on structured docs and chat. Clear section labels reduce ambiguity and make conflicting rules easier to spot in review. Structure is a reliability tool, not decoration.

Knowledge Check

  1. Short Answer: List the five sections of the production prompt skeleton. Answer: Role/policy, task, context, constraints, output.
  2. True/False: Durable product policy usually belongs in the system prompt. Answer: True.
  3. Multiple Choice: Per-request retrieved documents belong in: (a) role, (b) context, (c) output schema. Answer: (b).
  4. Short Answer: Why is a flat “wall of text” risky in production? Answer: Requirements blur together, so the model and reviewers miss constraints.
  5. True/False: Output format rules should be left implied. Answer: False—specify them explicitly.
  6. Multiple Choice: XML tags in prompts mainly help: (a) GPU kernels, (b) delimit sections/context, (c) replace tokenization. Answer: (b).
  7. Short Answer: Name one benefit of structured prompts for teams. Answer: Easier code review, versioning, or reuse via templates.
  8. Short Answer: Where should the single primary task statement live? Answer: In a dedicated Task section (often the user message).
  9. Multiple Choice: Module 13.2 focuses on: (a) training CNNs, (b) craft of writing production prompts, (c) SQL indexing. Answer: (b).
  10. True/False: Structure improves human review as well as model compliance. Answer: True.

Key Takeaways

  • Treat prompts as contracts: role, task, context, constraints, output.
  • Put durable policy in the system layer; put request-specific work in the user layer.
  • Labeled sections beat walls of text for models and teammates.
  • Pick Markdown, XML, or JSON delimiters to match your stack.
  • Next: Clarity & Specificity.
Trainer’s Guide

Hands-on idea: Give students a 120-word unstructured prompt and require a five-section rewrite without changing the intended task.

Discussion prompt: What belongs in system vs user when the same feature supports three product tiers?

Recap: Structure turns prompting from improvisation into an engineering artifact. Continue with Clarity & Specificity.