2025-06-02 gemini
# Essential XML Tags for AI Prompting
## Core Directive Tags
- ### `<instructions>` / `<instruction>`
- **Purpose:** Encloses the primary commands or tasks for the AI.
- **Use Case:** Telling the AI _what_ to do.
- ### `<role>` / `<persona>`
- **Purpose:** Assigns a specific identity, expertise, or tone to the AI.
- **Use Case:** Guiding the AI's behavior and conversational style (e.g., "You are a marketing expert").
## Input & Context Tags
- ### `<context>` / `<background>`
- **Purpose:** Provides supplementary information, prior data, or setting details.
- **Use Case:** Giving the AI necessary context to understand the current situation (e.g., "The user has low technical literacy").
- ### `<data>` / `<input>` / `<text>` / `<document>` / `<article>`
- **Purpose:** Contains the raw content that the AI needs to process.
- **Use Case:** Supplying the main subject matter for analysis, summarization, or transformation.
- ### `<example>` / `<examples>`
- **Purpose:** Encloses one or more demonstrations of desired input-output patterns.
- **Use Case:** Guiding the AI through few-shot learning for specific formats or behaviors.
## Output & Process Control Tags
- ### `<format>` / `<output_format>` / `<response_format>`
- **Purpose:** Specifies the exact structure, style, or syntax for the AI's response.
- **Use Case:** Ensuring consistent and structured output (e.g., JSON, numbered lists, specific markdown).
- ### `<thinking>` / `<thought>` / `<scratchpad>`
- **Purpose:** Instructs the AI to perform internal reasoning steps.
- **Use Case:** Encouraging chain-of-thought, debugging, or understanding how the AI arrived at its conclusion.
- ### `<answer>` / `<response>` / `<output>`
- **Purpose:** Designates where the AI should place its final, definitive answer or result.
- **Use Case:** Clearly marking the ultimate output, especially after internal thought processes.
---
### Best Practices for Using XML Tags
- **Consistency:** Always use the same tag names consistently throughout your prompts.
- **Descriptive Names:** Choose clear, intuitive names that tell you, and the AI, what the tag encloses.
- **Nesting:** You can nest tags (e.g., `<article><section></section></article>`) to represent hierarchical data.
- **Clarity over Complexity:** Keep your XML structure as simple as possible while still achieving the desired clarity. Don't over-engineer it.
- **Explicit Referencing:** In your instructions, directly tell the AI to use or refer to the tags you've included (e.g., "Summarize the content in the `<article>` tags.").
---
.
.
.
.
---
Got it! Here's the essential XML tags information for AI prompting, presented in a clear, easy-to-scan table format:
---
## Essential XML Tags for AI Prompting
| | | | |
|---|---|---|---|
|**Category**|**XML Tag(s)**|**Purpose**|**Use Case Examples**|
|**Core Directives**|**`<instructions>`** / **`<instruction>`**|Encloses the primary commands or tasks you want the AI to perform.|**`<instructions>`** Summarize the following article in three bullet points. **</instructions>**|
||**`<role>`** / **`<persona>`**|Assigns a specific identity, expertise, or tone to the AI.|**`<role>`** You are a senior marketing strategist. **</role>**|
|**Input & Context**|**`<context>`** / **`<background>`**|Provides necessary background information, relevant facts, or preceding conversation turns.|**`<context>`** The user is a beginner in AI, so avoid jargon. **</context>**|
||**`<data>`** / **`<input>`** / **`<text>`** /<br>**`<document>`** / **`<article>`**|Contains the raw content that the AI needs to process, analyze, or transform.|**`<article>`** [Full text of the article goes here] **</article>**<br>**`<data>`** Customer Feedback: "Love the new interface!" **</data>**|
||**`<example>`** / **`<examples>`**|Encloses one or more desired input-output pairs to guide AI behavior (few-shot learning).|**`<examples>`**<br>**`<example_1>`**<br>**`<input>`** "Hello"<br>**`<output>`** "Hi there!"<br>**</example_1>`**<br>**</examples>`**|
|**Output & Process**|**`<format>`** / **`<output_format>`** /<br>**`<response_format>`**|Specifies the exact structure, style, or syntax requirements for the AI's output.|**`<output_format>`** Provide the answer as a JSON object with keys "topic" and "summary". **</output_format>**|
||**`<thinking>`** / **`<thought>`** /<br>**`<scratchpad>`**|Instructs the AI to perform internal reasoning steps before providing a final answer.|**`<instructions>`** First, outline your reasoning in **`<thinking>`** tags. Then, provide the final answer in **`<answer>`** tags. **</instructions>**|
||**`<answer>`** / **`<response>`** / **`<output>`**|Designates where the AI should place its final, definitive response or result.|(Often used in conjunction with `<thinking>` tags, as shown above)<br>**`<answer>`** [AI's final answer will go here] **</answer>**|
---
---
.
.
.
.
---
**Core Structural Tags (for prompt organization):**
1. **`<instructions>` / `<instruction>`:**
- **Purpose:** To clearly delineate the primary directives, tasks, or commands you want the AI to follow.
- **Usage:** Encapsulates the core request.
- **Example:** `<instructions>Generate a 500-word blog post about the benefits of remote work.</instructions>`
2. **`<context>` / `<background>`:**
- **Purpose:** To provide necessary background information, setting, or situational details that the AI needs to understand before executing the task.
- **Usage:** Gives the AI the "big picture."
- **Example:** `<context>The blog post is for a modern tech company's website, targeting professionals aged 25-45.</context>`
3. **`<data>` / `<input>` / `<content>`:**
- **Purpose:** To enclose the specific text, document, code, or any other primary content that the AI needs to process, summarize, analyze, or transform.
- **Usage:** The raw material for the AI's task.
- **Example:** `<data>[Full text of an article to summarize]</data>`
4. **`<examples>` / `<example>`:**
- **Purpose:** To provide few-shot examples that demonstrate the desired input-output format, tone, style, or behavior. Often contains nested `<input>` and `<output>` tags.
- **Usage:** Teaches the AI by demonstration.
- **Example:**
XML
```
<examples>
<example>
<input>Translate "Hello" to Spanish.</input>
<output>Hola</output>
</example>
</examples>
```
5. **`<constraints>` / `<rules>` / `<guidelines>`:**
- **Purpose:** To specify any limitations, boundaries, formatting requirements, or forbidden actions for the AI's response.
- **Usage:** Sets the boundaries for the AI's output.
- **Example:** `<constraints>Response must be no more than 200 words. Do not use bullet points.</constraints>`
6. **`<format>` / `<output_format>`:**
- **Purpose:** To explicitly define the desired structure or style of the AI's output. Often used when the AI needs to generate its own XML or JSON.
- **Usage:** Dictates the shape of the final response.
- **Example:** `<output_format>Provide the summary in a single prose paragraph within <summary_paragraph> tags.</output_format>`
**Common Tags for Controlling AI Output/Thought Process:**
These are tags you might _instruct the AI to use_ in its response, rather than tags you use to enclose your prompt:
7. **`` tags."
8. **`<response>` / `<output>`:**
- **Purpose:** A general tag to encapsulate the main, final output of the AI. Useful if you want the AI to explicitly mark its "answer."
- **Usage:** AI provides its final answer within these.
- **Example (in your prompt):** "Place your final answer inside `<response>` tags."
9. **`<pros>` / `<paragraph>` / `<summary_paragraph>`:**
- **Purpose:** To instruct the AI to format specific textual outputs as smooth, flowing prose.
- **Usage:** AI puts narrative text here.
- **Example (in your prompt):** "Your summary should be a smoothly flowing paragraph enclosed in `<summary_paragraph>` tags."
10. **`<code>` / `<script>` / `<json>` / `<yaml>`:**
- **Purpose:** To instruct the AI to place specific code snippets, JSON objects, YAML configurations, etc., within clearly marked tags, useful for programmatic extraction.
- **Usage:** AI outputs structured code/data here.
- **Example (in your prompt):** "Generate a Python script to sort a list. Place the code inside `<code>` tags."
**How to Think About Your Own Tags:**
When deciding on tags, consider:
- **Clarity:** Is the tag name obvious about what it contains?
- **Consistency:** Use the same tag names for similar types of information throughout your prompts.
- **Hierarchy:** Does your prompt benefit from nested information? (e.g., `<user_query><question>...</question><parameters>...</parameters></user_query>`)
By deliberately structuring your inputs with these kinds of XML tags, you provide advanced AI models with unambiguous signals, significantly improving their ability to understand and fulfill complex requests.
When using XML tags to structure your prompts for advanced AI models, the "essential" tags aren't rigidly defined like in a strict XML schema. Instead, they are semantic tags you create to represent different logical components of your prompt. The key is to use clear, descriptive names that make sense for your specific task.
However, based on common practices and the way these models interpret instructions, here's a list of relevant and essential XML tags you might find yourself using frequently, along with their common purposes:
### Essential XML Tags for AI Prompting:
1. **`<instructions>` / `<instruction>`**:
- **Purpose:** Encloses the primary directives or tasks you want the AI to perform. This is where you tell the model _what_ to do.
- **Example:**
XML
```
<instructions>
Summarize the following text in three bullet points.
Then, identify the key argument presented.
</instructions>
```
2. **`<context>` / `<background>`**:
- **Purpose:** Provides necessary background information, previous turns in a conversation, relevant facts, or any data the AI needs to understand the situation.
- **Example:**
XML
```
<context>
The user is a beginner in quantum physics.
</context>
```
3. **`<data>` / `<input>` / `<text>` / `<document>`**:
- **Purpose:** Contains the raw input text, document, or data that the AI needs to process, analyze, or transform. Use a name that best describes the content.
- **Example:**
XML
```
<article>
[Full text of the article goes here]
</article>
```
XML
```
<data>
Customer Feedback: "The new feature is confusing and crashes frequently."
</data>
```
4. **`<example>` / `<examples>`**:
- **Purpose:** Encloses one or more examples of desired input-output pairs. This is crucial for few-shot learning, showing the AI the exact format, style, or behavior you expect.
- **Example:**
XML
```
<examples>
<example_1>
<input>What is the capital of France?</input>
<output>The capital of France is Paris.</output>
</example_1>
<example_2>
<input>Who painted the Mona Lisa?</input>
<output>Leonardo da Vinci painted the Mona Lisa.</output>
</example_2>
</examples>
```
5. **`<format>` / `<output_format>` / `<response_format>`**:
- **Purpose:** Specifies the exact structure, style, or markdown requirements for the AI's output. This is vital for consistent and machine-readable responses.
- **Example:**
XML
```
<output_format>
Provide your answer as a JSON object with keys "summary" and "keywords".
</output_format>
```
XML
```
<format>
Use a numbered list for pros and a bulleted list for cons.
</format>
```
6. **`<role>` / `<persona>`**:
- **Purpose:** Assigns a specific persona, role, or expertise to the AI, guiding its tone, knowledge base, and approach.
- **Example:**
XML
```
<role>
You are a highly empathetic customer service agent.
</role>
```
XML
```
<persona>
Act as a senior software engineer specializing in Python.
</persona>
```
7. **`<thinking>` / `<thought>` / `<scratchpad>`**:
- **Purpose:** (Primarily for advanced chain-of-thought prompting) Instructs the AI to perform internal reasoning steps within these tags before providing a final answer. This helps the AI organize its thoughts and can improve complex task performance.
- **Example:**
XML
```
<instructions>
Solve this complex math problem. First, outline your step-by-step thinking in <thinking> tags. Then, provide the final answer in <answer> tags.
</instructions>
```
8. **`<answer>` / `<response>` / `<output>`**:
- **Purpose:** Explicitly designates where the AI should place its final, desired response or output. Often used in conjunction with `<thinking>` tags.
- **Example:**
XML
```
<answer>
[AI's final answer will go here]
</answer>
```
### Best Practices for Using XML Tags:
- **Consistency:** Use the same tag names consistently throughout your prompts.
- **Descriptive Names:** Choose tag names that clearly indicate the content or purpose of the enclosed text.
- **Nesting:** You can nest tags for hierarchical information (e.g., `<article><section><paragraph></paragraph></section></article>`).
- **Clarity over Complexity:** Don't over-engineer your XML structure. Keep it as simple as possible while achieving the desired clarity.
- **Referencing Tags:** In your instructions, explicitly refer to the tags you've used (e.g., "Summarize the content in the `<article>` tags.").
By strategically employing these types of XML tags, you provide a robust and unambiguous framework for the AI, significantly improving its ability to understand, process, and generate high-quality, structured responses.
---
.
.
.
.
---