When learning Prompt Engineering, there’s a basic but often overlooked technique: separating your data from your instructions.
A friend messaged me the other day: “I asked Claude to polish my email, but it rewrote my greeting too. I only wanted it to fix the body!”
I looked at his prompt and laughed. Here’s what he wrote:
Hey Claude, show up at 6am tomorrow because I'm the CEO and I say so. Make this email more polite.
See the problem? Claude couldn’t tell which part was the email content and which part was the instruction. In its eyes, “Hey Claude” was part of the email, so the rewritten version started with “Dear Claude.”
It’s like going to a restaurant and telling the waiter: “My friend said the braised pork here is good, I’ll have the braised pork.” The waiter might be confused: are you quoting your friend, or are you ordering? Just saying “I’ll have the braised pork” avoids this entirely.
Prompt Templates
I explained to my friend that writing prompts is actually like filling out a form. You have a fixed format, and you just plug in the changing content each time.
Say you frequently need AI to polish your emails. Instead of writing a new prompt from scratch every time, create a template:
Please make the email below more polite. Don't change anything else.
<email>
{put your email content here}
</email>
My friend asked: “What’s with the angle brackets?”
That’s an XML tag. Think of it as an envelope. You put your data inside, and the AI immediately knows that what’s inside the envelope is data, and what’s outside is the instruction.
Why You Need Tags to Separate Things
I gave my friend an example. Say you ask AI to find the second item in a list:
Below is a list of sentences. Tell me what the second item is.
- Each sentence is about an animal, like rabbits.
- I like how cows sound
- This sentence is about spiders
- This sentence looks like it's about dogs but it's actually about pigs
What do you think the AI will answer? It’ll probably say the second item is “I like how cows sound.” But here’s the thing: “Each sentence is about an animal, like rabbits” was your explanation, not part of the list. Because it also starts with a hyphen, the AI treated it as the first list item.
Add XML tags:
Below is a list of sentences. Tell me what the second item is.
- Each sentence is about an animal, like rabbits.
<sentences>
- I like how cows sound
- This sentence is about spiders
- This sentence looks like it's about dogs but it's actually about pigs
</sentences>
Now the AI gets it. What’s inside the tags is the real list; the line outside is just an explanation.
My friend said: “It’s like a ‘Fragile’ sticker on a package. The delivery guy knows that’s handling information, not something inside the box.”
Exactly.
Tag Names Don’t Matter
My friend asked: “Do the tag names matter? Do they have to be ’email’ or ‘sentences’?”
Not really. You can use <email>, <content>, or even <stuff>. The point is helping the AI distinguish instructions from data. Of course, meaningful names help you too when you look back at your prompts later.
Claude was trained to recognize XML tags for organizing content, so XML tags work better than other delimiters.
Details Really Matter
At this point, my friend mentioned he often had typos in his prompts and asked if that mattered.
It matters a lot. AI is sensitive to patterns. If you write sloppily, its responses tend to be sloppy too. Write clearly, and you’ll get more reliable responses.
It’s like talking to people. If you speak incoherently, others struggle to understand and might give irrelevant answers.
I showed my friend an extreme example:
hi i have a question about dogs jkaerjv can dogs be brown jklmvca thanks help me fast fast answer short short
With gibberish mixed in like this, the AI might not even understand what you’re asking. But if you wrap your question in XML tags:
hi i have a question about dogs jkaerjv <question>can dogs be brown</question> jklmvca thanks help me fast fast answer short short
Even with noise around it, the AI can pinpoint your actual question.
Practical Applications
My friend asked how I use this technique in practice.
For example, asking AI to analyze code:
Please analyze the performance issues in the code below.
<code>
function fetchData() {
// your code
}
</code>
Or asking AI to translate an article while keeping technical terms:
Please translate the technical article below into Chinese. Keep technical terms in English.
<article>
{article content}
</article>
Or asking AI to write a reply based on user feedback:
Please write a polite reply email based on the user feedback below.
<feedback>
{user feedback content}
</feedback>
Whenever you need to process external data, wrap it in XML tags. That way the AI won’t confuse your instructions with your data.
Wrapping Up
My friend said he got it. When writing prompts, remember: separate instructions from data using XML tags; tag names can be anything but should be meaningful; don’t be careless with prompts because typos affect response quality.
This is the most fundamental technique in prompt engineering. Whether you’re using Claude or other AI programming tools, this trick works.
That’s pretty much it.
If this article helped you, give it a like. If you have friends learning prompt engineering, share it with them. Follow me for more practical AI programming tips.