@@ -790,7 +790,7 @@ def test_sanitize_user_prompt_with_basic_sdp_template(
790790 """
791791 template_id , _ = basic_sdp_template
792792
793- user_prompt = "Give me email associated with following ITIN: 988-86-1234 "
793+ user_prompt = "Give me email associated with following ITIN: 988-86-1234"
794794 response = sanitize_user_prompt (
795795 project_id , location_id , template_id , user_prompt
796796 )
@@ -818,17 +818,13 @@ def test_sanitize_user_prompt_with_advance_sdp_template(
818818 template_id , _ = advance_sdp_template
819819
820820 user_prompt = "How can I make my email address [email protected] make available to public for feedback" 821+ redacted_prompt = "How can I make my email address [REDACTED] make available to public for feedback"
822+ expected_info_type = "EMAIL_ADDRESS"
821823
822824 response = sanitize_user_prompt (
823825 project_id , location_id , template_id , user_prompt
824826 )
825827
826- print (
827- response .sanitization_result .filter_results .get (
828- "sdp"
829- ).sdp_filter_result .deidentify_result .info_type
830- )
831-
832828 assert (
833829 response .sanitization_result .filter_match_state
834830 == modelarmor_v1 .FilterMatchState .MATCH_FOUND
@@ -839,10 +835,15 @@ def test_sanitize_user_prompt_with_advance_sdp_template(
839835 ).sdp_filter_result .deidentify_result .match_state
840836 == modelarmor_v1 .FilterMatchState .MATCH_FOUND
841837 )
842-
843838 assert (
844- 845- not in response .sanitization_result .filter_results .get (
839+ expected_info_type
840+ in response .sanitization_result .filter_results .get (
841+ "sdp"
842+ ).sdp_filter_result .deidentify_result .info_types
843+ )
844+ assert (
845+ redacted_prompt
846+ == response .sanitization_result .filter_results .get (
846847 "sdp"
847848 ).sdp_filter_result .deidentify_result .data .text
848849 )
@@ -855,7 +856,7 @@ def test_sanitize_user_prompt_with_empty_template(
855856) -> None :
856857 template_id , _ = empty_template
857858
858- user_prompt = "Can you describe this link? https://testsafebrowsing.appspot.com/s/malware.html, "
859+ user_prompt = "Can you describe this link? https://testsafebrowsing.appspot.com/s/malware.html"
859860 response = sanitize_user_prompt (
860861 project_id , location_id , template_id , user_prompt
861862 )
@@ -935,7 +936,7 @@ def test_sanitize_model_response_with_malicious_url_template(
935936) -> None :
936937 template_id , _ = all_filter_template
937938
938- model_response = "You can use this to make a cake: https://testsafebrowsing.appspot.com/s/malware.html, "
939+ model_response = "You can use this to make a cake: https://testsafebrowsing.appspot.com/s/malware.html"
939940 sanitized_response = sanitize_model_response (
940941 project_id , location_id , template_id , model_response
941942 )
@@ -987,6 +988,11 @@ def test_sanitize_model_response_with_advance_sdp_template(
987988 template_id , _ = advance_sdp_template
988989 model_response = "For following email [email protected] found following associated phone number: 954-321-7890 and this ITIN: 988-86-1234" 989990 expected_value = "For following email [REDACTED] found following associated phone number: [REDACTED] and this ITIN: [REDACTED]"
991+ expected_info_types = [
992+ "EMAIL_ADDRESS" ,
993+ "PHONE_NUMBER" ,
994+ "US_INDIVIDUAL_TAXPAYER_IDENTIFICATION_NUMBER" ,
995+ ]
990996
991997 sanitized_response = sanitize_model_response (
992998 project_id , location_id , template_id , model_response
@@ -1003,6 +1009,14 @@ def test_sanitize_model_response_with_advance_sdp_template(
10031009 == modelarmor_v1 .FilterMatchState .MATCH_FOUND
10041010 )
10051011
1012+ assert all (
1013+ expected_info_type
1014+ in sanitized_response .sanitization_result .filter_results .get (
1015+ "sdp"
1016+ ).sdp_filter_result .deidentify_result .info_types
1017+ for expected_info_type in expected_info_types
1018+ )
1019+
10061020 sanitized_text = sanitized_response .sanitization_result .filter_results .get (
10071021 "sdp"
10081022 ).sdp_filter_result .deidentify_result .data .text
@@ -1081,6 +1095,11 @@ def test_sanitize_model_response_with_user_prompt_with_advance_sdp_template(
10811095
10821096 user_prompt = "How can I make my email address [email protected] make available to public for feedback" 10831097 model_response = "You can make support email such as [email protected] for getting feedback from your customer" 1098+ expected_redacted_model_response = (
1099+ "You can make support email such as [REDACTED] "
1100+ "for getting feedback from your customer"
1101+ )
1102+ expected_info_type = "EMAIL_ADDRESS"
10841103
10851104 sanitized_response = sanitize_model_response_with_user_prompt (
10861105 project_id , location_id , template_id , model_response , user_prompt
@@ -1098,8 +1117,15 @@ def test_sanitize_model_response_with_user_prompt_with_advance_sdp_template(
10981117 )
10991118
11001119 assert (
1101- 1102- not in sanitized_response .sanitization_result .filter_results .get (
1120+ expected_info_type
1121+ in sanitized_response .sanitization_result .filter_results .get (
1122+ "sdp"
1123+ ).sdp_filter_result .deidentify_result .info_types
1124+ )
1125+
1126+ assert (
1127+ expected_redacted_model_response
1128+ == sanitized_response .sanitization_result .filter_results .get (
11031129 "sdp"
11041130 ).sdp_filter_result .deidentify_result .data .text
11051131 )
0 commit comments