Delimiters and Markers for Parsing
What you'll learn: How to make LLM outputs easy to parse programmatically by wrapping content in delimiters and markers.
The Problem with Raw Text
When you prompt an LLM and get back a response, you often need to extract specific pieces of information programmatically. Without structure, parsing free-form text is error-prone and fragile. You might ask for a title and description, but how do you reliably split them apart?
Using Delimiters
Delimiters are special characters or strings that mark boundaries in the output. Think of them like bookends on a shelf—they show where one section ends and another begins.
Common delimiter patterns:
- Triple backticks:
``` - XML-style tags:
<title>...</title> - Special markers:
###,---,===
Example prompt instruction:
Please provide a title and description.
Format your response as:
TITLE: [your title here]
DESCRIPTION: [your description here]
Now you can split on "TITLE:" and "DESCRIPTION:" reliably.
XML Tags for Nested Structure
XML-style tags are particularly robust because they're self-contained and nest cleanly:
Return your analysis in this format:
<analysis>
<summary>Brief summary here</summary>
<sentiment>positive/negative/neutral</sentiment>
</analysis>
You can then parse with simple string methods or XML parsers to extract <summary> and <sentiment> reliably.
Why This Matters
Delimiters transform unpredictable prose into parseable structure. Without them, you'd need complex regex or fragile string searching. With them, extraction becomes a simple split or tag match.
Key Takeaway: Use explicit delimiters (markers, XML tags, or special characters) in your prompt instructions to make model outputs trivially parseable with basic string operations.