agentleFS
aegnticaegntic/compound-engineering/skills/xml-tag-structure/SKILL.md

xml-tag-structure

Skill1 starsChanged 5 months agoMITView on GitHub

Guide for structuring, parsing, and validating XML-like tags in LLM inputs, system prompts, outputs, and agent-to-agent communication. Use this skill when designing prompt templates, parsing structured content from text, or handling nested tag boundaries.

The file

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 4 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Parsing Output Payloads: Run robust parsing logic to extract tags, handling potentially truncated responses and malformed markup.

    line 29
  2. Distinctive:

    When designing system prompts, wrap different types of information in explicit tags.

    line 35
  3. Very specific:

    Use snake_case or kebab-case for tag names (e.g., <file_content> or <file-content>).

    line 46
  4. Very specific:

    Keep tag names descriptive and singular/plural consistent (e.g., <item> inside <items>).

    line 47
  5. Distinctive:

    Avoid mixing tags with standard markup or styling unless explicitly wrapping inline values.

    line 48
  6. Distinctive:

    Ensure all block tags are placed on their own lines to ease regex-based line splitting and parsing.

    line 60
  7. Very specific:

    Use the bundled script scripts/parse_xml.py to extract tag contents from text files or standard input.

    line 70
  8. Very specific:

    Use the --strict flag to disable fallback parsing for unclosed/truncated tags (strict parsing matches closed tags only):

    line 92

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

XML Tag Structure

Overview

This skill provides guidelines and tools for utilizing XML-like tags to structure prompts, format LLM output payloads, and robustly parse structured text data. It helps maintain clear delimiters for instruction blocks and data boundaries, even when dealing with malformed or truncated text.

File Tree

xml-tag-structure/
├── SKILL.md                     # This file. Skill definition and workflow guide.
├── references/
│   └── xml-guidelines.md        # Comprehensive best-practices reference for XML tags.
└── scripts/
    └── parse_xml.py             # CLI tool for extracting tag contents from text.

Workflow Decision Tree

To handle XML tags in LLM workflows, follow this process:

  1. Structuring Prompts: Wrap instructions, context, input variables, and output schemas in clean, snake_case XML tags.
  2. Structuring Outputs: Define specific tags for the model to output, using CDATA sections for nested code or raw markup blocks.
  3. Parsing Output Payloads: Run robust parsing logic to extract tags, handling potentially truncated responses and malformed markup.

1. Structuring Prompts

When designing system prompts, wrap different types of information in explicit tags. This helps the LLM distinguish instruction from context or user input, preventing prompt injection and instructions leakage.

Standard Tag Categories

  • <system_instructions>: Define the agent's identity, rules, and core directives.
  • <context>: Provide background information, schemas, file contexts, or system state.
  • <examples>: Enclose few-shot examples (each inside <example>).
  • <user_input>: Enclose the current input or request to process.

Rules for Prompt Tags

  • Use snake_case or kebab-case for tag names (e.g., <file_content> or <file-content>).
  • Keep tag names descriptive and singular/plural consistent (e.g., <item> inside <items>).
  • Avoid mixing tags with standard markup or styling unless explicitly wrapping inline values.

2. Formatting LLM Output Payloads

Instruct the LLM to output structured data wrapped in specific XML tags. This approach avoids JSON escaping issues and is easier for the model to stream.

Output XML Guidelines

  • Request unique tag wrappers for each output section (e.g., <thought>, <reasoning>, <code_changes>, <final_answer>).
  • Wrap any code or characters that look like XML tags in CDATA blocks: <![CDATA[ ... ]]>.
  • Ensure all block tags are placed on their own lines to ease regex-based line splitting and parsing.

3. Parsing and Handling Malformed Tags

LLM outputs are occasionally malformed or truncated due to context limits. Do not use strict parser APIs directly on raw output. Instead, use robust regex extraction.

Using the Bundled Extractor Script

Use the bundled script scripts/parse_xml.py to extract tag contents from text files or standard input.

Syntax

python3 scripts/parse_xml.py <tag_name> [-f <file_path>] [--strict]

Examples

Extract the content of the <thought> tag from a saved file:

python3 scripts/parse_xml.py thought -f response.txt

Extract the content of the <response> tag from standard input:

cat response.txt | python3 scripts/parse_xml.py response

Use the --strict flag to disable fallback parsing for unclosed/truncated tags (strict parsing matches closed tags only):

python3 scripts/parse_xml.py result -f response.txt --strict

4. Streaming / Chunked Parsing

Status: Out of scope for this skill.

Streaming and chunked parsing (processing partial LLM output as it arrives over SSE or chunked transfer) introduces distinct challenges: detecting partial opening tags, buffering incomplete content, and deciding when to emit extracted results. This skill focuses on parsing complete or truncated finished outputs. For streaming use cases, consider building a stateful streaming parser that accumulates chunks and applies the extraction logic from scripts/parse_xml.py once the stream closes or a boundary is detected.


References

For detailed standards and examples, see:

  • references/xml-guidelines.md — Comprehensive guide on XML tags in prompts and outputs.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.