Engineering XML Structured Output

XML Output Prompts

Legacy integrations and enterprise systems still speak XML. The output contract for well-formed, single-root XML responses — same engine, XML rules.

Overview

XML output is a compatibility play: SOAP-era integrations, enterprise middleware, feed formats. The contract engine is the same as JSON's — schema, example, validation, strictness — with XML's failure modes addressed by name: exactly one root element, one child element per field, entity escaping for &, <, and >. This resource loads an invoice-metadata contract in XML mode. One boundary worth knowing: this is XML as OUTPUT — using XML tags to structure your prompt's INPUT for Claude is a different technique, covered by the System Prompt Generator.

Workflow

  1. Generate in XML mode

    Note the single-root rule and the escaping rule — XML's two signature failures, addressed by name.

  2. Check the empty-element convention

    Unknown optional values become empty elements, keeping the element set stable for downstream XPath.

  3. Keep element order

    Strict mode pins schema order — XML consumers are far more order-sensitive than JSON ones.

Why This Works

  • Naming XML's failure modes (multiple roots, unescaped entities) prevents them specifically
  • A stable element set with empty-element nulls keeps XPath expressions valid across runs
  • The output/input boundary keeps this tool out of Claude-tag territory — different problem, different tool

Best for

  • Legacy system integrations where XML is non-negotiable
  • Middleware pipelines validating against XML structure
  • Enterprise environments mid-migration from XML to JSON

Not for

  • Structuring prompt INPUT with XML tags for Claude — that's input formatting, see the System Prompt Generator
  • Greenfield integrations — JSON parses cheaper; use the format select

Use cases

  • Feeding model output into SOAP-era and enterprise XML consumers
  • Generating feed-format entries that downstream XML parsers ingest
  • Porting an existing JSON contract to an XML-only integration

Tip: Save time by exploring related resources and tools that integrate with this workflow.

Explore all resources