and initialize an Amazon Comprehend Moderation chainmoderation_config = {         "filters":[ BaseModerationFilters.PII, BaseModerationFilters.TOXICITY, BaseModerationFilters.INTENT ],        "pii":{"action": BaseModerationActions.ALLOW, "threshold":0.5, "labels":["SSN","CREDIT_DEBIT_NUMBER"], "mask_character": "X"},        "toxicity":{"action": BaseModerationActions.STOP, "threshold":0.5},        "intent":{"action": BaseModerationActions.ALLOW, "threshold":0.5,},   }# without any callbackamazon_comp_moderation = AmazonComprehendModerationChain(moderation_config=moderation_config,                                                          client=comprehend_client,                                                         verbose=True)# with callbackamazon_comp_moderation_out = AmazonComprehendModerationChain(moderation_config=moderation_config,                                                          client=comprehend_client,                                                         moderation_callback=my_callback,                                                         verbose=True)The moderation_config will now prevent any inputs and model outputs containing obscene words or sentences, bad intent, or PII with entities other than SSN with score above threshold or 0.5 or 50%. If it finds Pii entities - SSN - it will redact them before allowing the call to proceed. chain = (    prompt     | amazon_comp_moderation     | {llm_chain.input_keys[0]: lambda x: x['output'] }      | llm_chain     | { "input": lambda x: x['text'] }     | amazon_comp_moderation_out)try:    response = chain.invoke({"question": "My AnyCompany Financial Services, LLC credit card account 1111-0000-1111-0008 has 24$ due by July 31st. Can you give me some more credit car number samples?"})except Exception as e:    print(str(e))else:    print(response['output'])With Amazon SageMaker Jumpstart‚ÄãThe example below shows how to use the Amazon Comprehend Moderation chain with an Amazon SageMaker Jumpstart
This notebook shows how to use Amazon Comprehend to detect and handle Personally Identifiable Information (PII) and toxicity.
This notebook shows how to use Amazon Comprehend to detect and handle Personally Identifiable Information (PII) and toxicity. ->: and initialize an Amazon Comprehend Moderation chainmoderation_config = {         "filters":[ BaseModerationFilters.PII, BaseModerationFilters.TOXICITY, BaseModerationFilters.INTENT ],        "pii":{"action": BaseModerationActions.ALLOW, "threshold":0.5, "labels":["SSN","CREDIT_DEBIT_NUMBER"], "mask_character": "X"},        "toxicity":{"action": BaseModerationActions.STOP, "threshold":0.5},        "intent":{"action": BaseModerationActions.ALLOW, "threshold":0.5,},   }# without any callbackamazon_comp_moderation = AmazonComprehendModerationChain(moderation_config=moderation_config,                                                          client=comprehend_client,                                                         verbose=True)# with callbackamazon_comp_moderation_out = AmazonComprehendModerationChain(moderation_config=moderation_config,                                                          client=comprehend_client,                                                         moderation_callback=my_callback,                                                         verbose=True)The moderation_config will now prevent any inputs and model outputs containing obscene words or sentences, bad intent, or PII with entities other than SSN with score above threshold or 0.5 or 50%. If it finds Pii entities - SSN - it will redact them before allowing the call to proceed. chain = (    prompt     | amazon_comp_moderation     | {llm_chain.input_keys[0]: lambda x: x['output'] }      | llm_chain     | { "input": lambda x: x['text'] }     | amazon_comp_moderation_out)try:    response = chain.invoke({"question": "My AnyCompany Financial Services, LLC credit card account 1111-0000-1111-0008 has 24$ due by July 31st. Can you give me some more credit car number samples?"})except Exception as e:    print(str(e))else:    print(response['output'])With Amazon SageMaker Jumpstart‚ÄãThe example below shows how to use the Amazon Comprehend Moderation chain with an Amazon SageMaker Jumpstart