Rephrase LogoRephrase Logo
FeaturesHow it WorksPricingGalleryDocsBlog
Rephrase LogoRephrase Logo

Better prompts. One click. In any app. Save 30-60 minutes a day on prompt iterations.

Rephrase on Product HuntRephrase on Product Hunt

Product

  • Features
  • Pricing
  • Download for macOS

Use Cases

  • AI Creators
  • Researchers
  • Developers
  • Image to Prompt

Resources

  • Documentation
  • About

Legal

  • Privacy
  • Terms
  • Refund Policy

Ask AI about Rephrase

ChatGPTClaudePerplexity

© 2026 Rephrase-it. All rights reserved.

Available for macOS 13.0+

All product names, logos, and trademarks are property of their respective owners. Rephrase is not affiliated with or endorsed by any of the companies mentioned.

Back to blog
Prompt Tips•Feb 19, 2026•9 min

How to Structure Prompts with XML and Markdown Tags (So They Don't Rot in Prod)

A practical way to make prompts readable, testable, and harder to break using XML-style sections plus Markdown fences.

How to Structure Prompts with XML and Markdown Tags (So They Don't Rot in Prod)

Most prompts fail for boring reasons.

Not because "the model got worse." Not because you didn't say "please." They fail because they're unstructured. Instructions leak into data. Examples blur into requirements. The model guesses what's a rule versus what's just context. Then you ship it, someone pastes a weird log file, and everything quietly melts.

When I want prompts that survive copy-paste, refactors, and "one more requirement," I lean on two lightweight tools: XML-style tags for semantic sections, and Markdown fences for hard boundaries. Think of it as giving your prompt an API surface.

What's interesting is that this isn't just style. Research and practitioner reports keep circling the same core idea: representation and structure change how reliably a model can "find" what it needs in the input, and long prompts can degrade performance even when the information is technically present. So structure isn't decoration; it's retrieval help for the model's attention mechanism. Giabbanelli calls out how prompt complexity and length can backfire, and why being selective and explicit matters [1]. He also highlights that representation choices (lists vs adjacency vs tag-based/XML-like representations) can materially change outcomes even when the underlying information is equivalent [1]. That's the door XML tags walk through.


XML tags: make the prompt parseable (for the model and for you)

When I say "XML," I don't mean you need strict schemas or valid XML. I mean you use angle-bracket section markers as a simple, regular pattern:

  • They create named compartments.
  • They reduce ambiguity when you inject user content.
  • They make it easier to template prompts and test them.

The biggest win is that you stop writing prompts like essays and start writing them like structured inputs: instructions, constraints, data, and output format are explicitly separated. This aligns with the broader engineering advice in the literature: prompt quality often comes from explicit task definitions, clear expected output formats, and avoiding prompts that blur instructions with examples and counterexamples [1].

Here's the rule I follow: every prompt gets an explicit, repeatable "shape." The model shouldn't have to infer where the rules stop and the raw input begins.

A simple skeleton:

<role>
You are a {persona}. Your job is to {job}.
</role>

<task>
{one-sentence task statement}
</task>

<constraints>
{hard rules, e.g. "don't do X", "must include Y"}
</constraints>

<input>
{user-provided content goes here}
</input>

<output_format>
{exact formatting contract}
</output_format>

Notice what's missing: vibes. No meandering paragraphs. No "here's some context" mixed into rules.

Also, don't underestimate closing tags. Even if the model doesn't "parse XML," the symmetry helps it keep track of boundaries. Practitioners routinely report that explicit sectioning reduces drift and weird cross-contamination when prompts get large or modular [3].


Markdown fences: hard delimiters for messy payloads

XML tags are great for sections you control. But user payloads are chaotic: stack traces, CSVs, SQL, HTML, configs. This is where Markdown fences shine.

Markdown code blocks (triple backticks) are a blunt tool: they say "treat what's inside as literal." That matters for two reasons.

First, it reduces accidental instruction following. If someone pastes text like "Ignore previous instructions," you want it to stay inside <input> as data, not become the new boss.

Second, it reduces the model's temptation to "reformat" the payload before reasoning about it. You want faithful handling first, interpretation second.

So I often do this hybrid pattern:

<input>
```log
...raw logs here...
```

You get semantic sectioning from XML and literal boundaries from Markdown.

Giabbanelli's guide is blunt about a related failure mode: longer prompts can degrade performance even when retrieval is perfect, so being selective and clearly separating components (instructions vs examples vs data) becomes a practical necessity, not pedantry [1]. Fences are one cheap way to keep those components from blurring.


The real trick: treat prompts like interfaces, not messages

If you take one idea from this, make it this: the prompt is an interface contract.

When prompts are "messages," people keep adding sentences. When prompts are "interfaces," people add fields.

That shift has second-order benefits:

You can version prompts. You can diff them. You can A/B test variants that change one section at a time. You can even write little validators ("does this prompt include <output_format>?") before it ever hits a model.

Research folks talk about reproducibility and modularity: prompts should be communicable, interpretable artifacts, not mysterious blobs you paste into a paper appendix [1]. In real product work, the same argument applies: if nobody can explain why the prompt is shaped the way it is, you're one teammate away from breaking it.


Practical examples you can copy-paste

Here are three templates I've actually seen hold up in real workflows.

Example 1: "Bento box" debugging prompt (XML + Markdown)

This pattern shows up a lot in community practice: separate tasks from raw payloads, and make the model summarize state before acting [4]. I like it because it prevents the common failure where the model starts "fixing" your config file instead of first identifying what's wrong.

<role>
You are a senior SRE. You are precise and you never guess.
</role>

<task>
Diagnose the issue and propose a minimal fix plan.
</task>

<constraints>
- If you are missing info, ask up to 3 targeted questions.
- Don't invent commands I ran.
- Don't rewrite configs unless I ask.
</constraints>

<context>
<infrastructure>
```yaml
proxmox: true
firewall: pfsense
vlans:
  - id: 10
    name: mgmt
  - id: 20
    name: services
```text PASTE CLI OUTPUT HERE ``` ```conf PASTE CONFIG HERE ``` Return: 1) What's most likely broken (1 paragraph) 2) Evidence from the data (quote exact lines) 3) Fix steps (numbered) 4) Verification commands (numbered) ```

Example 2: Safe variable injection template for business writing

This mirrors the "prompts as functions" mindset from the community: isolate variables to reduce leakage [3]. It's not academic proof, but it's a solid operational heuristic.

<role>
You are a product marketing writer. You are crisp and specific.
</role>

<task>
Write a landing page section.
</task>

<inputs>
<product_name>{PRODUCT_NAME}</product_name>
<target_user>{TARGET_USER}</target_user>
<key_benefit>{KEY_BENEFIT}</key_benefit>
<proof_points>
```text
{PASTE BULLETS}
- Don't claim metrics not in proof_points. - Avoid hype words like "revolutionary" or "game-changing." Markdown only: - H2 headline - 2 short paragraphs - 3 bullet benefits ```

Example 3: Enforce structured output for parsing

Even with good structure, models sometimes add extra words. The Modeling & Simulation guide notes that "even when an LLM is supposed to simply state an option," it may wrap it in fluff, and you may need parsing or stronger output constraints [1]. The lowest-friction fix is to make the output format painfully explicit.

<task>
Classify the support ticket.
</task>

<input>
```text
{TICKET_TEXT}
Return exactly this XML and nothing else: {one of: billing|bug|how_to|account|other} {one of: low|medium|high} {true|false} ```

Now you can parse it deterministically, and you'll notice quickly when the model violates the contract.


The catch: structure doesn't replace evaluation

One risk with structured prompts is you start trusting them because they look "engineered." Don't.

Giabbanelli emphasizes that prompt quality doesn't necessarily improve with length, and that empirical evaluation is still necessary because interactions between representation, task, and model can be unintuitive [1]. Structure reduces a class of failures, but it doesn't guarantee correctness.

My workflow is: lock the shape, then iterate inside the sections. If you keep changing both the content and the structure, you can't tell what helped.


Closing thought

If your prompt is important, don't write it like a chat.

Write it like a config file.

Use XML tags to name intent. Use Markdown fences to quarantine payloads. Then treat the whole thing like an interface you can version, diff, and test. You'll get fewer weird failures, and when something does break, you'll actually know where to look.


References

Documentation & Research

  1. A Guide to Large Language Models in Modeling and Simulation: From Core Techniques to Critical Challenges - arXiv cs.AI - https://arxiv.org/abs/2602.05883
  2. GRP-Obliteration: Unaligning LLMs With a Single Unlabeled Prompt - arXiv cs.AI - https://arxiv.org/abs/2602.06258

Community Examples

  1. The "Variable Injection" Framework: How to build prompts that act like software. - r/PromptEngineering - https://www.reddit.com/r/PromptEngineering/comments/1qwmx94/the_variable_injection_framework_how_to_build/
  2. Advanced Prompt Engineering in 2026? - r/PromptEngineering - https://www.reddit.com/r/PromptEngineering/comments/1r8yl5j/advanced_prompt_engineering_in_2026/
Ilia Ilinskii
Ilia Ilinskii

Founder of Rephrase-it. Building tools to help humans communicate with AI.

Related Articles

How to Write AI Prompts for Newsletters
prompt tips•7 min read

How to Write AI Prompts for Newsletters

Learn how to write AI prompts for newsletter subject lines, hooks, and retention sequences with better structure and examples. Try free.

How to Prompt AI for Better Software Tests
prompt tips•8 min read

How to Prompt AI for Better Software Tests

Learn how to write AI testing prompts for unit tests, E2E flows, and test data generation with better coverage and fewer retries. Try free.

How to Write CLAUDE.md Prompts
prompt tips•7 min read

How to Write CLAUDE.md Prompts

Learn how to write CLAUDE.md prompts that give Claude Code lasting project memory, better constraints, and fewer repeats. See examples inside.

How to Prompt AI for Ethical Exam Prep
prompt tips•8 min read

How to Prompt AI for Ethical Exam Prep

Learn how to use AI for exam prep without cheating by writing ethical prompts that build understanding, not shortcuts. See examples inside.

Want to improve your prompts instantly?

On this page

  • XML tags: make the prompt parseable (for the model and for you)
  • Markdown fences: hard delimiters for messy payloads
  • The real trick: treat prompts like interfaces, not messages
  • Practical examples you can copy-paste
  • Example 1: "Bento box" debugging prompt (XML + Markdown)
  • Example 2: Safe variable injection template for business writing
  • Example 3: Enforce structured output for parsing
  • The catch: structure doesn't replace evaluation
  • Closing thought
  • References