diff --git a/guardrails/classes/history/iteration.py b/guardrails/classes/history/iteration.py index 45c60baab..74b31492c 100644 --- a/guardrails/classes/history/iteration.py +++ b/guardrails/classes/history/iteration.py @@ -98,7 +98,7 @@ def completion_tokens_consumed(self) -> Optional[int]: def raw_output(self) -> Optional[str]: """The exact output from the LLM.""" response = self.outputs.llm_response_info - if response is not None: + if response is not None and response.output: return response.output elif self.outputs.raw_output is not None: return self.outputs.raw_output diff --git a/guardrails/merge.py b/guardrails/merge.py index 07e3d9487..b5be28d62 100644 --- a/guardrails/merge.py +++ b/guardrails/merge.py @@ -88,7 +88,7 @@ def merge( advance = True composed_text.append(source_text) tempdiff = DIFFER.diff_main(target_text, source_text) - _, invariant = tempdiff[1] + _, invariant = tempdiff[1] if len(tempdiff) > 1 else tempdiff[0] # _, (_, invariant) = DIFFER.diff_main(source_text, target_text) prev_source_text = source[1] source = next(diff1, None) # type: ignore diff --git a/tests/unit_tests/test_merge.py b/tests/unit_tests/test_merge.py index 517a8efd1..d621a1c69 100644 --- a/tests/unit_tests/test_merge.py +++ b/tests/unit_tests/test_merge.py @@ -33,20 +33,23 @@ ], """ is funny and lives in """, ), - # broken! - # ( - # """JOHN lives IN SAN francisco""", - # [ - # """ lives in """, - # """john lives in san francisco""", - # ], - # """ lives in """, - # ) - # (broken) test behavior with a word close to PERSON - # ("""Perry is FUNNY and LIVES in NEW york""", - # [""" is FUNNY and lives in """, - # """perry is funny and lives in new york"""], - # """ is funny and lives in """), + ( + """JOHN lives IN SAN francisco""", + [ + """ lives in """, + """john lives in san francisco""", + ], + """ lives in """, + ), + # (broken) test behavior with a word close to PERSON - seems to work!? + ( + """Parson is FUNNY and LIVES in NEW york""", + [ + """ is FUNNY and lives in """, + """parson is funny and lives in new york""", + ], + """ is funny and lives in """, + ), ], ) def test_merge(original, new_values, expected):