Skip to main content

The Art of Prompt Formatting and Delimiters

"The difference between a good prompt and a great prompt often lies not in what you say, but how you say it."

Introduction

Imagine handing a brilliant but disorganized assistant a messy pile of notes and asking them to write a detailed report. They might get the job done, but the result would likely be confusing and unstructured. Now, imagine giving that same assistant a neatly organized binder with clear sections, labeled tabs, and highlighted instructions. The difference in output would be night and day.

This is precisely the role of formatting and delimiters in prompt engineering. In the world of LLMs, the way you structure and present information is just as important as the information itself. This article dives into the art and science of prompt formatting, showing you how to use simple structural tools to gain precise control over your model's output, enhance clarity, and prevent common errors.

Why Formatting is the Unsung Hero of Prompt Engineering

At first glance, formatting might seem like a trivial detail. After all, aren't LLMs smart enough to understand a block of text? While they are incredibly capable, they are not mind-readers. LLMs are systems that thrive on structure. Clear formatting acts as a blueprint, guiding the model's attention and helping it distinguish between different parts of your request—instructions, examples, context, and questions.

Think of it this way:

  • Instructions are the "what to do."
  • Context is the "what you need to know."
  • Examples are the "how to do it."
  • Input Data is the "what to do it with."

Without clear separation, these elements can bleed into one another, leading to confused and unpredictable responses.

The Power of Delimiters

Delimiters are special characters or strings that create boundaries in your prompt. They act like fences, clearly sectioning off different parts of the text. This is one of the most powerful and easy-to-implement techniques for improving prompt reliability.

Common delimiters include:

  • Triple backticks: ```
  • Triple quotes: """
  • XML tags: <example>, </example>
  • Dashes or asterisks: ---, ***
  • Section titles: ## Instructions ##

Here’s a simple example of how delimiters can transform a prompt.

❌ Unformatted Prompt:

Translate the following text to French. The text is "Hello, how are you?".

✅ Delimited Prompt:

Translate the following text to French.

Text to translate:
"""
Hello, how are you?
"""

The second prompt is far less ambiguous. The model knows exactly which part of the prompt is the instruction and which part is the data to operate on.

Practical Formatting Techniques and When to Use Them

Let's explore some of the most effective formatting techniques and the scenarios where they shine.

1. Using XML Tags for Complex Inputs

XML tags are a robust way to structure complex prompts, especially when you have multiple distinct pieces of information. They are highly effective because they are a common data format that models have seen extensively during training.

Scenario: You need to summarize a customer review and extract key information.

You are a helpful assistant. Your task is to process a customer review.
First, summarize the review in a single sentence.
Second, extract the product name and the customer's sentiment (positive, negative, or neutral).

<review>
I recently purchased the "Starlight Pro" camera, and I'm absolutely blown away!
The picture quality is stunning, especially in low light.
My only complaint is that the battery life could be a bit better, but overall, I'm thrilled with my purchase.
</review>

Please provide the output in a JSON format.

Why it works: The <review> tags create a clear, isolated block of text for the model to process. This prevents the model from getting confused and trying to summarize its own instructions.

2. Triple Backticks for Code and Technical Inputs

When working with code, file contents, or any text that might contain special characters, triple backticks are the gold standard. They signal to the model that the enclosed text should be treated as a literal block.

Scenario: You want the model to debug a piece of Python code.

Please analyze the following Python code for errors and suggest a fix.

```python
def calculate_average(numbers):
total = sum(numbers)
return total / len(numbers)

my_list = [1, 2, 3, "4"]
print(calculate_average(my_list))

Key Insight: Using ```python not only delimits the code but also provides a hint about the language, which can help the model provide more accurate syntax highlighting and analysis.

3. Markdown for Structuring and Emphasis

Markdown is a powerful tool for creating a visual hierarchy in your prompts. You can use headings, bold text, and lists to guide the model's attention to the most important parts of your request.

Scenario: You're creating a complex prompt with multiple instructions and constraints.

# Task: Generate a marketing email

## Instructions:
1. Write an email to a customer who has abandoned their shopping cart.
2. The email should be friendly and persuasive, not pushy.
3. **Crucially, offer a 10% discount code: `COMEBACK10`**.

## Customer Cart Contents:
- 1x "The Innovator's Toolkit" (Book)
- 1x "Productivity Planner" (Stationery)

## Tone:
Empathetic and helpful.

Why it works: The markdown structure helps the model process the request in a structured way. The bolding of the discount code increases the likelihood that the model will include it in the final output.

Common Pitfalls and How to Avoid Them

While formatting is powerful, it's not foolproof. Here are some common mistakes to watch out for.

1. Inconsistent Formatting If you use different delimiters or formatting styles within the same prompt, you can confuse the model. Stick to a consistent style throughout your request.

2. Overly Complex Structures While structure is good, a prompt that is too deeply nested or uses obscure formatting can be counterproductive. Aim for clarity and simplicity.

3. Delimiter Collisions Be careful that the delimiters you choose do not appear naturally in your input text. For example, if you are processing text that contains a lot of triple backticks, you should choose a different delimiter, like XML tags.

Try This Yourself

Ready to see the power of formatting in action?

  1. Start with a messy prompt. Take a complex task (e.g., "Write a blog post about the benefits of remote work, including a section on challenges and a conclusion that summarizes the key points") and write it as a single block of text.
  2. Run the prompt and observe the output.
  3. Refine the prompt with formatting. Now, rewrite the prompt using the techniques we've discussed. Use headings for each section, delimiters for any source text, and bolding for key instructions.
  4. Compare the results. Notice the difference in the structure, coherence, and quality of the output.

Key Takeaways

  • Structure is not optional: Clear formatting is one of the most effective ways to improve the reliability and quality of LLM responses.
  • Delimiters are your best friend: Use them to create clear boundaries between instructions, context, and input data.
  • Choose the right tool for the job: Use XML tags for complex data, triple backticks for code, and markdown for visual hierarchy.
  • Consistency is key: A consistent formatting style helps the model understand your intent.

What's Next?

Now that you've mastered the art of formatting individual prompts, you're ready to take the next step: structuring conversations. In the next article, we'll explore the difference between system messages and user messages, and how to use them to create powerful, stateful interactions with LLMs.

Quick Reference

Essential Delimiters:

  • ``` (Triple Backticks): Best for code, technical inputs, and literal text blocks.
  • """ (Triple Quotes): A good general-purpose delimiter for text.
  • <tag></tag> (XML Tags): Excellent for structuring complex, multi-part inputs.
  • --- or ***: Useful for creating simple visual separations.

When to Use Formatting:

  • When your prompt has multiple components (instructions, context, data).
  • When you need to process code or technical text.
  • When you want to guide the model's attention to specific details.
  • When your prompts are failing due to ambiguity.

Common Pitfalls:

  • Inconsistent formatting: Confuses the model.
  • Over-engineering: Keep it as simple as possible, but no simpler.
  • Delimiter collision: Ensure your delimiters don't appear in the input text.

By mastering the structure of your prompts, you unlock a new level of precision and control, turning your instructions into a clear blueprint for success.