"Unable to Retrieve Extracted Fields Using Prebuilt Model for ID Documents in Azure Form Recognizer"
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.
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
)
)