Skip to main content

Wider Page

 

Bigger text

 

In the last few lessons, we explored the Extended Modeling Language (XML). I am pretty sure some students already ask themselves, “Why do I need to learn about XML? Is this still relevant today?

Well, guess what — the skills you gained from learning XML actually help you work more effectively with AI tools like ChatGPT.

This bonus lesson on prompt engineering will show you that no knowledge is ever wasted. Everything you learn can become useful in unexpected ways. Let’s find out how.

What is Prompt Engineering?

Prompt engineering is the art of writing the most optimal and efficient instructions to AI models like ChatGPT. The way you write your instructions — called prompts — determines the quality of the response. Many people think ChatGPT simply “knows everything.” In reality, it doesn't know everything; it relies on a very large set of data, Google searches, and generative language. The results it yields are very closely related to how well you write your prompt.

ChatGPT Prompt
Figure 1. ChatGPT Prompt.

If you already know XML, you’re at an advantage. XML teaches you how to structure data using tags. Prompt engineering is similar — you structure instructions, roles, and ideas using user-defined tags. In this lesson, we’ll explore how XML-style prompting helps for better results.

What is a Prompt?

A prompt is the input or message you give to ChatGPT. It can be a single question, a set of rules, or even an entire document. For example:

Simple ChatGPT prompt
Figure 2. Simple ChatGPT prompt.

This looks like a simple prompt, and most people believe nothing could go wrong with it. However, it’s not clear or specific enough. Many users assume the AI is smart enough to “guess” their intentions and deliver the perfect answer automatically. In reality, it doesn’t work that way.

KEY NOTE: With AI models, you must be explicit about everything.

Now let's see the same example but using contextual tags like XML. Look how much more explicit the prompt is. Logically, it will give a result that aligns much better with our intentions.

Simple structured ChatGPT prompt
Figure 3. Simple structured ChatGPT prompt.

Keep in mind that these tags are not real XML. They are a tag-based structure that gives ChatGPT more explicit instructions on what you want and what it must do. 

Prompting in Structure

XML’s main strength is clarity through hierarchy—prompt engineering benefits from the same mindset. When your instructions have a clear structure, ChatGPT interprets them much better and yields much better results.

Consider the following example of an unstructured prompt:

Unstructured prompt
Figure 4. Unstructured prompt.

Now consider the same example but written with a user-defined tag structure that explicitly tells ChatGPT what we want.

Example of a well-structured prompt.
Figure 5. Example of a well-structured prompt.

Which prompt do you think will yield better results? It is obvious that the question doesn't need answering.

Using tag-based prompting will yield much stronger results: The idea is that XML-like thinking builds clearer and more layered instructions.

The main elements of a good prompt

After researching the topic and drawing on my personal experience, I identified the following elements that I believe are essential for sound prompt engineering. You can think of every good prompt as an XML document with these tags:

ChatGPT prompt main components
Figure 6. ChatGPT prompt main components.
  • The context tells ChatGPT who it is or what situation it’s in, helping it set the right tone and perspective.
  • The task explains exactly what you want it to do — such as write, compare, or summarize.
  • The output section defines how the result should look, including the length, format, and style. 

When these three elements are clear, ChatGPT can produce focused, accurate, and well-structured answers. This structured way of thinking ensures the model has all the details it needs.

The other tag elements are optional and provide a slight improvement most of the time. However, depending on the subject, there can be a huge difference.

Prompt Nesting

Just like XML allows nested elements, complex prompt engineering can have nested requests. This is useful when building multi-part outputs. Consider the following example.

ChatGPT prompt nesting
Figure 7. ChatGPT prompt nesting.

This produces an organized, multi-section result because each task is clearly defined — similar to child elements in XML.

Common Mistakes in Prompt Writing

Most people don't really think about prompt engineering at all. Therefore, they always use suboptimal prompts and get suboptimal results. Here are the most common mistakes to avoid when working with AI tools:

  • Missing context - The model doesn’t know the context you are asking the question in. It assumes the context from your chat history with it, which is often suboptimal. You typically have the context in your head and assume the AI model gets it from one sentence, which is not the case in reality. Always provide context in <context> tags for better results.
  • Contradicting instructions - Mixed instructions confuse the AI model, and the answer often turns out inconsistent. The best approach is to give clear, explicit, single-purpose instructions.
  • Vague requirements - If your prompt is too broad, the answer can go in any direction. Always specify length, tone, or format — as if defining an XML document.

Why does XML prompting work so well?

ChatGPT doesn’t execute XML code, but the logical structure of XML mirrors the logic of good communication.  Using XML-style tags works well because they make your prompts explicit, clear, and organized. Each tag defines a specific part of the instruction, such as the task, tone, or format. This structured approach helps ChatGPT understand context and priorities more accurately. It’s similar to how XML organizes data, making your intentions easier for the model to follow.

By using these concepts, you give the AI clear “metadata” about your intentions — similar to how XML tells software what each piece of data means.

Practice, practice, practice...

To improve, take your normal prompts and “wrap” them in XML-style tags before sending them. You can test both versions and compare the results. The structured one will almost always produce a cleaner and more relevant answer.

Bonus Tip: Iterations

Lastly, let me share with you one of the most powerful prompt engineering hacks that can significantly improve the quality of the results you are getting from ChatGPT.

Full Content Access is for Subscribed Users Only...

  • Learn any CCNA, CCIE or Network Automation topic with animated explanation.
  • We focus on simplicity. Networking tutorials and examples written in simple, understandable language.