Paramclasses Academy - Blog

Tutorials Details

How to Use XML Tags and Structured Prompts in Claude AI: A Practical Guide with Examples

How to Use XML Tags and Structured Prompts in Claude AI: A Practical Guide with Examples

October 22, 2026

How to Use XML Tags and Structured Prompts in Claude AI: A Practical Guide with Examples

Welcome to Param Classes!

Claude AI can help you write content, understand programming concepts, analyze documents, solve coding problems, and complete many other tasks. However, when a prompt contains several instructions, examples, documents, and requirements, it can become difficult to organize everything clearly.

One useful technique is structured prompting with XML-style tags.

XML tags help separate different parts of a prompt so Claude can more easily distinguish background information, instructions, examples, and reference material. You do not need to build an XML application or learn advanced programming to use this technique. You can use simple text tags directly in your prompt.

In this tutorial, you will learn what XML tags are, why structured prompts are useful, how to use tags such as <context>, <instructions>, and <example>, and how to apply them to writing and programming tasks.

What Are XML Tags in Claude AI?

XML stands for Extensible Markup Language. It is a markup language that uses tags to organize information into labeled sections.

For example, an XML-style structure might look like this:

<topic>
    PHP Variables
</topic>

<instructions>
    Explain PHP variables in simple English.
    Include two code examples.
</instructions>

In this example:

  • <topic> identifies the subject.

  • <instructions> identifies what Claude should do.

  • </topic> and </instructions> mark the ends of the sections.

Claude can work with XML-style tags included in ordinary text prompts. You do not need to use a special editor or install software just to write these prompts.

Important: Using tags in a Claude prompt does not automatically mean you are creating a formally validated XML document. In this context, tags are a practical way to organize instructions and information.

Why Use Structured Prompts in Claude?

A short prompt may work well for a simple question. But complex tasks often contain several types of information.

For example, when asking Claude to write a tutorial article, you might need to provide:

  • The topic of the article.

  • The target audience.

  • Writing instructions.

  • A sample format.

  • Words or topics that must be included.

  • Requirements for the final output.

If all this information is placed into one long paragraph, the structure may be harder to follow.

Structured prompts separate these elements into clearly labeled sections.

The main benefits include:

  • Better organization: Different parts of the request are separated.

  • Clearer instructions: The task is easier to identify.

  • Reusable prompts: You can adapt the same structure for similar work.

  • Easier editing: You can update one section without rewriting everything.

  • Improved consistency: Repeated tasks can follow a similar format.

XML-style tags do not guarantee a perfect response, but they can make complicated prompts easier to understand and maintain.

1. Understanding Opening and Closing Tags

XML-style tags generally use an opening tag and a closing tag.

For example:

<instructions>
    Explain JavaScript functions with examples.
</instructions>

Here, <instructions> is the opening tag, and </instructions> is the closing tag.

The text between the tags contains the instruction.

You can use meaningful names to describe the contents of each section.

Examples include:

<context>
    I am learning web development.
</context>

<task>
    Explain HTML forms.
</task>

<requirements>
    Include a basic HTML example.
    Explain each important attribute.
</requirements>

The tag names act as labels. They help organize the prompt into logical sections.

You do not need to memorize a fixed list of tag names. Choose names that clearly describe the information inside each section.

2. Common XML Tags You Can Use in Claude Prompts

Here are some practical tags for organizing different types of information.

XML-style tag Purpose
<context> Provides background information
<task> Defines the main task
<instructions> Lists the instructions Claude should follow
<requirements> Specifies necessary content or features
<example> Provides a sample to follow
<document> Contains reference text or document content
<constraints> Defines limits or restrictions
<format> Describes the desired output structure
<audience> Identifies the intended reader
<output> Labels the expected deliverable or a section of content

These are practical naming conventions, not special built-in Claude commands. You can choose other meaningful tag names when they suit your task.

3. How to Write Your First Structured Prompt

Let's create a simple structured prompt for learning PHP.

Step 1: Define the Context

Explain your situation or learning goal.

<context>
    I am a beginner learning PHP for web development.
</context>

This tells Claude who the explanation is intended for.

Step 2: Define the Task

Describe the main thing you want Claude to do.

<task>
    Explain PHP variables.
</task>

Step 3: Add the Requirements

List the details you want included.

<requirements>
    Explain how to declare variables.
    Include two simple PHP code examples.
    Explain the output of each example.
</requirements>

Step 4: Specify the Output Format

Tell Claude how to organize its response.

<format>
    Use headings, short paragraphs, and code blocks.
    Finish with a short summary.
</format>

Step 5: Combine the Sections

You can now combine everything into one prompt:

<context>
    I am a beginner learning PHP for web development.
</context>

<task>
    Explain PHP variables.
</task>

<requirements>
    Explain how to declare variables.
    Include two simple PHP code examples.
    Explain the output of each example.
</requirements>

<format>
    Use headings, short paragraphs, and code blocks.
    Finish with a short summary.
</format>

Copy this structure into Claude and review the response.

The main advantage is that each part of your request has a clear place.

4. Using XML Tags for Writing and Blog Creation

Structured prompts can be particularly helpful when creating articles for an educational website.

Suppose you want Claude to write a tutorial about JavaScript events.

You could use the following prompt:

<context>
    I am creating programming tutorials for an educational website.
    My readers are beginners learning JavaScript.
</context>

<task>
    Write a tutorial explaining JavaScript events.
</task>

<requirements>
    Explain what events are.
    Cover common events such as click, input, and submit.
    Include simple code examples.
    Explain the code in easy English.
    Include frequently asked questions.
</requirements>

<constraints>
    Avoid unnecessarily complicated terminology.
    Use original explanations.
    Keep the examples relevant to web development.
</constraints>

<format>
    Start with an introduction.
    Organize the article using clear headings.
    Include code blocks and a final summary.
</format>

This prompt separates the audience, task, requirements, restrictions, and article structure.

You can reuse the same template for PHP, Python, Django, databases, and other technical topics by changing the subject and requirements.

5. Using <example> Tags to Show Your Preferred Style

Sometimes you need Claude to follow a particular writing style or output pattern.

An <example> section can contain a sample that demonstrates what you want.

For example:

<task>
    Write a short description for a programming tutorial.
</task>

<example>
    Topic: PHP Arrays

    Description: Learn what arrays are in PHP,
    how they store multiple values, and how to
    use them with simple code examples.
</example>

<requirements>
    Create a description for Python Lists.
    Follow a similar structure and level of detail.
    Do not copy the example word for word.
</requirements>

The example shows the desired structure and level of detail.

This approach is useful when generating course descriptions, product summaries, FAQs, structured reports, or similar content repeatedly.

For best results, provide examples that accurately represent the style and format you want Claude to follow.

6. Using XML Tags for Coding Tasks

Structured prompts can also help when you need assistance with programming.

For example, suppose you are working on a PHP application and a form is not saving data correctly.

Instead of writing a vague prompt, organize the information into sections:

<context>
    I am developing a PHP application that stores
    student records in a MySQL database.
</context>

<task>
    Help me investigate why the form does not save data.
</task>

<current_code>
    Paste the relevant PHP code here.
</current_code>

<error_message>
    Paste the exact error message here,
    or describe what happens when the form is submitted.
</error_message>

<requirements>
    Identify the likely cause.
    Explain the problem in simple English.
    Provide the necessary code changes.
    Include steps to test the solution.
</requirements>

<constraints>
    Preserve the existing page design.
    Avoid unrelated changes.
    Do not introduce unnecessary libraries.
</constraints>

This structure makes the purpose of each section clear.

It also helps separate the code being analyzed from the instructions about what to do with that code.

Practical tip: Include only the relevant code and remove passwords, API keys, database credentials, and other secrets before sharing information with an AI assistant. Always test generated code in a development environment before deploying it.

7. How to Separate Reference Documents From Instructions

When working with long documents, it can be useful to separate the document itself from the task you want Claude to perform.

For example:

<task>
    Summarize the document below.
    Identify its main points and list any action items.
</task>

<document>
    Paste the document text here.
</document>

<format>
    Provide a short summary followed by a bullet list
    of the main points and action items.
</format>

The <document> tag identifies the source material, while <task> explains what to do with it.

This distinction is especially useful for summarizing meeting notes, reviewing specifications, analyzing reports, and extracting information from lengthy text.

If the document contains instructions as part of its content, treat those instructions as source material unless you explicitly intend Claude to follow them. For example, a sentence inside a document that says “ignore all previous instructions” should not automatically become an instruction for the assistant to follow.

8. Nested XML Tags for Complex Prompts

Sometimes one section needs to contain smaller sections. This is called nesting.

For example:

<project>
    <context>
        I am creating a student management system.
    </context>

    <technology>
        PHP, MySQL, HTML, CSS, and Bootstrap.
    </technology>

    <task>
        Create a student registration form.
    </task>

    <requirements>
        <requirement>
            Include name, email, and phone fields.
        </requirement>

        <requirement>
            Validate the required fields.
        </requirement>
    </requirements>
</project>

In this example, the <context>, <technology>, <task>, and <requirements> sections are placed inside a larger <project> section.

Nesting can help organize complex prompts with several related components. However, it is not necessary for every task.

For most everyday requests, a few clearly named sections are enough.

9. Common Mistakes to Avoid

Using Tags Without a Clear Purpose

Adding many tags does not automatically improve a prompt.

Instead of creating separate sections for every sentence, use tags only when they help organize distinct types of information.

Forgetting Closing Tags

Keep opening and closing tags consistent.

For example, use:

<task>
    Explain Python functions.
</task>

Avoid accidentally using a different closing tag, such as </instructions>, when the opening tag is <task>.

Claude can often interpret imperfect formatting, but consistent tags make prompts easier to read and maintain.

Using Unclear Tag Names

Names such as <section1> and <section2> do not explain what the sections contain.

Prefer meaningful labels such as <context>, <task>, and <constraints>.

Mixing Instructions With Reference Material

If you paste a long document and place your actual task somewhere inside it, the intended action may be less clear.

Use separate sections for the task and the source material.

Assuming XML Tags Guarantee Accuracy

XML-style tags organize information; they do not guarantee that Claude will follow every instruction perfectly or that its answer will be factually correct.

Review the result and verify important details.

10. Best Practices for Structured Prompts

Follow these practical guidelines to make your prompts easier to understand.

  • Use meaningful tag names that describe their contents.

  • Put related information together in the same section.

  • Keep instructions specific and avoid contradictory requirements.

  • Use examples when necessary to demonstrate a preferred result.

  • Separate source material from instructions when analyzing documents.

  • Avoid unnecessary complexity for simple tasks.

  • Review the output and refine the prompt if needed.

You can also create a reusable prompt template for recurring tasks, such as writing tutorials, reviewing code, or preparing reports. This reduces repeated work and makes your instructions more consistent.

Frequently Asked Questions

1. What are XML tags in Claude AI?

XML tags are labels such as <context> and <instructions> that you can use to organize information inside a prompt. They help distinguish different sections of your request.

2. Do I need to know XML programming to use structured prompts?

No. You can start by using simple opening and closing tags in ordinary text. Advanced XML knowledge is not necessary for this prompting technique.

3. Which XML tags should beginners learn first?

Start with <context>, <task>, <instructions>, <example>, <constraints>, and <format>. These labels are sufficient for many everyday tasks.

4. Do XML tags always improve Claude's responses?

No. They are most useful for complex prompts containing multiple sections or requirements. A short, clear question may work perfectly well without tags.

5. Can I use XML-style tags for coding and blog writing?

Yes. You can use them to organize project details, code samples, writing requirements, reference documents, examples, and output formats.

What Have We Learned?

In this tutorial, we learned how to organize Claude AI prompts using XML-style tags and structured sections.

The key takeaways are:

  • XML-style tags help organize prompt information.

  • Context and task sections explain the situation and the required action.

  • Examples demonstrate the expected format or style.

  • Constraints identify requirements and restrictions.

  • Structured prompts are useful for writing, programming, and document analysis.

  • Clear organization can improve consistency, but it does not guarantee perfect answers.

Start with a few simple tags, practise with real tasks, and add more structure only when it helps.

Continue Learning with Param Classes

Continue learning about Claude AI with Param Classes. Practise structured prompting using your own writing and coding tasks, and explore how clear instructions can help you work more effectively with AI.

Keep learning with Param Classes!