Guide to Structuring Complex Prompts Using Tags and Delimiters
When interacting with AI systems, particularly for tasks requiring precision and clarity, using structured prompts with identifiable tags or delimiters is essential. This guide explains how to design such prompts, the advantages of structured formatting, and the commonly used tags recognized internally by AI models like ChatGPT. These techniques help create modular, reusable, and easy-to-understand prompts for a variety of tasks.
Tags and delimiters bring order and clarity to your prompts, making them more interpretable for both humans and AI. Here are the key benefits:
Here are the most effective tags that can be used when designing prompts:
Defines the situation, role, or background that the AI needs to adopt.
<context>
You are an expert in TypeScript and React.js.
</context>
Specifies what task or action the AI should perform.
<instruction>
Write a concise explanation of closures in JavaScript.
</instruction>
Provides examples to guide the AI’s behavior.
<examples>
Input: [2, 4, 6]
Output: 12 (sum of all elements)
Input: [1, 3, 5]
Output: 9 (sum of all elements)
</examples>
Defines any limitations or rules that must be followed.
<constraints>
1. Use plain English.
2. Keep responses under 100 words.
</constraints>
Specifies the desired output format.
<formatting>
Output the explanation as a Markdown bullet list.
</formatting>
Describes the ultimate goal or objective of the task.
<goal>
Help the reader understand memoization in React and how it prevents unnecessary re-renders.
</goal>
Explicitly sets the AI’s role or persona.
<role>
You are a teacher explaining concepts to beginners.
</role>
Organizes information in a Q&A format.
<question>
What are closures in JavaScript?
</question>
<answer>
A closure is a function that retains access to variables from its outer scope, even after the outer function has executed.
</answer>
Adds additional information or reminders for clarification.
<notes>
This explanation should be suitable for junior developers with minimal experience.
</notes>
If you prefer not to use XML-like tags, you can use these alternative formats:
Structured prompts can also be represented as JSON, which is easily parsed by software:
{
"context": "You are a JavaScript expert.",
"instruction": "Explain closures in simple terms.",
"examples": [
{
"input": "function outer() { let x = 1; return function inner() { return x; }; }",
"output": "The inner function retains access to the variable 'x'."
}
],
"constraints": "Keep the explanation under 50 words."
}
Instead of using tags, you can separate sections with distinct symbols or headings:
### Context:
You are an SQL optimization expert.
### Task:
Optimize the following query:
SELECT * FROM orders WHERE status = 'completed';
### Constraints:
- Database: PostgreSQL
- Avoid using subqueries.
### Example:
Input:
SELECT * FROM orders WHERE status = 'completed';
Output:
SELECT id, status, created_at FROM orders WHERE status = 'completed';
If your prompt is simple or short, using tags might be unnecessary and could add unnecessary complexity. For example:
Explain what closures are in JavaScript and provide an example.
For one-off or straightforward tasks, a single line is often sufficient.
Here’s an example of a fully tagged prompt for a complex task:
<context>
You are an AI assistant helping developers optimize React applications.
</context>
<instruction>
Explain how to use React.memo to optimize component rendering.
</instruction>
<examples>
Example 1:
Input: A parent component with frequently changing props.
Output: Use React.memo to prevent re-renders of child components when props have not changed.
</examples>
<constraints>
1. Use simple language.
2. Keep responses under 100 words.
</constraints>
<goal>
Help developers understand when and how to use React.memo effectively.
</goal>
Using structured prompts with tags or delimiters provides clarity, consistency, and modularity for complex tasks. Whether you’re creating reusable templates, parsing prompts programmatically, or ensuring precision in responses, adopting a structured approach will significantly improve outcomes. Experiment with these techniques and find the style that best suits your workflows.
If you have specific needs or questions, feel free to reach out for tailored advice!
Organize your work by saving anything to your private dashboard
Get a For you & Following feed.
Copy any page you can see
Subscribe to get in app notifications changes of pages
Create your own curated searches for content you care about
Follow others
View history of what you have created, updated, or viewed
Limited time offer
When signing up for a year, I will work with you for an hour to create prompts specific for your needs!Create Private content
Add specific people to edit or view your content
Get access to a growing list of AI features to help you convert your prompts, summarize content for organization, and more!