The Secret Language That Makes AI Understand You Perfectly
Master XML and completely transform your conversations with artificial intelligence
Here's what I'm thinking. What if we step out of our comfort zone and learn an advanced way to structure any prompt?
Today we're going to play with XML.
You're probably thinking something like "XML... WTF?" I thought the same thing many years ago when I first heard that term. Don't worry, it's not rocket science (though NASA does use it for their planetary data systems) - I promise it's simple and will completely change how you write prompts :)
So please, just give me one chance to show you what it is and how to use it.
What is XML and what does it have to do with prompts?
Here's the bottom line: XML is a way to structure the text you write so machines understand it better.
Let me put it another way. I bet you use Tupperware to store food - I do too. I use containers for rice, vegetables, I even have containers in the freezer with turkey I made last Christmas. XML is like Tupperware, but for your text. It lets you create separate containers for each part of what you want to say.
Let's try a simple example. Say you have this prompt:
I need creative excuses for not turning in my science homework. I want them to be original, not the typical ones like "my dog ate it" or "I forgot it at home." I'd like one to involve a pet doing something unexpected, another about technology that failed, and the last one something exaggerated but somewhat believable. They should be funny but not make it obvious they're lies.
Not bad, but what happens if we add XML?
<objective>
I need creative excuses for not turning in my science homework.
</objective>
<requirements>
I want them to be original, not the typical ones like "my dog ate it" or "I forgot it at home."
</requirements>
<ideas>
I'd like one to involve a pet doing something unexpected, another about technology that failed, and the last one something exaggerated but somewhat believable.
</ideas>
<tone>
They should be funny but not make it obvious they're lies.
</tone>
If you notice, it's exactly the same text, we've just added these "containers" like <objective> </objective>
, <requirements> </requirements>
, <ideas> </ideas>
and <tone> </tone>
that "wrap around" sections of the prompt.
It's like we're putting each part of the text in its own Tupperware container, and instead of labeling it turkey or rice, we're labeling it as an objective, requirement, ideas, tone, or anything you want! (Yes, seriously, anything that makes sense to you.) And that simple change is what makes a machine understand you so much better.
But wait, there's more! It also has a side effect: it forces us to think about the structure of our prompts, and that alone is a game-changer. Our favorite AI will be much more precise in its responses.
Now, let me tell you that these "containers" have a slightly more technical name. They're called XML elements and they're pretty easy to write.
Anatomy of an XML Element
Ready to impress your friends at your next dinner party with your XML knowledge?
Let me show you an XML element:
Every XML element has three parts:
The opening tag: It's like saying "HERE STARTS something important." It goes between the < > symbols and you give it whatever name you want (as long as it makes sense). In this example I used <context>.
The content: This is what goes inside the element - your question, instruction, or information. Basically, your text.
The closing tag: It's like saying "HERE ENDS that important thing." It looks just like the opening tag but with a / in front, like </context>.
Put it all together, and an XML element looks like this:
<context>
I'm a digital marketing manager looking for campaign ideas
</context>
See how simple it is? Plus, I can't deny that it feels super cool using these keyboard symbols (<, >, /) especially if you weren't used to them before. I used to feel like Neo from The Matrix when I was coding. (Okay, it's not actually programming, but I don't want to get too technical about it)
It's time to put this into action, but first, remember that the structure of an XML element is:
<opening tag> + Content + </closing tag>
Basic Prompt + XML = Super Prompt
You've seen that XML isn't hard to use, and you understand why it makes such a difference. AI is already good at responding, but with this technique you're speaking to it in pro mode. You separate your ideas, give clear context, and eliminate any confusion about what you want.
The result? More precise prompts, more useful responses, and you looking like "why didn't I start doing this sooner?"
And here's the best part: every time you use this structure, you're not just helping the machine... you're also helping yourself think more clearly about what you're asking for.
Your Swiss Army Knife for Prompts
This isn't the first time I've referenced MacGyver (and it won't be the last), but XML is like having a Swiss Army knife for your AI conversations. Just like MacGyver could solve any problem with his knife, two paper clips and some gum, you can structure any prompt with a few XML tags.
The secret is knowing that XML elements can have any name that makes sense to you. Here are some examples:
<context>: Your "who I am and what I need"
<context>I'm an elementary school teacher preparing a class about dinosaurs for 8-year-olds.</context>
<instruction>: Your "do this, please"
<instruction>Create a fun activity that teaches about different types of dinosaurs.</instruction>
<example>: Your "I want something like this"
<example>An activity could be "Dinosaur Detective" where kids get clues and have to guess which dinosaur it is.</example>
There are no "right" or "wrong" names for your elements. What matters is that they're clear and make sense to you...
Well, actually there are a few wrong names :P
You can't use spaces inside an XML tag, so instead of <my instructions> you can use <my_instructions>, <my-instructions>, or <myInstructions>.
Expert Level XML
If you're already comfortable using XML to separate parts of your prompt, get ready for the next level: putting elements inside other elements.
It's like putting a smaller Tupperware container inside a bigger one (I know nobody actually does that, except maybe for storage, but I had to keep the metaphor going).
Sometimes, a single container isn't enough. There are ideas with sub-ideas, instructions with steps, or examples that need context, and XML lets you organize all of that without losing track (or your sanity).
Take a look at this example:
<consultation>
<patient>
I'm a movie villain who feels misunderstood by society.
</patient>
<problem>
I'm considering leaving crime but I miss the dramatic monologues.
</problem>
<question>
How can I channel my need for attention without causing chaos?
</question>
</consultation>
See what we did? We grouped <patient>, <problem> and <question> inside a single element called <consultation>. It's like telling the AI: "all of this is part of the same case... treat it as one package." (I highly recommend trying this prompt with your AI - the recommendations are hilarious!)
And here's the beauty of it: you can keep nesting elements inside others, and inside others... There's no limit. As long as everything is properly closed and tagged, the AI will understand it perfectly.
Before You Were Cool, But Now You Use XML (And You're Even Cooler)
Remember those infomercials where someone tries to do sit-ups in black and white, falls over, gets frustrated... and then a miracle machine appears that transforms them in six weeks?
Well, this is the same thing. Except I'm not here to sell you the Ab-Shaper™... but XML (and I'm not promising to transform your physique, just your prompts).
BEFORE (in black and white, obviously):
I have a dog with expensive tastes who's bankrupting me. I need recipes that seem gourmet but are cheap to prepare. I've noticed he loves meat dishes, especially lamb. He also seems to appreciate elegant food presentation. Can you suggest 3 deceptive recipes? I also need ideas for presenting these recipes so they look like luxury restaurant food.
Everything is there... but everything is mixed together. Context, needs, observations and two different requests. The AI might hit the mark or get lost halfway through.
AFTER (in full color with motivational music):
<context>
I have a dog with expensive tastes who's bankrupting me.
</context>
<observations>
<point>I need recipes that seem gourmet but are cheap to prepare.</point>
<point>He loves meat dishes, especially lamb.</point>
<point>He seems to appreciate elegant food presentation.</point>
</observations>
<requests>
<request>Suggest 3 deceptive recipes that meet these criteria.</request>
<request>Give me ideas for presenting these recipes so they look like luxury restaurant food.</request>
</requests>
Can you see the difference?
The AI knows what's context and what are the requests.
Each key point is separated, clear and easy to digest.
Having nested elements lets you handle complex prompts with ease.
There's no room for anything to slip through the cracks.
Turn Your XML Elements Into Superheroes (Not Villains)
You know how to use XML elements now, but as Uncle Ben said, with great power comes great responsibility. So before you start throwing tags around like crazy, here are some tips to turn your prompts into super-prompts... not disasters with capes.
1. Give them names your grandma would understand
You don't need technical or fancy terms. The best names clearly say what's inside. If your grandma gets it, the AI gets it. And you get it, which is even more important.
Good prompt :)
<my_problem>
I can't stop thinking about conspiracy theories involving cats.
</my_problem>
<what_i_already_tried>
I turned off the Wi-Fi, deleted TikTok and tried to meditate.
</what_i_already_tried>
<what_i_need>
Give me 3 ways to distract my mind before bed (without involving cats).
</what_i_need>
Not so good prompt :(
<p1>
I can't stop thinking about conspiracy theories involving cats.
</p1>
<data>
I turned off the Wi-Fi, deleted TikTok and tried to meditate.
</data>
<query>
Give me 3 ways to distract my mind before bed (without involving cats).
</query>
<p1>? <data>? <query>? They tell you nothing. These names are so generic that even you don't know what's inside them. If they confuse you, they'll confuse the AI too.
2. Be consistent (like your favorite TV show... not like the Game of Thrones finale)
If you start calling something <my_problem>, don't change it later to <the_issue>.
Consistency isn't just for the AI - it's for you too. It helps you not get lost in your own tags and stay in control, like any good script should. Right, Daenerys?
3. Don't go into "XML architect mode"
You don't need to build a complex structure just because you can. Use the elements that actually bring clarity, and skip the rest.
Remember you're writing a prompt, not designing a pyramid. Nobody's giving you an award for using "<meta_superior_contextual_tag_v2>".
When XML Really Shines
Not every prompt needs structure. If you're just asking AI about the weather in Tokyo, one line does the job.
But when your request is more... let's say... ambitious, XML swoops in like a ninja! 🥷
<context>
I want to learn ninjutsu, seriously.
</context>
<current_situation>
I have two young kids, a full-time job, a weekly newsletter, and a to-do list that's terrifying.
</current_situation>
<limitations>
Very little free time. Tight budget. Zero experience in martial arts.
</limitations>
<objective>
Design a minimal viable routine to get started in ninjutsu without destroying my family or professional life.
</objective>
<request>
Give me a realistic training plan for someone like me, with:
1. Free resources to start from home
2. Small but epic weekly goals
3. Tips for staying motivated when everything gets chaotic
</request>
This isn't a simple prompt. It's an attempt to balance parenthood, work, and the art of becoming invisible.
Without structure, the AI would probably just say: "Find a ninjutsu school near you."
The Doubts You Probably Have (I Had Them Too)
When I started using XML, I had tons of questions. These are probably the same ones you're thinking about right now:
Isn't this too technical for me?
Not at all. If you can use quotation marks or hashtags, you can handle XML. We're not programming here - just labeling. It's like putting sticky notes on a document to organize your thoughts.
What if I make a mistake? Do I ruin everything?
Relax. AI doesn't penalize you for errors. If you forget to close a tag or misspell something, it usually figures it out anyway.
Are there "correct" names I should use for tags?
Nope, no official names. The rule is simple: make them meaningful to you and the AI, clearly describe what's inside, and avoid spaces (or special characters).
Is it worth the extra effort?
Depends. For simple prompts, probably not. But when you have multiple parts, conditions, or complex instructions, the difference between using XML or not can be massive.
What if I forget to close a tag? Does everything explode?
Two things can happen, and neither is ideal (though AI often figures it out anyway):
You don't close it: It's like leaving Tupperware open in your backpack. Everything gets mixed together - rice ends up with dessert and nobody knows what's what. AI tries to guess and usually does fine, but your prompt might turn into a soup of concepts.
You close it wrong: It's like putting a small container inside a big one, closing the big one first... then trying to put the lid on the small one from outside. It doesn't fit and things might go haywire!
</post>
Yes, this is a closing tag. It doesn't do anything, but I had to end with style :)
If you made it this far, you know more about XML than 99% of people. I know this was a long journey, so thanks for sticking with an explanation full of gourmet dogs, tags, and ninjas. And if you now see text containers everywhere in your prompts... mission accomplished!
Best,
G
Hey! I'm Germán, and I write about AI in both English and Spanish. This article was first published in Spanish in my newsletter AprendiendoIA, and I've adapted it for my English-speaking friends at My AI Journey. My mission is simple: helping you understand and leverage AI, regardless of your technical background or preferred language. See you in the next one!