Prompt Engineering via Prompt Patterns — The Template Pattern
The article is part of series: Prompt Engineering via Prompt Patterns
You can switch to video version of this article
Summary
The article discusses the Template Pattern in Prompt Engineering, a method to control the format of ChatGPT's output by providing a structured template with placeholders for content.
Abstract
The "Prompt Engineering via Prompt Patterns — The Template Pattern" article delves into a technique that allows users to dictate the structure of ChatGPT's responses. It emphasizes the importance of the Template Pattern for users who require specific formatting in the AI's output, which may not align with the AI's default response style. The pattern involves providing ChatGPT with a template that includes placeholders for the desired content, instructing the AI to adhere to this structure. This approach is particularly useful when the user wants to organize information in a non-standard format or when control over the presentation of content is crucial. The article also touches on the potential limitations of using templates, such as restricting the AI's ability to provide additional context or information beyond the placeholders. Examples are given to illustrate how to effectively use the Template Pattern for structured outputs, such as lists of passenger aircraft or summaries of TV show episodes.
Opinions
The article is part of series: Prompt Engineering via Prompt Patterns
You can switch to video version of this article
In conversation with ChatGPT you might have noticed that by default, ChatGPT chooses to provide you information in paragraphs, tables or lists or some other format of its choosing. While this works most of the time, sometime you want more control of how you want the output to look like, or how information in output text is organized, or some key information should be generated near the end and not at the top or middle of content. Clearly not a format that LLM would use as a default option. So it needs to be instructed to do so. This is something the template pattern can help with.
Template pattern instructs LLM to produce its output in a format it would not ordinarily use for the specified type of content being generated. This is usually done by providing LLM a glimpse, sample or template of how the final output should look like. The key contextual statements that make the magic happen are of the form
· I am going to provide a template for your output
· X is my placeholder for content
· Try to fit the output into one or more of the placeholders that I list
· Please preserve the formatting and overall template that I provide
· This is the template: PATTERN and PLACEHOLDERS
The first statement is instructing LLM to follow your provided template to format its output, and make it consistent with user’s need. Note that this template is used when LLM is not aware of the intended format. If it is a well known format, you can simply instruct LLM to use that format and skip this pattern, like organize information in form of a CSV (comma separated value). You don’t need this pattern to provide template to generate a CSV style output. However, if generating a table and want to be in control of column names and order, you would choose to use this pattern.
If you have ever worked with templates say in Microsoft word, or filled any bank or government forms by using their provided template letter, you must be familiar with the concept of ‘placeholders’. Placeholder is the indication in template where you are supposed to fill in your information leaving the other areas untouched. Placeholders in templates can be underscores, all caps, backticks, double quotes, angle brackets etc. As user of ChatGPT, you would be instructing ChatGPT how the output should be inserted in template using the placeholders. Not only the placeholders indicate how/where output needs to be added to template, it has an interesting side effect that it implicitly instructs what not to add to the output. You can control the rigidity by using rigid or open ended placeholders, like
The third statement tries to constrain the LLM to comply with the provided template, however there is no guarantee of that happening and additional output might still seep in or around the template.
One additional concern with constraints is that this pattern actively stops LLM to provide ‘additional information’ about the topic and restrict it to your template. Usage should take that consideration into account.
Lets go over a few examples to understand this pattern better. One example can be that you are studying passenger aeroplanes and want the information to be presented in a particular format. So you would go about doing so like
Provide a list of passenger aircrafts in use by major airlines. I would be providing a template for your output. Follow the formatting and overall template of the output. Use the following template
Name:
Manufacturer:
History:
Engine:
Give this a try and come to admire the results. Not only the output would be in your required format, the LLM would understand the instruction within your template like in the history section. You could restrict such open playing field by just saying Engine:
Another example can be to extract information about episodes from season 1 of your favorite tv show. The prompt could look like You would be provided with a template for output formatting. Capitalized words are the placeholders. Fill in the placeholders with your output. Preserve the formatting of the given template. The template is
## Episode Title:
***Plot***:
***Characters***:
Hopefully you would be able to make use of information in this article to use template pattern in real life with ease. Please clap/share and subscribe this article if you enjoyed. You can also consider subscribing to our YouTube channel as well. Thank you!!!.
Next article: Prmopt Engineering via Prompt Patterns — Infinite Generation Pattern

Niall McNultyWhenever I have repeatable tasks, I think about how I can use AI to assist with them. One of the best ways to do that is to create an…
Anjolaoluwa AjayiFrom Easy to Advanced with Examples