Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryAgentsCallbacksModulesSecurityGuidesAdaptersDebuggingDeploymentEvaluationFallbacksLangSmithRun LLMs locallyModel comparisonPrivacyPydantic compatibilitySafetyAmazon Comprehend Moderation ChainConstitutional chainHugging Face prompt injection identificationLogical Fallacy chainModeration chainMoreGuidesSafetyAmazon Comprehend Moderation ChainOn this pageAmazon Comprehend Moderation ChainThis notebook shows how to use Amazon Comprehend to detect and handle Personally Identifiable Information (PII) and toxicity.Setting up‚Äã%pip install boto3 nltkimport boto3comprehend_client = boto3.client('comprehend', region_name='us-east-1')from langchain_experimental.comprehend_moderation import AmazonComprehendModerationChaincomprehend_moderation = AmazonComprehendModerationChain(    client=comprehend_client, #optional    verbose=True)Using AmazonComprehendModerationChain with LLM chain‚ÄãNote: The example below uses the Fake LLM from LangChain, but the same concept could be applied to other LLMs.from langchain.prompts import PromptTemplatefrom langchain.chains import LLMChainfrom langchain.llms.fake import FakeListLLMfrom langchain_experimental.comprehend_moderation.base_moderation_exceptions import ModerationPiiErrortemplate = """Question: {question}Answer:"""prompt = PromptTemplate(template=template, input_variables=["question"])responses = [    "Final Answer: A credit card number looks like 1289-2321-1123-2387. A fake SSN number looks like 323-22-9980. John Doe's phone number is (999)253-9876.",     "Final Answer: This is a really shitty way of constructing a birdhouse. This is fucking insane to think that any birds would actually create their motherfucking nests here."]llm
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. ->: Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryAgentsCallbacksModulesSecurityGuidesAdaptersDebuggingDeploymentEvaluationFallbacksLangSmithRun LLMs locallyModel comparisonPrivacyPydantic compatibilitySafetyAmazon Comprehend Moderation ChainConstitutional chainHugging Face prompt injection identificationLogical Fallacy chainModeration chainMoreGuidesSafetyAmazon Comprehend Moderation ChainOn this pageAmazon Comprehend Moderation ChainThis notebook shows how to use Amazon Comprehend to detect and handle Personally Identifiable Information (PII) and toxicity.Setting up‚Äã%pip install boto3 nltkimport boto3comprehend_client = boto3.client('comprehend', region_name='us-east-1')from langchain_experimental.comprehend_moderation import AmazonComprehendModerationChaincomprehend_moderation = AmazonComprehendModerationChain(    client=comprehend_client, #optional    verbose=True)Using AmazonComprehendModerationChain with LLM chain‚ÄãNote: The example below uses the Fake LLM from LangChain, but the same concept could be applied to other LLMs.from langchain.prompts import PromptTemplatefrom langchain.chains import LLMChainfrom langchain.llms.fake import FakeListLLMfrom langchain_experimental.comprehend_moderation.base_moderation_exceptions import ModerationPiiErrortemplate = """Question: {question}Answer:"""prompt = PromptTemplate(template=template, input_variables=["question"])responses = [    "Final Answer: A credit card number looks like 1289-2321-1123-2387. A fake SSN number looks like 323-22-9980. John Doe's phone number is (999)253-9876.",     "Final Answer: This is a really shitty way of constructing a birdhouse. This is fucking insane to think that any birds would actually create their motherfucking nests here."]llm