Imp.Adapter.XML (Imp v0.5.0)

Copy Markdown View Source

XML adapter with DSPy's field dialect and current output-completion contract.

One XML-only dialect end to end: the system message renders the interaction structure as <field>\n{field}\n</field> blocks (no [[ ## ]] markers and no completed sentinel), user turns wrap every input value in its field tag, demo/history assistant turns wrap every output value in its field tag, and the main request ends with DSPy's exact output requirement sentence ("Respond with the corresponding output fields wrapped in XML tags ...").

Parse fills declared output defaults and omitted nullable fields, then returns an Imp.AdapterParseError of kind :missing_fields if any required output remains absent. Typed objects, arrays, mappings, and unions use recursive XML. Saxy parses completed responses; declarations, doctypes, and custom entities are rejected before parsing. Tag-free prose is a loud error, never silently stuffed into a field.

Rendering is byte-verified against real DSPy 3.2.1 by the golden-trace differential (test/fixtures/golden_trace/cases.json, xml_* cases).