MyiWorlds
MyiWorlds
Guide for designing structured prompts
Public
Text
0
Owner & Editor:
Edited: over 1 year agoCreated: over 1 year ago

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.




Why Use Structured Prompts with Tags?

Tags and delimiters bring order and clarity to your prompts, making them more interpretable for both humans and AI. Here are the key benefits:

  1. Segmentation of Contexts: By breaking the prompt into sections, you can better convey specific information like instructions, examples, or constraints.
  2. Clarity: Tags make each part of the prompt’s intent explicit, reducing ambiguity and errors.
  3. Reusability: Modular design allows you to reuse and adapt different sections.
  4. Scalability: Complex multi-step tasks or instructions can be handled more effectively by AI.
  5. Parsing: If you are programmatically managing prompts, using structured tags simplifies processing and automation.




Common Tags Recognized Internally by AI

Here are the most effective tags that can be used when designing prompts:

1. Context Tags

Defines the situation, role, or background that the AI needs to adopt.

<context>
You are an expert in TypeScript and React.js.
</context>

2. Instruction Tags

Specifies what task or action the AI should perform.

<instruction>
Write a concise explanation of closures in JavaScript.
</instruction>

3. Example Tags

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>

4. Constraints Tags

Defines any limitations or rules that must be followed.

<constraints>
1. Use plain English.
2. Keep responses under 100 words.
</constraints>

5. Formatting Tags

Specifies the desired output format.

<formatting>
Output the explanation as a Markdown bullet list.
</formatting>

6. Goal Tags

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>

7. Role Tags

Explicitly sets the AI’s role or persona.

<role>
You are a teacher explaining concepts to beginners.
</role>

8. Question/Answer Tags

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>

9. Notes Tags

Adds additional information or reminders for clarification.

<notes>
This explanation should be suitable for junior developers with minimal experience.
</notes>


Alternative Formats

If you prefer not to use XML-like tags, you can use these alternative formats:

JSON Format

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."
}

Delimiters

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';


Best Practices for Prompt Structuring

  1. Be Explicit: Clearly define the purpose and scope of each section.
  2. Use Relevant Tags: Only include tags that are necessary for the task. Avoid overloading the prompt.
  3. Keep It Concise: AI performs better when given direct, to-the-point instructions.
  4. Experiment and Iterate: Test different structures to see what works best for your specific application.
  5. Be Consistent: Use the same tagging style across all prompts for predictability.
  6. Avoid Ambiguity: Avoid vague instructions; use examples and constraints to clarify.


When to Avoid Tags

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.



Combining Tags for Complex Tasks

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>


Conclusion

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!



Create an account to create public content for free!

With an account you can:
  • 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

Upgrade to Pro!

  • 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!