Build

XML Tags vs. Markdown in LLM Prompts: When to Use Each

Choose prompt boundaries for readability, nested data, and the model you actually deploy.

Published
Read time4 min read
Side-by-side conceptual comparison of a prompt structured with Markdown headings and one structured with XML-style tags.

Use Markdown headings for a readable default and XML-style tags when explicit content boundaries or nested structure help. Combine them when each does a different job—for example, Markdown for top-level instructions and XML tags around a supplied document. There is no universal winner: OpenAI documents both as useful ways to mark logical boundaries, while Anthropic recommends descriptive XML tags for complex prompts. Test the format against your model and task rather than treating syntax as a performance guarantee.

What changes between Markdown and XML tags?#

Markdown uses familiar headings, lists, and emphasis to organize instructions. XML-style tags wrap a section in an explicit opening and closing marker. Both can make prompt parts easier to distinguish, but they are not a security boundary and do not replace clear instructions.

Comparison of equivalent prompt sections written with Markdown headings and XML-style tags.
Two ways to mark prompt structure; choose based on readability and boundary clarity.

Markdown example:

Markdown
## Task
Summarize the supplied document in three bullets.

## Context
The audience is a software engineering manager.

## Input
[DOCUMENT TEXT]

XML-style example:

XML
<task>
Summarize the supplied document in three bullets.
</task>

<context>
The audience is a software engineering manager.
</context>

<input>
[DOCUMENT TEXT]
</input>

These examples express the same intended organization. The choice is about how you want to express boundaries and maintain the prompt—not about choosing a magic syntax.

When Markdown is the better default#

Choose Markdown when the prompt is primarily a set of instructions that people need to read, review, and maintain.

  • Human-readable sections: headings like ## Task and ## Constraints are quick to scan in a code review.
  • Lists of requirements: bullets make independent rules easy to inspect and edit.
  • Simple prompt templates: a short task with a few sections may not benefit from additional opening and closing tags.
  • Documentation and collaboration: Markdown is widely used in repositories, issue trackers, and internal docs.

For example, a classification prompt with a clear task, a few decision rules, and a short output contract may be easiest to maintain as Markdown. Keep the structure proportional to the prompt; do not add headings simply to make a small instruction look more formal.

When XML-style tags are useful#

Use XML-style tags when the prompt contains multiple kinds of content that need explicit start and end boundaries, especially when some sections contain long or nested material.

XML
<instructions>
Summarize the source. Use only facts supported by it.
</instructions>

<source_document>
[UNTRUSTED DOCUMENT CONTENT]
</source_document>

<output_requirements>
Return three bullet points and identify any missing information.
</output_requirements>

This makes it easier to see where the source begins and ends. Anthropic recommends descriptive, consistent tag names and nesting tags when the content has a natural hierarchy. OpenAI's guidance also describes XML tags as a way to delineate supporting documents and context data. The benefits are organizational; tags alone do not neutralize malicious instructions inside a document or guarantee that the model will follow the intended boundaries.

XML-style tags are particularly useful when:

  • The prompt includes a long source document or several documents.
  • You need to distinguish instructions from quoted or user-provided content.
  • A section has a natural hierarchy, such as a collection of documents and each document's metadata.
  • You need clear boundaries around examples or variable input.

Use descriptive tag names that explain the content, such as <instructions>, <context>, <source_document>, and <output_requirements>. Consistency matters more than inventing a complicated tag vocabulary.

When to combine Markdown and XML#

You do not have to choose one format for every part of a prompt. A practical hybrid uses Markdown for the top-level outline and XML-style tags for data boundaries:

Markdown
## Task
Summarize the supplied source in three bullets. Do not add facts that are absent from the source.

## Source
<source_document>
[PASTE SOURCE TEXT HERE]
</source_document>

## Output format
Return exactly three bullets. If the source does not support a requested detail, say so.

The Markdown headings make the overall task easy to scan. The XML tags mark the beginning and end of the source content. Use a hybrid only when it adds clarity; duplicated layers of headings and tags can make a prompt harder to maintain.

A decision guide#

Practical starting points, not benchmark results.
Prompt situationPractical starting pointWhy
Short task with a few rulesMarkdownReadable without extra syntax
Long source documentXML tags around the source, with Markdown instructions if usefulMakes the source boundary explicit
Multiple related documentsNested XML-style tags plus concise top-level instructionsRepresents the hierarchy of inputs
Prompt maintained by a teamWhichever format is easiest to review consistentlyReviewability is a maintenance requirement
Model-specific workflowFollow the provider's current guidance, then evaluatePrompt behavior can differ across models and versions
Strict machine-readable outputUse the provider's supported structured-output feature when availablePrompt formatting alone is not schema enforcement

This is a starting guide, not a benchmark result. The table summarizes the cited providers' guidance and a practical maintainability recommendation; it does not claim that one syntax is more accurate across all models.

Formatting does not replace application safeguards#

A tagged input section can make a source boundary visible, but untrusted text may still contain instruction-like content. Do not rely on Markdown headings or XML tags as the only protection against prompt injection. Limit tool permissions, separate trusted instructions from untrusted data in the application design, validate outputs, and test realistic adversarial cases.

Likewise, if your application needs JSON or another strict output shape, defining it in Markdown or XML is not the same as enforcing a schema. Use a supported structured-output feature where available and validate the result in your application. OpenAI distinguishes JSON mode from Structured Outputs in its Structured Outputs guide.

Test the choice with your actual task#

Do not evaluate syntax in the abstract. Keep the task, input, model, and success criteria stable while you compare versions.

Write one baseline prompt using the format your team finds easiest to maintain.

Create an alternative that changes only the boundaries or section markup—not the underlying instructions.

Run both against representative normal, ambiguous, and edge-case inputs.

Score outputs against explicit criteria, such as required fields, factual support, correct refusal or fallback behavior, and downstream parseability.

Repeat on the model and deployment configuration you actually intend to use.

Keep the clearer or better-performing version, record the decision, and rerun the checks after meaningful changes.

If you already have prompt wording and only need to arrange it into Markdown headings, XML tags, or plain labels, use the Letinix Prompt Formatter. It organizes existing sections and can clean whitespace or quotation marks; it does not rewrite wording or prove that the resulting prompt is better.

Bottom line#

Start with Markdown for a readable outline. Add XML-style tags where long or nested content needs explicit boundaries. Combine them when the two formats have distinct jobs, and keep the result as simple as the task allows. The only reliable way to choose for a production workflow is to evaluate representative inputs against criteria that matter to your application.

References#

OpenAI, Prompt engineering. Guidance on message formatting with Markdown and XML tags.

Anthropic, Claude prompting best practices. Guidance on XML tags, descriptive names, and nested content.

OpenAI, Structured Outputs. Guidance on schema-constrained output and related limitations.

Muhammad Azlaan Zubair

Software Engineer and Researcher, writing about AI, developer tooling and automation.

Newsletter

New guides, comparisons and analysis, sent only when there is something worth your time.

  • New articles worth your time, not every link we publish.
  • Tools and resources when they launch.
  • No spam, no selling your address. Unsubscribe anytime.

Get useful signal by email

We're building the list before the first issue. You'll get an email when the newsletter starts.