<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sanat Kulkarni</title>
    <description>The latest articles on DEV Community by Sanat Kulkarni (@sanatkulkarni).</description>
    <link>https://dev.to/sanatkulkarni</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3283193%2Fe539ad4b-4a8d-4588-8b32-89f3a8069736.png</url>
      <title>DEV Community: Sanat Kulkarni</title>
      <link>https://dev.to/sanatkulkarni</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sanatkulkarni"/>
    <language>en</language>
    <item>
      <title>Why XML Prompting?</title>
      <dc:creator>Sanat Kulkarni</dc:creator>
      <pubDate>Thu, 13 Aug 2026 05:41:33 +0000</pubDate>
      <link>https://dev.to/sanatkulkarni/why-xml-prompting-ip3</link>
      <guid>https://dev.to/sanatkulkarni/why-xml-prompting-ip3</guid>
      <description>&lt;p&gt;LLMs act in weird ways for unexplainable reasons sometimes, especially SLMs (Small Language Models). Yet, we have to work with them for various reasons; be it available resources, policy restraints, etc.&lt;/p&gt;

&lt;p&gt;XML (Extensible Markup Language) Prompting helps you with this exact problem. It gives your LLM or SLM the exact right type of context that is needed for it to act unambiguously. It is a way of structuring prompts that mix instructions, context, examples, and variable inputs.&lt;/p&gt;

&lt;p&gt;How does an XML look? To those who have used HTML before, it might look similar. A snippet looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;message&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;text&amp;gt;&lt;/span&gt;Hello World!&lt;span class="nt"&gt;&amp;lt;/text&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/message&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use case:&lt;br&gt;
SLMs usually struggle with maintaining context, have less memory capacity and are either heavily quantized or having less training data as compared to LLMs. &lt;/p&gt;

&lt;p&gt;They are the exact playground when you need speed yet you want the job to be done in specified constraints (Assuming usage of local AI to prevent any kind of confidential data leakage). &lt;/p&gt;

&lt;p&gt;Let's take an example of a prompt with and without XML prompting:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Without XML Prompting&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You are a document summarization assistant.

Task:
Summarize the document provided by the user.

Instructions:
- Identify the main topic.
- Extract the most important points.
- Keep the summary under 150 words.
- Do not invent information.
- Use simple language.

Example:
Input: "The company reported a 20% increase in revenue..."
Output: "The company experienced significant revenue growth..."

Document:
{{DOCUMENT}}

Additional user instructions:
{{USER_INSTRUCTIONS}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;With XML Prompting&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;task&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;name&amp;gt;&lt;/span&gt;Document Summarization&lt;span class="nt"&gt;&amp;lt;/name&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;instructions&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;instruction&amp;gt;&lt;/span&gt;Identify the main topic.&lt;span class="nt"&gt;&amp;lt;/instruction&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;instruction&amp;gt;&lt;/span&gt;Extract the most important points.&lt;span class="nt"&gt;&amp;lt;/instruction&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;instruction&amp;gt;&lt;/span&gt;Keep the summary under 150 words.&lt;span class="nt"&gt;&amp;lt;/instruction&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;instruction&amp;gt;&lt;/span&gt;Do not invent information.&lt;span class="nt"&gt;&amp;lt;/instruction&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;instruction&amp;gt;&lt;/span&gt;Use simple language.&lt;span class="nt"&gt;&amp;lt;/instruction&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/instructions&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;example&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&amp;gt;&lt;/span&gt;
      The company reported a 20% increase in revenue...
    &lt;span class="nt"&gt;&amp;lt;/input&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;output&amp;gt;&lt;/span&gt;
      The company experienced significant revenue growth...
    &lt;span class="nt"&gt;&amp;lt;/output&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/example&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;context&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;audience&amp;gt;&lt;/span&gt;Business executives&lt;span class="nt"&gt;&amp;lt;/audience&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;tone&amp;gt;&lt;/span&gt;Concise and professional&lt;span class="nt"&gt;&amp;lt;/tone&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/context&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;document&amp;gt;&lt;/span&gt;
    {{DOCUMENT}}
  &lt;span class="nt"&gt;&amp;lt;/document&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;user_instructions&amp;gt;&lt;/span&gt;
    {{USER_INSTRUCTIONS}}
  &lt;span class="nt"&gt;&amp;lt;/user_instructions&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/task&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With XML prompting, the model does not have to infer the purpose of the specific parts of the prompt, leading to desirable and structured answers. The model refers to the specific way of input and output and provides the result in a similar way (where formatting practice constraints are necessary)&lt;/p&gt;

&lt;p&gt;Few extra tips:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Using descriptive and consistent tags across your prompt is a good practice&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can use nested tags when the content has a natural hierarchy (for example  can have )&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This can help speed up a lagging process in a sustainable and structured way. &lt;/p&gt;

&lt;p&gt;Hope you enjoyed reading and learnt about the best practices to prompt your LLMs and SLMs! :)&lt;/p&gt;

</description>
      <category>ai</category>
      <category>rag</category>
      <category>mcp</category>
      <category>llm</category>
    </item>
  </channel>
</rss>
