Introduction: Why Model-Specific Formatting?

As you learned in the previous lesson, clear formatting helps language models understand your requests better. Now, let's take this a step further. Some language models, such as Claude, GPT, or Gemini, work best when you use a specific format in your prompt. This is called model-specific formatting.

Why does this matter? Each model is trained differently and may expect information in a specific structure. If you use the right format, you can get more accurate and helpful responses. In this lesson, I will show you how to adapt your prompts to fit the needs of different models, focusing on XML formatting for Claude as a key example.

What Is Model-Specific Formatting?

Model-specific formatting means shaping your prompt to match what a particular language model expects. For example, some models work well with plain text, while others prefer structured formats like XML or JSON.

If you use Claude, Anthropic recommends using XML tags to structure your prompt. Using the right format is like speaking the model's "native language." It makes your instructions clearer and helps the model give you better answers.

Basics of XML

XML (eXtensible Markup Language) is a way to organize information using custom tags. It looks similar to HTML, but you can create your own tag names to describe your data. Each piece of information is wrapped in a pair of tags: an opening tag (like <data>) and a closing tag (like </data>). This helps both humans and language models understand the structure and meaning of the information.

For example:

You can use any tag names that make sense for your task, such as <instructions>, <data>, or <summary>.

Example: XML Prompting for Claude

Consider the following case: you have some data and want to summarize key trends and insights from it. Let's build an XML-formatted prompt for Claude to handle this task.

Step 1: Start with Your Data

First, you need to provide the data you want the model to analyze. For example, you might have a large CSV file with survey responses. You can wrap this data in a <data> tag to make it clear where the data starts and ends.

Using the <data> tag, you tell Claude, "Everything inside here is the data you should look at."

Step 2: Add Your Instructions

Next, tell the model what you want it to do with the data. You can use an <instructions> tag for this.

By structuring your prompt this way, you help Claude understand precisely what information to use and what task to perform. The XML tags act as clear boundaries, reducing confusion and improving the quality of the response.

Key Point:
Always check the documentation for the model you are using. Some models, like Claude, perform better with structured formats like XML. Others, like GPT, might be more flexible with markdown.

Example: Nested XML Tags

XML tags can also be nested, meaning you can put tags inside other tags to show relationships between pieces of information. This is useful when you have complex data or want to clearly organize your instructions.

For example:

In this example, the <task> tag contains both <instructions> and <data>, and the <data> section contains multiple <response> entries. This structure clarifies which instructions go with which data and helps the model process your prompt more accurately.

Summary And What's Next

In this lesson, you learned how to adapt your prompt structure to fit the needs of different language models. You saw how using XML tags for Claude can simplify your instructions and data, leading to better results.

Next, you'll get to practice creating and adapting prompts for different models. This will help you become more comfortable with model-specific formatting and improve the quality of your interactions with language models.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal