Skip to content
FeaturesPricingBlogDownload

← All posts

Markdown vs JSON vs XML in prompts: which format to use when

Use Markdown to organize prompt instructions, XML tags to wrap documents, and JSON for data the model returns. What OpenAI, Anthropic and Google advise.

Diagram card on a light background showing three prompt formats, Markdown, JSON and XML, each paired with what it suits

In the Markdown vs JSON vs XML question for prompts, each format has a different job. Use Markdown headings and lists to organize the instructions, XML tags to wrap documents and inputs whose start and end must be unambiguous, and JSON for data the model has to read or return as data, ideally enforced with the API's structured output feature. OpenAI, Anthropic and Google all describe some version of this split in their prompting guides, and none of them says one format wins everywhere.

Below is what each vendor's documentation actually says, when each format fits, and how to apply it to notes you paste into a prompt. The vendor guidance was checked in November 2026.

What do OpenAI, Anthropic and Google recommend?

Read side by side, the three guides agree more than they disagree.

Vendor guide Markdown XML tags JSON
OpenAI prompt engineering "Markdown headers and lists can be helpful to mark distinct sections of a prompt, and to communicate hierarchy to the model." "XML tags can help delineate where one piece of content (like a supporting document used for reference) begins and ends." The model can "return structured data in JSON format."
OpenAI GPT-4.1 prompting guide "We recommend starting here, and using markdown titles for major sections and subsections." "XML performed well in our long context testing." Well understood in coding contexts, but for long lists of documents "JSON performed particularly poorly."
Anthropic prompting guide Your prompt's style can carry over: "removing markdown from your prompt can reduce the volume of markdown in the output." "XML tags help Claude parse complex prompts unambiguously, especially when your prompt mixes instructions, context, examples, and variable inputs." Use JSON "to make schema requirements explicit" for structured state such as test results.
Google Gemini prompting strategies "XML-style tags (e.g., <context>, <task>) or Markdown headings are effective." Same line; Google adds: "Choose one format and use it consistently within a single prompt." Prompts can describe simple JSON, but use "structured output feature when specifying a more complex JSON Schema."

Two cautions about this table. The GPT-4.1 findings come from OpenAI's own testing of that model family and may not carry over to other models. And these guides change; read the current version before you build a large prompt around one sentence.

When should you use Markdown in a prompt?

Use Markdown for the parts a person writes and maintains: the role, the rules, the steps, the output requirements. Headings show which part is which, and lists keep rules separate so you can add or remove one without rewriting a paragraph.

# Role
You review pull request descriptions for a mobile app team.

# Rules
- Flag any change to payment code.
- Ignore formatting-only changes.

# Output
A short verdict line, then one bullet per problem found.

Markdown also costs little. Headings and bullets add a few characters each, so the text stays close to plain prose in length. If you want to measure that, how many tokens a Markdown file uses compares the same note in all three formats.

The limit shows up when you paste content that has its own Markdown. A pasted meeting note with ## Decisions sits at the same level as your prompt's ## Output, and nothing in the text says where the note ends. That is the job XML tags do better.

When are XML tags the better choice?

Use XML tags to wrap anything that comes from outside the prompt: documents, notes, transcripts, a user's message, examples. A closing tag marks the end of the content, which a Markdown heading cannot do.

Anthropic's guide shows a layout for several documents, with each one in its own tag and its source in a subtag:

<documents>
  <document index="1">
    <source>notes/2026-11-24-weekly.md</source>
    <document_content>
      ...the note, unchanged...
    </document_content>
  </document>
</documents>

Using only the documents above, list every decision and who owns it.

Points from the vendor guides that make tags work:

  • Consistent, descriptive names. Anthropic recommends using "consistent, descriptive tag names across your prompts" and nesting tags when content has a natural hierarchy.
  • Metadata as attributes. OpenAI notes that "XML attributes can also be used to define metadata about content in the prompt that can be referenced by your instructions," such as <doc id="3" title="Pricing">.
  • Refer to the tags by name. An instruction such as "quote the relevant lines in <quotes> tags" gives the answer a structure you can find in the response.
  • Documents near the top. Anthropic's guide says to place long documents above the query and instructions. OpenAI's GPT-4.1 guide suggests putting instructions both before and after a long context, or, if only once, above it.

The tags do not need to be valid XML documents. Nothing parses them; they are labels the model reads.

When does JSON belong in a prompt?

JSON fits in three places:

  1. The answer itself, when code will read it. If a program parses the response, describe the shape with a JSON Schema and turn on the API's structured output feature rather than asking politely in the prompt. OpenAI's docs say Structured Outputs "constrains completed, non-refusal model output to your supplied JSON Schema," and that plain JSON mode ensures valid JSON but not schema adherence. Anthropic's structured outputs take the schema in output_config.format and "constrain Claude's responses to follow a specific schema." Google recommends its structured output feature for complex schemas.
  2. Input that already is JSON. An API response or a config file is clearest in its own format, inside a fenced code block or a tag.
  3. State that has a schema. Anthropic's guide suggests JSON for tracking structured information such as test results across a long task, and free text for progress notes.

JSON is a weak choice for prose. A paragraph inside a JSON string needs escaped quotes and \n for line breaks, which makes it harder for you to read and edit. And OpenAI's long-context testing on GPT-4.1 found JSON worked poorly as a wrapper for many documents, while XML and a plain ID: | TITLE: | CONTENT: layout worked well.

Can you mix Markdown, XML and JSON in one prompt?

Yes, and most production prompts do. OpenAI's prompt engineering guide includes an example developer message built from Markdown sections with XML-tagged examples inside. The common pattern:

Part of the prompt Format
Instructions, rules, steps Markdown headings and lists
Pasted documents, notes, user input XML tags, with source as a subtag or attribute
Examples of input and output XML tags around each example
Required output for a program JSON Schema through structured outputs

Google's advice to "choose one format and use it consistently within a single prompt" reads as a warning against switching delimiters for the same kind of thing, such as ### for one document and <doc> for the next. Giving each role one format, as in the table, keeps that consistency.

Does the prompt format change the answer's format?

It can. Anthropic's guide says the formatting style of your prompt "might influence Claude's response style," and suggests matching the prompt to the output you want. A prompt full of bullets tends to get bullets back.

The guide's other advice on output format is to say what you want rather than what you do not want, for example "Your response should be composed of smoothly flowing prose paragraphs" instead of "Do not use markdown." If the answer will be read by a person, Markdown output is usually what you want anyway, since it renders in chat apps and pastes cleanly into a Markdown editor. Why Markdown is the language of AI covers why models default to it.

How does this apply to notes you paste as context?

Notes kept as .md files are already in the format the instructions part of a prompt uses, so all that is left is wrapping each one:

<note path="projects/launch-plan.md">
# Launch plan
- Owner: Mina
- Due: 2026-12-15
</note>

Keep the note unchanged inside the tag. Converting a note to JSON to make it look structured adds escaping and tokens and removes nothing the model needs. The path attribute lets you ask the model to cite which note an answer came from. For deciding which notes to include, see using Markdown notes as AI context, and for keeping reusable prompt files, a prompt library in Markdown.

Writing prompts and context files in Noteline

Noteline, which we make, is a Markdown editor, not an AI tool, and it does not send anything to a model. It is useful for the files around a prompt: open a folder (Cmd+O on a Mac, Ctrl+O on Windows and Linux) and your prompt files and notes are plain .md files in the sidebar. Fenced code blocks for JSON or XML examples get syntax highlighting, and Cmd+Shift+M (Ctrl+Shift+M on Windows and Linux) switches to source view so you see the exact characters you will paste. JSON and YAML files you open with Noteline appear in tabs next to your notes, though the sidebar lists only Markdown, text and PDF files. The iPhone, iPad and Android apps are free.

Start with one note. Keep the file.

Open a folder and write. Every note is a plain .md file, with no account to create.

Try desktop free for 14 days ↓Free on iPhone, iPad and Android →

Desktop: 14-day trial, then $9.99 once. Mobile apps: free. No account.

Keep reading

  • Markdown headings
  • Markdown code blocks
  • How to keep AI meeting notes as Markdown files you own
  • AI memory files: what your assistant should remember, kept in Markdown
  • An AI research workflow in Markdown: sources, summaries and claims

A Markdown note editor with everything you need

We’re listening

Tell us what you need or what gets in your way. If something isn’t working, write to us any time.

contact@noteline.io→

Product

  • Download
  • Pricing
  • Features
  • Changelog

Learn

  • Markdown syntax
  • Use cases
  • Blog

Compare

  • vs Obsidian
  • vs Notion

Support

  • Help
  • Support
  • Privacy
  • Terms

© 2026 Notelinecontact@noteline.io