Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tests/test_xml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ def test_parse_answer_from_string_completion(self, xml_parser):
result == "45"
) # Should return just the last answer, not a full parse() namespace

def test_parse_answer_from_message_completion_uses_last_answer(self, xml_parser):
"""Test extracting the last answer from a message completion."""
completion = [
{
"role": "assistant",
"content": "<answer>44</answer><reasoning>Actually, that's not right either.</reasoning><answer>45</answer>",
}
]
result = xml_parser.parse_answer(completion)
assert result == "45"

def test_parse_answer_no_answer_field(self, xml_parser):
"""Test parse_answer when no answer field is found."""
completion = [
Expand Down
2 changes: 1 addition & 1 deletion verifiers/legacy/parsers/xml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def parse_answer(self, completion: Messages) -> str | None:
if isinstance(msg, dict)
else (msg.content or "")
)
parsed = self.parse(content)
parsed = self.parse(content, last=True)
if (
parsed
and hasattr(parsed, self.answer_field)
Expand Down