chapter three

3 Prompt Design: Structural Elements

 

This chapter covers

  • The core structural elements of prompts, instructions, context, inputs, output formats, and delimiters.
  • Parameterizing prompts with input placeholders and dynamic variables to enable reuse.
  • Specifying output structure and applying constraints to guide model responses.
  • Using delimiters to organize complex prompts and insulate external context from instructions.
  • Combining these elements to build reliable, parseable prompts for specific tasks.

In the earlier chapters, we introduced the concept of Prompt Engineering and explored the technical aspects of transformers and Large Language Models (LLMs) from an AI engineer’s perspective. Now, it is time to introduce the fundamental building blocks of effective prompts: structural elements.

Structural elements are the building blocks of prompts. They increase the likelihood of continuations from training data that align with the specified task or format.

Overview of Structural Elements

Before diving into the details, let us first provide a high-level overview of the key structural elements we will cover in this chapter:

3.1 Instructions

3.1.1 Practical Example 1: Generating a Shakespearean Sonnet

3.1.2 Constraints

3.1.3 Practical Example 2: Creating a Recipe (with Constraints)

3.1.4 Hands-On Practice

3.2 Context

3.2.1 Practical Example 1: Generating a News Article

3.2.2 Practical Example 2: Generating Dialogue for a Science Fiction Novel

3.2.3 Hands-On Practice

3.3 Input Parameters

3.3.1 Practical Example 1: Sentiment Analysis

3.3.2 Practical Example 2: Personalized Product Recommendation

3.3.3 Hands-On Practice

3.4 Output Format

3.4.1 Output Indicator Pattern

3.4.2 Practical Example 1: Generating a Product Review

3.4.3 Template Pattern (Aka. Fill-in-the-Blanks Pattern)

3.4.4 Practical Example 2: Generating a Recipe

3.4.5 Hands-On Practice

3.5 Delimiters

3.5.1 The Delimiter Pattern

3.5.2 Practical Example 1: Generating Article Summaries

3.5.3 Practical Example 2: Answering Questions Based on a Document

3.5.4 Hands-On Practice

3.6 Combining Structural Elements

3.6.1 Practical Example 1: Generating Product Descriptions

3.6.2 Practical Example 2: Writing News Article Summaries

3.6.3 Hands-On Practice