Skip to content

analyze_document

analyze_document(
    document: Document,
    feature_types: FeatureTypes,
    *,
    config_overrides: Optional[TextractClientConfig] = None,
    human_loop_config: Optional[HumanLoopConfig] = None,
    queries_config: Optional[QueriesConfig] = None,
    adapters_config: Optional[AdaptersConfig] = None,
) -> AnalyzeDocumentResponse

Analyzes an input document for relationships between detected items.

The types of information returned are as follows:

  • Form data (key-value pairs). The related information is returned in two Block objects, each of type KEY_VALUE_SET: a KEY Block object and a VALUE Block object. For example, Name: Ana Silva Carolina contains a key and value. Name: is the key. Ana Silva Carolina is the value.

  • Table and table cell data. A TABLE Block object contains information about a detected table. A CELL Block object is returned for each cell in a table.

  • Lines and words of text. A LINE Block object contains one or more WORD Block objects. All lines and words that are detected in the document are returned (including text that doesn't have a relationship with the value of FeatureTypes).

  • Signatures. A SIGNATURE Block object contains the location information of a signature in a document. If used in conjunction with forms or tables, a signature can be given a Key-Value pairing or be detected in the cell of a table.

  • Query. A QUERY Block object contains the query text, alias and link to the associated Query results block object.

  • Query Result. A QUERY_RESULT Block object contains the answer to the query and an ID that connects it to the query asked. This Block also contains a confidence score.

Selection elements such as check boxes and option buttons (radio buttons) can be detected in form data and in tables. A SELECTION_ELEMENT Block object contains information about a selection element, including the selection status.

You can choose which type of analysis to perform by specifying the FeatureTypes list.

The output is returned in a list of Block objects.

AnalyzeDocument is a synchronous operation. To analyze documents asynchronously, use StartDocumentAnalysis.

For more information, see Document Text Analysis.

Parameters:

  • document (Document) –

    The input document as base64-encoded bytes or an Amazon S3 object. If you use the AWS CLI to call Amazon Textract operations, you can't pass image bytes. The document must be an image in JPEG, PNG, PDF, or TIFF format.

    If you're using an AWS SDK to call Amazon Textract, you might not need to base64-encode image bytes that are passed using the Bytes field.

  • feature_types (FeatureTypes) –

    A list of the types of analysis to perform. Add TABLES to the list to return information about the tables that are detected in the input document. Add FORMS to return detected form data. Add SIGNATURES to return the locations of detected signatures. Add LAYOUT to the list to return information about the layout of the document. All lines and words detected in the document are included in the response (including text that isn't related to the value of FeatureTypes).

  • human_loop_config (Optional[HumanLoopConfig], default: None ) –

    Sets the configuration for the human in the loop workflow for analyzing documents.

    Amazon Textract uses Amazon Augmented AI (A2I) to run the human review workflows that you specify in HumanLoopConfig. A2I entered maintenance mode in July 2026 and no longer accepts new customers. If your account is not an existing A2I customer, requests fail with an InvalidParameterException. For more information, see AWS service availability. If you're an existing A2I customer but receive this error, contact AWS Support and request assistance from the A2I team.

  • queries_config (Optional[QueriesConfig], default: None ) –

    Contains Queries and the alias for those Queries, as determined by the input.

  • adapters_config (Optional[AdaptersConfig], default: None ) –

    Specifies the adapter to be used when analyzing a document.

Raises:

  • AccessDeniedException –

    You aren't authorized to perform the action. Use the Amazon Resource Name (ARN) of an authorized user or IAM role to perform the operation.

  • BadDocumentException –

    Amazon Textract isn't able to read the document. For more information on the document limits in Amazon Textract, see Hard limits.

  • DocumentTooLargeException –

    The document can't be processed because it's too large. The maximum document size for synchronous operations 10 MB. The maximum document size for asynchronous operations is 500 MB for PDF files.

  • HumanLoopQuotaExceededException –

    Indicates you have exceeded the maximum number of active human in the loop workflows available

  • InternalServerError –

    Amazon Textract experienced a service issue. Try your call again.

  • InvalidParameterException –

    An input parameter violated a constraint. For example, in synchronous operations, an InvalidParameterException exception occurs when neither of the S3Object or Bytes values are supplied in the Document request parameter. Validate your parameter before calling the API operation again.

  • InvalidS3ObjectException –

    Amazon Textract is unable to access the S3 object that's specified in the request. for more information, Configure Access to Amazon S3 For troubleshooting information, see Troubleshooting Amazon S3

  • ProvisionedThroughputExceededException –

    The number of requests exceeded your throughput limit. If you want to increase this limit, contact Amazon Textract.

  • ThrottlingException –

    Amazon Textract is temporarily unable to process the request. Try your call again.

  • UnsupportedDocumentException –

    The format of the input document isn't supported. Documents for operations can be in PNG, JPEG, PDF, or TIFF format.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_textract/_services/textract.py
def analyze_document(
    self,
    document: "capo_textract.types.document.Document",
    feature_types: "capo_textract.types.feature_types.FeatureTypes",
    *,
    config_overrides: Optional[TextractClientConfig] = None,
    human_loop_config: Optional[
        "capo_textract.types.human_loop_config.HumanLoopConfig"
    ] = None,
    queries_config: Optional[
        "capo_textract.types.queries_config.QueriesConfig"
    ] = None,
    adapters_config: Optional[
        "capo_textract.types.adapters_config.AdaptersConfig"
    ] = None,
) -> "capo_textract.types.analyze_document_response.AnalyzeDocumentResponse":
    """<p>Analyzes an input document for relationships between detected items. </p> <p>The types of information returned are as follows: </p> <ul> <li> <p>Form data (key-value pairs). The related information is returned in two <a>Block</a> objects, each of type <code>KEY_VALUE_SET</code>: a KEY <code>Block</code> object and a VALUE <code>Block</code> object. For example, <i>Name: Ana Silva Carolina</i> contains a key and value. <i>Name:</i> is the key. <i>Ana Silva Carolina</i> is the value.</p> </li> <li> <p>Table and table cell data. A TABLE <code>Block</code> object contains information about a detected table. A CELL <code>Block</code> object is returned for each cell in a table.</p> </li> <li> <p>Lines and words of text. A LINE <code>Block</code> object contains one or more WORD <code>Block</code> objects. All lines and words that are detected in the document are returned (including text that doesn't have a relationship with the value of <code>FeatureTypes</code>). </p> </li> <li> <p>Signatures. A SIGNATURE <code>Block</code> object contains the location information of a signature in a document. If used in conjunction with forms or tables, a signature can be given a Key-Value pairing or be detected in the cell of a table.</p> </li> <li> <p>Query. A QUERY Block object contains the query text, alias and link to the associated Query results block object.</p> </li> <li> <p>Query Result. A QUERY_RESULT Block object contains the answer to the query and an ID that connects it to the query asked. This Block also contains a confidence score.</p> </li> </ul> <p>Selection elements such as check boxes and option buttons (radio buttons) can be detected in form data and in tables. A SELECTION_ELEMENT <code>Block</code> object contains information about a selection element, including the selection status.</p> <p>You can choose which type of analysis to perform by specifying the <code>FeatureTypes</code> list. </p> <p>The output is returned in a list of <code>Block</code> objects.</p> <p> <code>AnalyzeDocument</code> is a synchronous operation. To analyze documents asynchronously, use <a>StartDocumentAnalysis</a>.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/textract/latest/dg/how-it-works-analyzing.html">Document Text Analysis</a>.</p>

    Args:
        document: <p>The input document as base64-encoded bytes or an Amazon S3 object. If you use the AWS CLI to call Amazon Textract operations, you can't pass image bytes. The document must be an image in JPEG, PNG, PDF, or TIFF format.</p> <p>If you're using an AWS SDK to call Amazon Textract, you might not need to base64-encode image bytes that are passed using the <code>Bytes</code> field. </p>
        feature_types: <p>A list of the types of analysis to perform. Add TABLES to the list to return information about the tables that are detected in the input document. Add FORMS to return detected form data. Add SIGNATURES to return the locations of detected signatures. Add LAYOUT to the list to return information about the layout of the document. All lines and words detected in the document are included in the response (including text that isn't related to the value of <code>FeatureTypes</code>). </p>
        human_loop_config: <p>Sets the configuration for the human in the loop workflow for analyzing documents.</p> <note> <p>Amazon Textract uses Amazon Augmented AI (A2I) to run the human review workflows that you specify in <code>HumanLoopConfig</code>. A2I entered maintenance mode in July 2026 and no longer accepts new customers. If your account is not an existing A2I customer, requests fail with an <code>InvalidParameterException</code>. For more information, see <a href="https://aws.amazon.com/about-aws/whats-new/2026/06/aws-service-availability/">AWS service availability</a>. If you're an existing A2I customer but receive this error, contact AWS Support and request assistance from the A2I team.</p> </note>
        queries_config: <p>Contains Queries and the alias for those Queries, as determined by the input. </p>
        adapters_config: <p>Specifies the adapter to be used when analyzing a document.</p>

    Raises:
        capo_textract.errors.access_denied_exception.AccessDeniedException: <p>You aren't authorized to perform the action. Use the Amazon Resource Name (ARN) of an authorized user or IAM role to perform the operation.</p>
        capo_textract.errors.bad_document_exception.BadDocumentException: <p>Amazon Textract isn't able to read the document. For more information on the document limits in Amazon Textract, see <a href="https://docs.aws.amazon.com/textract/latest/dg/limits.html">Hard limits</a>.</p>
        capo_textract.errors.document_too_large_exception.DocumentTooLargeException: <p>The document can't be processed because it's too large. The maximum document size for synchronous operations 10 MB. The maximum document size for asynchronous operations is 500 MB for PDF files.</p>
        capo_textract.errors.human_loop_quota_exceeded_exception.HumanLoopQuotaExceededException: <p>Indicates you have exceeded the maximum number of active human in the loop workflows available</p>
        capo_textract.errors.internal_server_error.InternalServerError: <p>Amazon Textract experienced a service issue. Try your call again.</p>
        capo_textract.errors.invalid_parameter_exception.InvalidParameterException: <p>An input parameter violated a constraint. For example, in synchronous operations, an <code>InvalidParameterException</code> exception occurs when neither of the <code>S3Object</code> or <code>Bytes</code> values are supplied in the <code>Document</code> request parameter. Validate your parameter before calling the API operation again.</p>
        capo_textract.errors.invalid_s3_object_exception.InvalidS3ObjectException: <p>Amazon Textract is unable to access the S3 object that's specified in the request. for more information, <a href="https://docs.aws.amazon.com/AmazonS3/latest/dev/s3-access-control.html">Configure Access to Amazon S3</a> For troubleshooting information, see <a href="https://docs.aws.amazon.com/AmazonS3/latest/dev/troubleshooting.html">Troubleshooting Amazon S3</a> </p>
        capo_textract.errors.provisioned_throughput_exceeded_exception.ProvisionedThroughputExceededException: <p>The number of requests exceeded your throughput limit. If you want to increase this limit, contact Amazon Textract.</p>
        capo_textract.errors.throttling_exception.ThrottlingException: <p>Amazon Textract is temporarily unable to process the request. Try your call again.</p>
        capo_textract.errors.unsupported_document_exception.UnsupportedDocumentException: <p>The format of the input document isn't supported. Documents for operations can be in PNG, JPEG, PDF, or TIFF format.</p>
        capo_textract.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_textract.types.analyze_document_request.AnalyzeDocumentRequest]",
    ) -> OperationResponse[
        "capo_textract.types.analyze_document_response.AnalyzeDocumentResponse"
    ]:
        import capo_textract._operations.textract.analyze_document

        output, http_response = (
            capo_textract._operations.textract.analyze_document.analyze_document(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("AnalyzeDocument")
    )
    input_: capo_textract.types.analyze_document_request.AnalyzeDocumentRequest = {
        "document": document,
        "feature_types": feature_types,
    }
    if human_loop_config is not None:
        input_["human_loop_config"] = human_loop_config
    if queries_config is not None:
        input_["queries_config"] = queries_config
    if adapters_config is not None:
        input_["adapters_config"] = adapters_config

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output