"Unable to Retrieve Extracted Fields Using Prebuilt Model for ID Documents in Azure Form Recognizer"

Muskan Choudhary 0 Reputation points
2024-10-01T11:45:58.8266667+00:00

I have been using Azure Document AI Studio with the prebuilt model identifying documents. In the studio, I successfully added query fields like "borrower", "lender", loan amount and loan agreement date and the model returned the results after analysis.

When I run the code, and print id_documents.documents it returns [AnalyzedDocument(doc_type=idDocument, bounding_regions=[BoundingRegion(page_number=1, polygon=[Point(x=0.0, y=0.0), Point(x=691.0, y=0.0), Point(x=691.0, y=858.0), Point(x=0.0, y=858.0)])], spans=[DocumentSpan(offset=0, length=516)], fields={}, confidence=0.995)] .The fields value is empty although I could see that the document is properly loaded when I print id_documents . Even though it works perfectly in the Azure Document AI Studio, I am unable to retrieve any results with this code.Screenshot 2024-10-01 133216

Am I missing something in my implementation, or could there be an issue with how I'm using the prebuilt model in the code?

I wanted to replicate this functionality using Python. Here's the Python code I'm using:


from azure.core.credentials import AzureKeyCredential
from azure.ai.formrecognizer import DocumentAnalysisClient

document_path = r".."

document_analysis_client = DocumentAnalysisClient(
    endpoint=endpoint, credential=AzureKeyCredential(key)
)
with open(document_path, "rb") as f:
    poller = document_analysis_client.begin_analyze_document(
        "prebuilt-idDocument", document=f
    )

    
id_documents = poller.result()
print(id_documents)

for idx, id_document in enumerate(id_documents.documents):
    print(id_documents.documents)
    print(id_document.fields)
    borrower = id_document.fields.get("borrower")
    if borrower:
        print(
            "borrower : {} has confidence: {}".format(
                borrower.value, borrower.confidence
            )
        )

Azure AI Document Intelligence
Azure AI Document Intelligence
An Azure service that turns documents into usable data. Previously known as Azure Form Recognizer.
1,662 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.