Skip to content

detect_toxic_content async

detect_toxic_content(
    text_segments: ListOfTextSegments,
    language_code: LanguageCode,
    *,
    config_overrides: Optional[AsyncComprehendClientConfig] = None,
) -> DetectToxicContentResponse

Performs toxicity analysis on the list of text strings that you provide as input. The API response contains a results list that matches the size of the input list. For more information about toxicity detection, see Toxicity detection in the Amazon Comprehend Developer Guide.

Parameters:

  • text_segments (ListOfTextSegments) –

    A list of up to 10 text strings. Each string has a maximum size of 1 KB, and the maximum size of the list is 10 KB.

  • language_code (LanguageCode) –

    The language of the input text. Currently, English is the only supported language.

Raises:

Source code in docs_src/capo_comprehend/_services/async_comprehend.py
async def detect_toxic_content(
    self,
    text_segments: "capo_comprehend.types.list_of_text_segments.ListOfTextSegments",
    language_code: "capo_comprehend.types.language_code.LanguageCode",
    *,
    config_overrides: Optional[AsyncComprehendClientConfig] = None,
) -> (
    "capo_comprehend.types.detect_toxic_content_response.DetectToxicContentResponse"
):
    """<p>Performs toxicity analysis on the list of text strings that you provide as input. The API response contains a results list that matches the size of the input list. For more information about toxicity detection, see <a href="https://docs.aws.amazon.com/comprehend/latest/dg/toxicity-detection.html">Toxicity detection</a> in the <i>Amazon Comprehend Developer Guide</i>. </p>

    Args:
        text_segments: <p>A list of up to 10 text strings. Each string has a maximum size of 1 KB, and the maximum size of the list is 10 KB.</p>
        language_code: <p>The language of the input text. Currently, English is the only supported language.</p>

    Raises:
        capo_comprehend.errors.internal_server_exception.InternalServerException: <p>An internal server error occurred. Retry your request.</p>
        capo_comprehend.errors.invalid_request_exception.InvalidRequestException: <p>The request is invalid.</p>
        capo_comprehend.errors.text_size_limit_exceeded_exception.TextSizeLimitExceededException: <p>The size of the input text exceeds the limit. Use a smaller document.</p>
        capo_comprehend.errors.unsupported_language_exception.UnsupportedLanguageException: <p>Amazon Comprehend can't process the language of the input text. For a list of supported languages, <a href="https://docs.aws.amazon.com/comprehend/latest/dg/supported-languages.html">Supported languages</a> in the Comprehend Developer Guide. </p>
        capo_comprehend.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_comprehend.types.detect_toxic_content_request.DetectToxicContentRequest]",
    ) -> AsyncOperationResponse[
        "capo_comprehend.types.detect_toxic_content_response.DetectToxicContentResponse"
    ]:
        import capo_comprehend._operations.comprehend_20171127.detect_toxic_content

        (
            output,
            http_response,
        ) = await capo_comprehend._operations.comprehend_20171127.detect_toxic_content.async_detect_toxic_content(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_comprehend.types.detect_toxic_content_request.DetectToxicContentRequest",
    ) -> dict[str, Any]:
        import capo_comprehend.types.detect_toxic_content_request

        return capo_comprehend.types.detect_toxic_content_request.redact_sensitive(
            input_
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("DetectToxicContent", redact_input=_redact_input),
    )
    input_: capo_comprehend.types.detect_toxic_content_request.DetectToxicContentRequest = {
        "text_segments": text_segments,
        "language_code": language_code,
    }

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output