Skip to content

XML-Style Tagged Prompts: A Framework for Reliable AI Responses

Published: at 

Why Traditional AI Communication Falls Short

Getting consistent, well-structured responses can be challenging when working with LLMs. Traditional prompting often leads to unpredictable results, making relying on AI assistance for complex tasks difficult. While exploring prompt engineering techniques this year, I discovered an interesting approach: Tagged Prompts. This method has improved my interactions with AI, delivering more thoughtful responses.

What Are Tagged Prompts? A Simple Guide

Tagged prompts borrow from XML’s structured approach to data organization. By wrapping different parts of our prompts in descriptive tags, we create a clear framework for AI responses. Think of it as creating a mental model that guides the AI’s thinking process.

The XML Connection

To understand tagged prompts, let’s first look at XML’s simple yet powerful structure:

<book>
  <title>The Great Gatsby</title>
  <author>F. Scott Fitzgerald</author>
</book>

This familiar structure provides the foundation for our prompt engineering approach.

How Tagged Prompts Work: XML-Style Structure

Let’s compare how an AI responds to the same question with and without tagged prompts:

Standard Response

👤
I want to learn software engineering. What should I do?

Before vs After: Impact of Tagged Prompts on AI Responses

Step-by-Step Guide to Implementing Tagged Prompts

Tagged prompts can be implemented in two ways:

  1. As a system prompt for ongoing AI interactions
  2. As part of individual conversation messages
Claude System Prompt
Example of how a system prompt with instructions on Claude's project looks like.

Basic Implementation

Here’s a simple but effective system prompt structure:

System Prompt

When answering queries:
1. Think through your reasoning in <thinking> tags
2. Provide your answer in <output> tags 
3. If you spot an error, explain and correct it in <reflection> tags

Tagged Response Example

👤
I want to learn software engineering. What should I do?

Advanced Techniques: Taking Tagged Prompts Further

For more sophisticated applications, we can add quality metrics and step tracking:

System Prompt

Use <thinking> tags to explore different approaches and viewpoints  
Use <step> tags to break down the solution (20 step budget, request more if needed)  
Add <count> tags after each step to track remaining budget  
Use <reflection> tags to evaluate progress and be self-critical  
Rate quality with <reward> tags (0.0-1.0):

- Greater than or equal to 0.8: Continue approach
- Between 0.5 and 0.7: Minor adjustments
- Less than 0.5: Try new approach

Show all work and calculations explicitly  
Explore multiple solutions when possible  
Summarize final answer in <answer> tags  
End with final reflection and reward score  
Adjust strategy based on reward scores and intermediate results

Tagged Prompts in Production: v0 by Vercel Case Study

Vercel’s AI assistant v0 demonstrates how tagged prompts work in production. Their implementation, revealed through a leaked prompt on Reddit, shows the power of structured prompts in professional tools.

Essential Resources for Mastering Tagged Prompts

For deeper exploration of tagged prompts and related concepts:

Key Takeaways: Getting Started with Tagged Prompts

This was just a quick overview to explain the basic idea of tagged prompts. I would suggest trying out this technique for your specific use case. Compare responses with tags and without tags to see the difference.