@@ -790,7 +790,7 @@ def test_sanitize_user_prompt_with_basic_sdp_template(
790
790
"""
791
791
template_id , _ = basic_sdp_template
792
792
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"
794
794
response = sanitize_user_prompt (
795
795
project_id , location_id , template_id , user_prompt
796
796
)
@@ -818,17 +818,13 @@ def test_sanitize_user_prompt_with_advance_sdp_template(
818
818
template_id , _ = advance_sdp_template
819
819
820
820
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"
821
823
822
824
response = sanitize_user_prompt (
823
825
project_id , location_id , template_id , user_prompt
824
826
)
825
827
826
- print (
827
- response .sanitization_result .filter_results .get (
828
- "sdp"
829
- ).sdp_filter_result .deidentify_result .info_type
830
- )
831
-
832
828
assert (
833
829
response .sanitization_result .filter_match_state
834
830
== modelarmor_v1 .FilterMatchState .MATCH_FOUND
@@ -839,10 +835,15 @@ def test_sanitize_user_prompt_with_advance_sdp_template(
839
835
).sdp_filter_result .deidentify_result .match_state
840
836
== modelarmor_v1 .FilterMatchState .MATCH_FOUND
841
837
)
842
-
843
838
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 (
846
847
"sdp"
847
848
).sdp_filter_result .deidentify_result .data .text
848
849
)
@@ -855,7 +856,7 @@ def test_sanitize_user_prompt_with_empty_template(
855
856
) -> None :
856
857
template_id , _ = empty_template
857
858
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"
859
860
response = sanitize_user_prompt (
860
861
project_id , location_id , template_id , user_prompt
861
862
)
@@ -935,7 +936,7 @@ def test_sanitize_model_response_with_malicious_url_template(
935
936
) -> None :
936
937
template_id , _ = all_filter_template
937
938
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"
939
940
sanitized_response = sanitize_model_response (
940
941
project_id , location_id , template_id , model_response
941
942
)
@@ -987,6 +988,11 @@ def test_sanitize_model_response_with_advance_sdp_template(
987
988
template_id , _ = advance_sdp_template
988
989
model_response = "For following email [email protected] found following associated phone number: 954-321-7890 and this ITIN: 988-86-1234"
989
990
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
+ ]
990
996
991
997
sanitized_response = sanitize_model_response (
992
998
project_id , location_id , template_id , model_response
@@ -1003,6 +1009,14 @@ def test_sanitize_model_response_with_advance_sdp_template(
1003
1009
== modelarmor_v1 .FilterMatchState .MATCH_FOUND
1004
1010
)
1005
1011
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
+
1006
1020
sanitized_text = sanitized_response .sanitization_result .filter_results .get (
1007
1021
"sdp"
1008
1022
).sdp_filter_result .deidentify_result .data .text
@@ -1081,6 +1095,11 @@ def test_sanitize_model_response_with_user_prompt_with_advance_sdp_template(
1081
1095
1082
1096
user_prompt = "How can I make my email address [email protected] make available to public for feedback"
1083
1097
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"
1084
1103
1085
1104
sanitized_response = sanitize_model_response_with_user_prompt (
1086
1105
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(
1098
1117
)
1099
1118
1100
1119
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 (
1103
1129
"sdp"
1104
1130
).sdp_filter_result .deidentify_result .data .text
1105
1131
)
0 commit comments