fix(dspy): escape nonstr XMLAdapter output fields - #97
Open
detail-app[bot] wants to merge 1 commit into
Open
Conversation
Greptile SummaryThis PR broadens XML entity escaping from exact-
Confidence Score: 5/5The PR appears safe to merge with no actionable correctness, security, or repository-rule issues identified. Output text is escaped exactly once and decoded before type conversion, while the tests exercise the reported malformed-XML path and preserve the intended input-field behavior. Important Files Changed
Reviews (1): Last reviewed commit: "fix(dspy): escape nonstr XMLAdapter outp..." | Re-trigger Greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Warning
GitHub issue creation failed
Detail attempted to publish this bug to GitHub, but the issue could not be created. This fix PR was created without that issue, and missing tracker references are shown as
Unknown issue.You can review and merge this PR normally. Please review your tracker integration settings before the next publish run.
Detail bug report: View on Detail
📝 Changes Description
This PR fixes malformed XML in
XMLAdapteroutput for non-stroutput fields.XMLAdapter.format_field_with_valuegated XML escaping of</&onis_output and field.info.annotation is str(exact identity). Output fields whose annotation is not exactlystr— notablystr | Noneanddspy.Code(apydantic.BaseModel, not astrsubclass) — fell through unescaped, embedding raw</&into few-shot demo (assistant) messages. When the LM echoed the demonstrated pattern,XMLAdapter.parseraisedAdapterParseError(end-to-end viaPredict.forward -> adapter.__call__ -> XMLAdapter.parse). The bug was introduced in33aaa19e, which added the escape but narrowed the gate to exact-stroutputs.... is stridentity gate so escaping applies to every plain-text output field. The nested-XML branch (_value_to_xml, which already escapes leaf text) and input-field rendering are unchanged. This is the narrower of the two options in the report; it coversstr | Noneanddspy.Codewithout widening the blast radius to input rendering.Closes Unknown issue
✅ Contributor Checklist
Testing
tests/adapters/test_xml_adapter.py:test_xml_adapter_escapes_non_str_output_fields— verifiesstr | Noneanddspy.Codeoutputs escape</&, produce well-formed XML (xml.etree.ElementTree.fromstring), and format->parse round-trip to the original literal value.test_xml_adapter_does_not_escape_input_fields_with_special_chars— pins the scope boundary so an accidental over-broadening to input fields (which would break prompt snapshots) is caught.XMLAdaptersuite (26 tests, including thestr-output escape round-trip,Nonedefaults, nested-XML, and all exact-message snapshots) remains green (28/28).uv run pytest -m 'not extra and not deno' tests/) all pass with no regressions.ruff check,pre-commit run, anduv build(wheel importsdspy3.3.1) all pass.llama3.2:3bLM: the assistant demo for adspy.Codesignature whose prior demo contains<is now well-formed/escaped XML in the assembled prompt, and the default production path (use_json_adapter_fallback=True) returns the correctCode(code='return 3 < 5')with the literal<intact.Authored by Detail: Automatic Fixes. Input-field escaping is intentionally left unchanged —
XMLAdapter.parseonly consumes output fields, so unescaped input XML is not parse-reachable; escaping inputs is a broader prompt-fidelity behavior change and is out of scope.Automatic Fixes PRs can be configured here.