0% complete

Data, models, and prompt engineering · Lesson 2 of 3

Prompt structure and instruction design

Write prompts that clearly specify role, task, context, constraints, and response format.

Lesson

An effective prompt makes the task explicit. Separate system-level behavior from the user request, provide relevant context, define constraints, and show the expected output shape. Place untrusted input in a clearly delimited region and tell the model how to use it. Avoid contradictory instructions and unnecessary background that consumes context without improving the answer. Prompts are application artifacts: version them, review changes, and run the same evaluation set after editing. Examples can clarify a desired classification or style, but they also bias behavior, so include representative and edge cases. Do not treat a prompt as an authorization boundary or a substitute for validating model output. A prompt template should make the boundary between trusted instructions and untrusted content obvious. State the task, the permitted evidence, the desired response format, and an explicit fallback when evidence is insufficient. Keep reusable instructions separate from per-request data, and avoid placing secrets or unnecessary personal information in the prompt. When changing a template, compare the new version with a saved baseline on the same cases, including injection attempts and ambiguous requests. Prompts influence model behavior but do not enforce access control; validate outputs and authorize every consequential action in application code. Implementation drill: trace one representative request through the stages in the diagram. Write down what enters each stage, what output or evidence it produces, and which identity is allowed to perform it. Then test an empty input, an unauthorized request, a dependency timeout, and an unexpected result. For each case, state whether the application should retry, reject, abstain, or ask a person for help. Keep the observed failure as a regression example so changes to prompts, models, data, or code can be checked against the same behavior. Practice task: What should an application do with text retrieved from an external source?

Visual guide

Build a bounded prompt

  1. Step 01 Instruct

    State the task and response rules.

  2. Step 02 Context

    Add relevant, clearly delimited evidence.

  3. Step 03 Constrain

    Specify fallback and output format.

  4. Step 04 Evaluate

    Compare versions on test cases.

Code examples

A bounded prompt template
TEXT
Task: Answer the question using only the supplied excerpts.
If the excerpts do not support an answer, say that the information is unavailable.

Excerpts:
{{context}}

Question:
{{question}}

Return: answer, supporting excerpt IDs, and confidence notes.
Expected output
The template states the task, evidence boundary, fallback, and response contract.

Key points

  • State the task, evidence, constraints, and output format explicitly.
  • Version prompts and evaluate changes against the same examples.
  • Prompts do not enforce authorization or replace output validation.

Check your understanding

Practice

What should an application do with text retrieved from an external source?

Your learning progress

Finish this lesson