diff --git a/src/careconnect/agents/verification_agent.py b/src/careconnect/agents/verification_agent.py index 187bdc4..d1e15ba 100644 --- a/src/careconnect/agents/verification_agent.py +++ b/src/careconnect/agents/verification_agent.py @@ -97,6 +97,9 @@ def classify(self, text): return reply if isinstance(reply, dict) else {} +SOURCE_BLOCK = re.compile(r"\n?Source:[ \t]*\n\S+") + + class BedrockGuardrail: def __init__(self, client=None): self.client = client @@ -108,7 +111,7 @@ def apply(self, text): guardrailIdentifier=guardrail_id, guardrailVersion=guardrail_version, source="OUTPUT", - content=[{"text": {"text": hide_hospital_address(hide_hospital_phones(text))}}], + content=[{"text": {"text": hide_hospital_address(hide_hospital_phones(SOURCE_BLOCK.sub("", text)))}}], outputScope="FULL", ) return { diff --git a/test/test_verification_agent.py b/test/test_verification_agent.py index 9646f5b..9db03d7 100644 --- a/test/test_verification_agent.py +++ b/test/test_verification_agent.py @@ -167,6 +167,16 @@ def test_the_guardrail_adapter_sends_the_word_address_in_place_of_the_listed_add sent = client.apply_guardrail.call_args.kwargs["content"][0]["text"]["text"] self.assertEqual(sent, "At address. Home: 12 Elm Street.") + def test_the_guardrail_adapter_leaves_the_source_file_name_out(self): + client = mock.Mock() + client.apply_guardrail.return_value = {"action": "NONE"} + env = {"CARECONNECT_GUARDRAIL_ID": "gid", "CARECONNECT_GUARDRAIL_VERSION": "3"} + draft = "Approved Riverside Health information:\nA fact.\nSource:\ns3://bucket/approved/emergency-and-urgent-care-info.md" + with mock.patch.dict(os.environ, env): + agent.BedrockGuardrail(client).apply(draft) + sent = client.apply_guardrail.call_args.kwargs["content"][0]["text"]["text"] + self.assertEqual(sent, "Approved Riverside Health information:\nA fact.") + def test_the_adapter_returns_an_empty_reply_on_function_error_or_bad_json(self): for response in ( {"FunctionError": "Unhandled", "Payload": io.BytesIO(b'{"errorMessage": "boom"}')},