<aside> <img src="/icons/swap-horizontally_gray.svg" alt="/icons/swap-horizontally_gray.svg" width="40px" /> Navigate:


Next Page: Ch. 6: Introduction to Advanced Techniques in Prompt Design

Previous Page: Ch. 4: Refining Prompts for Better Outputs

Collection Home: Mastering GPT-4 Prompt Engineering


</aside>

<aside> <img src="/icons/reorder_gray.svg" alt="/icons/reorder_gray.svg" width="40px" /> Table of Contents

</aside>


【5.1.】Techniques to Control the Length and Format of GPT-4 Outputs

Controlling the length and format of GPT-4 outputs using prompt design is a crucial aspect of mastering prompt engineering. When using ChatGPT, you have the ability to guide the model's responses through the prompt itself, which gives you a certain level of control over the output's length and format. Here are several strategies you can use:

<aside> 🔹 1. Being Explicit in Your Prompts:


The simplest and most direct way to control the length of the output is to ask for it explicitly within the prompt. For instance, if you're seeking a brief summary, you could structure your prompt as such: "In two sentences, summarize the plot of the Harry Potter series." The model is trained to understand and respond to this type of instruction.

</aside>

<aside> 🔹 2. Using Prompts That Imply Length and Format:


Some prompts implicitly suggest a certain length or format. For example, if you ask ChatGPT to "draft a tweet about the importance of AI ethics," it knows to limit its response to the character limit of a typical tweet. Similarly, if you prompt it to write a haiku about spring, it should generate a three-line poem with a 5-7-5 syllable pattern.

</aside>

<aside> 🔹 3. Structuring Your Prompt with Lists:


Lists are another great way to control the format and potentially the length of a model's output. For instance, if you want three key points about a specific topic, you could ask: "List three reasons why climate change is a pressing issue." This makes it clear that you want a succinct output in a list format.

</aside>

<aside> 🔹 4. Utilizing Follow-up Questions to Control Response Length:


If the model produces an output that's longer or shorter than what you wanted, you can use a follow-up question or statement to request a different length. For example, if the model's response was too long, you might respond with "Can you condense that into a single sentence?"

</aside>

<aside> 🔹 5. Leveraging System-Level Prompts:


System prompts, or meta-prompts, allow you to instruct the model about the structure of its responses. For example, you could tell the model: "You are an assistant that always responds with concise, one-sentence answers." Although this approach is less certain due to the model's inherent variability, it can still guide the model towards generating shorter responses.

</aside>

Remember, controlling length and format is part art and part science. These techniques provide a starting point, but the best results often come from iterative experimentation and refinement.


【5.2.】Expert Level Prompts Demonstrating These Techniques

<aside> 🔹 Prompt 1: Being Explicit in Your Prompts


"Write a five-sentence description of the quantum computing concept."

</aside>

<aside> 🔹 Prompt 2: Using Prompts That Imply Length and Format


"Compose a LinkedIn post highlighting the role of machine learning in today's digital economy."

</aside>

<aside> 🔹 Prompt 3: Structuring Your Prompt with Lists


"Identify and elaborate on the top five ethical considerations AI developers should bear in mind when building AI models."

</aside>

<aside> 🔹 Prompt 4: Utilizing Follow-up Questions to Control Response Length


First Prompt:

"Describe the blockchain technology in detail."

Follow-up Prompt:

"Great explanation. Now, can you simplify this description to be understood by a 5th grader?"

</aside>

<aside> 🔹 Prompt 5: Leveraging System-Level Prompts


"You are an assistant that responds in the style of a concise and informative infographic description. Explain the process of photosynthesis."

</aside>

These expert prompts are intended to challenge your skills in controlling GPT-4's output length and format. Don't be discouraged if you don't achieve the desired result on the first attempt. Mastering these techniques involves practice, learning from any missteps, and refining your approach based on what you observe.