Skip to content
Merged
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
5 changes: 4 additions & 1 deletion src/careconnect/agents/verification_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions test/test_verification_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}')},
Expand Down
Loading