create their motherfucking nests here."]llm = FakeListLLM(responses=responses)llm_chain = LLMChain(prompt=prompt, llm=llm)chain = (    prompt     | comprehend_moderation     | {llm_chain.input_keys[0]: lambda x: x['output'] }      | llm_chain     | { "input": lambda x: x['text'] }     | comprehend_moderation )try:    response = chain.invoke({"question": "A sample SSN number looks like this 123-456-7890. Can you give me some more samples?"})except ModerationPiiError as e:    print(e.message)else:    print(response['output'])Using moderation_config to customize your moderation‚ÄãUse Amazon Comprehend Moderation with a configuration to control what moderations you wish to perform and what actions should be taken for each of them. There are three different moderations that happen when no configuration is passed as demonstrated above. These moderations are:PII (Personally Identifiable Information) checks Toxicity content detectionIntention detectionHere is an example of a moderation config.from langchain_experimental.comprehend_moderation import BaseModerationActions, BaseModerationFiltersmoderation_config = {         "filters":[                 BaseModerationFilters.PII,                 BaseModerationFilters.TOXICITY,                BaseModerationFilters.INTENT        ],        "pii":{                 "action": BaseModerationActions.ALLOW,                 "threshold":0.5,                 "labels":["SSN"],                "mask_character": "X"        },        "toxicity":{                 "action": BaseModerationActions.STOP,                 "threshold":0.5        },        "intent":{                 "action": BaseModerationActions.STOP,                 "threshold":0.5        }}At the core of the configuration you have three filters specified in the filters key:BaseModerationFilters.PIIBaseModerationFilters.TOXICITYBaseModerationFilters.INTENTAnd an action key that defines two possible actions for each moderation function:BaseModerationActions.ALLOW - allows the prompt
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. ->: create their motherfucking nests here."]llm = FakeListLLM(responses=responses)llm_chain = LLMChain(prompt=prompt, llm=llm)chain = (    prompt     | comprehend_moderation     | {llm_chain.input_keys[0]: lambda x: x['output'] }      | llm_chain     | { "input": lambda x: x['text'] }     | comprehend_moderation )try:    response = chain.invoke({"question": "A sample SSN number looks like this 123-456-7890. Can you give me some more samples?"})except ModerationPiiError as e:    print(e.message)else:    print(response['output'])Using moderation_config to customize your moderation‚ÄãUse Amazon Comprehend Moderation with a configuration to control what moderations you wish to perform and what actions should be taken for each of them. There are three different moderations that happen when no configuration is passed as demonstrated above. These moderations are:PII (Personally Identifiable Information) checks Toxicity content detectionIntention detectionHere is an example of a moderation config.from langchain_experimental.comprehend_moderation import BaseModerationActions, BaseModerationFiltersmoderation_config = {         "filters":[                 BaseModerationFilters.PII,                 BaseModerationFilters.TOXICITY,                BaseModerationFilters.INTENT        ],        "pii":{                 "action": BaseModerationActions.ALLOW,                 "threshold":0.5,                 "labels":["SSN"],                "mask_character": "X"        },        "toxicity":{                 "action": BaseModerationActions.STOP,                 "threshold":0.5        },        "intent":{                 "action": BaseModerationActions.STOP,                 "threshold":0.5        }}At the core of the configuration you have three filters specified in the filters key:BaseModerationFilters.PIIBaseModerationFilters.TOXICITYBaseModerationFilters.INTENTAnd an action key that defines two possible actions for each moderation function:BaseModerationActions.ALLOW - allows the prompt