今日已更新 34 条资讯 | 累计 29487 条内容
关于我们

XML Tagging in Prompts: The Secret to Getting Better Output from Claude and GPT

Maryam Saba 2026年08月04日 04:39 2 次阅读 来源:Dev.to

XML Tagging in Prompts: The Secret to Getting Better Output from Claude and GPT A simple structuring trick that turns messy, unpredictable LLM outputs into clean, reliable ones. If you've spent any time writing prompts for Claude, GPT, or any other large language model, you've probably hit this wall: your prompt works fine for a simple ask, but the moment you pack in multiple instructions — some context, a few examples, formatting rules, and the actual task — the model starts mixing things up. It answers the wrong part of the question. It ignores your formatting instructions. It treats your example output as part of the actual task. The fix is almost embarrassingly simple: wrap your prompt sections in XML tags. Why XML Tags Work So Well LLMs are trained on enormous amounts of code, documentation, and markup. XML (and HTML) syntax is deeply embedded in that training data, which means models are very good at recognizing where one tagged section ends and another begins. Unlike plain paragraphs — where the boundary between "here's my context" and "here's my instruction" is fuzzy — a tag creates an unambiguous boundary. Anthropic actually recommends this explicitly for Claude: wrapping distinct parts of a prompt (instructions, context, examples, output format) in tags like <instructions> , <context> , <example> , and <output_format> measurably improves consistency, especially in longer or more complex prompts. Think of it like the difference between handing someone a wall of text versus handing them a form with labeled fields. Both contain the same information, but one is far easier to parse correctly — for a human, and for a model. A Before-and-After Example Without tags: Summarize the article below in 3 bullet points. Keep it under 50 words. Use a neutral tone. Here's an example of the style I want: "- Company X raised $10M in Series A funding." Now here's the article: [long article text] The model has to guess where the instructions end and the article begins — and wi

本文内容来源于互联网,版权归原作者所有
查看原文