1+ <xml_structuring_best_practices >
2+ <overview >
3+ XML tags help Claude parse prompts more accurately, leading to higher-quality outputs.
4+ This guide covers best practices for structuring mode instructions using XML.
5+ </overview >
6+
7+ <why_use_xml_tags >
8+ <benefit type =" clarity" >
9+ Clearly separate different parts of your instructions and ensure well-structured content
10+ </benefit >
11+ <benefit type =" accuracy" >
12+ Reduce errors caused by Claude misinterpreting parts of your instructions
13+ </benefit >
14+ <benefit type =" flexibility" >
15+ Easily find, add, remove, or modify parts of instructions without rewriting everything
16+ </benefit >
17+ <benefit type =" parseability" >
18+ Having Claude use XML tags in its output makes it easier to extract specific parts of responses
19+ </benefit >
20+ </why_use_xml_tags >
21+
22+ <core_principles >
23+ <principle name =" consistency" >
24+ <description >Use the same tag names throughout your instructions</description >
25+ <example >
26+ Always use <step > for workflow steps, not sometimes <action > or <task >
27+ </example >
28+ </principle >
29+
30+ <principle name =" semantic_naming" >
31+ <description >Tag names should clearly describe their content</description >
32+ <good_examples >
33+ <tag >detailed_steps</tag >
34+ <tag >error_handling</tag >
35+ <tag >validation_rules</tag >
36+ </good_examples >
37+ <bad_examples >
38+ <tag >stuff</tag >
39+ <tag >misc</tag >
40+ <tag >data1</tag >
41+ </bad_examples >
42+ </principle >
43+
44+ <principle name =" hierarchical_nesting" >
45+ <description >Nest tags to show relationships and structure</description >
46+ <example >
47+ <workflow >
48+ <phase name =" preparation" >
49+ <step >Gather requirements</step >
50+ <step >Validate inputs</step >
51+ </phase >
52+ <phase name =" execution" >
53+ <step >Process data</step >
54+ <step >Generate output</step >
55+ </phase >
56+ </workflow >
57+ </example >
58+ </principle >
59+ </core_principles >
60+
61+ <common_tag_patterns >
62+ <pattern name =" workflow_structure" >
63+ <usage >For step-by-step processes</usage >
64+ <template ><![CDATA[
65+ <workflow>
66+ <overview>High-level description</overview>
67+ <prerequisites>
68+ <prerequisite>Required condition 1</prerequisite>
69+ <prerequisite>Required condition 2</prerequisite>
70+ </prerequisites>
71+ <steps>
72+ <step number="1">
73+ <title>Step Title</title>
74+ <description>What this step accomplishes</description>
75+ <actions>
76+ <action>Specific action to take</action>
77+ </actions>
78+ <validation>How to verify success</validation>
79+ </step>
80+ </steps>
81+ </workflow>
82+ ]]> </template >
83+ </pattern >
84+
85+ <pattern name =" examples_structure" >
86+ <usage >For providing code examples and demonstrations</usage >
87+ <template ><![CDATA[
88+ <examples>
89+ <example name="descriptive_name">
90+ <description>What this example demonstrates</description>
91+ <context>When to use this approach</context>
92+ <code language="typescript">
93+ // Your code example here
94+ </code>
95+ <explanation>
96+ Key points about the implementation
97+ </explanation>
98+ </example>
99+ </examples>
100+ ]]> </template >
101+ </pattern >
102+
103+ <pattern name =" guidelines_structure" >
104+ <usage >For rules and best practices</usage >
105+ <template ><![CDATA[
106+ <guidelines category="category_name">
107+ <guideline priority="high">
108+ <rule>The specific rule or guideline</rule>
109+ <rationale>Why this is important</rationale>
110+ <exceptions>When this doesn't apply</exceptions>
111+ </guideline>
112+ </guidelines>
113+ ]]> </template >
114+ </pattern >
115+
116+ <pattern name =" tool_usage_structure" >
117+ <usage >For documenting how to use specific tools</usage >
118+ <template ><![CDATA[
119+ <tool_usage tool="tool_name">
120+ <purpose>What this tool accomplishes</purpose>
121+ <when_to_use>Specific scenarios for this tool</when_to_use>
122+ <syntax>
123+ <command>The exact command format</command>
124+ <parameters>
125+ <parameter name="param1" required="true">
126+ <description>What this parameter does</description>
127+ <type>string|number|boolean</type>
128+ <example>example_value</example>
129+ </parameter>
130+ </parameters>
131+ </syntax>
132+ <examples>
133+ <example scenario="common_use_case">
134+ <code>Actual usage example</code>
135+ <output>Expected output</output>
136+ </example>
137+ </examples>
138+ </tool_usage>
139+ ]]> </template >
140+ </pattern >
141+ </common_tag_patterns >
142+
143+ <formatting_guidelines >
144+ <guideline name =" indentation" >
145+ Use consistent indentation (2 or 4 spaces) for nested elements
146+ </guideline >
147+ <guideline name =" line_breaks" >
148+ Add line breaks between major sections for readability
149+ </guideline >
150+ <guideline name =" comments" >
151+ Use XML comments <!-- like this --> to explain complex sections
152+ </guideline >
153+ <guideline name =" cdata_sections" >
154+ Use CDATA for code blocks or content with special characters:
155+ <![CDATA[ <code><![CDATA[your code here]]> </code >]]>
156+ </guideline >
157+ <guideline name =" attributes_vs_elements" >
158+ Use attributes for metadata, elements for content:
159+ <example type =" good" >
160+ <step number =" 1" priority =" high" >
161+ <description >The actual step content</description >
162+ </step >
163+ </example >
164+ </guideline >
165+ </formatting_guidelines >
166+
167+ <anti_patterns >
168+ <anti_pattern name =" flat_structure" >
169+ <description >Avoid completely flat structures without hierarchy</description >
170+ <bad ><![CDATA[
171+ <instructions>
172+ <item1>Do this</item1>
173+ <item2>Then this</item2>
174+ <item3>Finally this</item3>
175+ </instructions>
176+ ]]> </bad >
177+ <good ><![CDATA[
178+ <instructions>
179+ <steps>
180+ <step order="1">Do this</step>
181+ <step order="2">Then this</step>
182+ <step order="3">Finally this</step>
183+ </steps>
184+ </instructions>
185+ ]]> </good >
186+ </anti_pattern >
187+
188+ <anti_pattern name =" inconsistent_naming" >
189+ <description >Don't mix naming conventions</description >
190+ <bad >
191+ Mixing camelCase, snake_case, and kebab-case in tag names
192+ </bad >
193+ <good >
194+ Pick one convention (preferably snake_case for XML) and stick to it
195+ </good >
196+ </anti_pattern >
197+
198+ <anti_pattern name =" overly_generic_tags" >
199+ <description >Avoid tags that don't convey meaning</description >
200+ <bad >data, info, stuff, thing, item</bad >
201+ <good >user_input, validation_result, error_message, configuration</good >
202+ </anti_pattern >
203+ </anti_patterns >
204+
205+ <integration_tips >
206+ <tip >
207+ Reference XML content in instructions:
208+ "Using the workflow defined in < workflow> tags..."
209+ </tip >
210+ <tip >
211+ Combine XML structure with other techniques like multishot prompting
212+ </tip >
213+ <tip >
214+ Use XML tags in expected outputs to make parsing easier
215+ </tip >
216+ <tip >
217+ Create reusable XML templates for common patterns
218+ </tip >
219+ </integration_tips >
220+ </xml_structuring_best_practices >
0 commit comments