azure-sdk-for-python icon indicating copy to clipboard operation
azure-sdk-for-python copied to clipboard

Bug: DocumentIntelligenceClient, MARKDOWN table Output differs from document intelligence studio table output

Open MyaLeoni opened this issue 2 years ago • 13 comments

output_content_format=ContentFormat.MARKDOWN

  • Package Name: azure.ai.documentintelligence
  • Package Version: newest
  • Operating System: Windows
  • Python Version: 3.11.9

Describe the bug We use Document Intelligence Layout Modell to analyze orders. In that case we had today two bugs. The Markdown result differs from the result in the document intelligence studio interface. The difference is that the table columns are not the same. How can we get a markdown with the table columns we see in the document studio interface?

To Reproduce Steps to reproduce the behavior:

  1. Use our testdocument (PDF) here and look the table: https://documentintelligence.ai.azure.com/studio/layout (See Screenshot)
  2. Use our testdokument with: output_content_format=ContentFormat.MARKDOWN an look at the table. (See Screenshot) Columns are not the same.

Expected behavior We expect the table we see in the document intelligence interface from microsoft. Screenshots Bildschirmfoto 2024-08-09 um 16 13 29

If applicable, add screenshots to help explain your problem.

Additional context 2E_Val_240605_VALSP2224A_TECHN_05133305_geschwärzt.pdf

Bildschirmfoto 2024-08-09 um 16 12 53

Add any other context about the problem here.

MyaLeoni avatar Aug 09 '24 14:08 MyaLeoni

Thanks for the feedback, we’ll investigate asap.

xiangyan99 avatar Aug 09 '24 14:08 xiangyan99

Thank you!!!!! Unfortunately, our customers are currently dissatisfied.

MyaLeoni avatar Aug 09 '24 14:08 MyaLeoni

Hi @MyaLeoni , we need more info before further investigation: Are you using the same API version as in SDK in studio? Can you share the http request details in SDK?

Thanks

YalinLi0312 avatar Aug 09 '24 18:08 YalinLi0312

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @bojunehsu @vkurpad.

github-actions[bot] avatar Aug 09 '24 18:08 github-actions[bot]

In the second screenshot of the Studio result, you are using 2022-08-31. The latest result using 2024-07-31-preview is slightly different due to continuous refinements we make to our models to improve the overall quality. In this case, neither result is perfect. I get the same result whether I request text or markdown as the output format.

image

However, there may be another issue here. It appears that you are using a custom rendering solution in your first screenshot, which appears to support non-standard markdown since "-->" is rendered as an arrow instead of treating that entire line as a HTML comment. Please view the result using another Markdown viewer. image

Finally, please make sure you are using 2024-07-31-preview. Since standard Markdown tables do not support merged cells, earlier versions returned tables with merged cells in MultiMarkdown format which most viewers do not support. In the latest version, we switched to rendering tables as HTML.

bojunehsu avatar Aug 09 '24 20:08 bojunehsu

Hi @MyaLeoni. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

github-actions[bot] avatar Aug 14 '24 19:08 github-actions[bot]

We use Document intelligence as first step of a long AI Agent/ Flow. After the import we use the markdown result for llm calls. The LLM Calls we run with langchain. If we use the html table, we need more tokens. Is this a long term decision?

MyaLeoni avatar Aug 15 '24 08:08 MyaLeoni

def use_azure_original_docload(self, url, api_model) -> str:
    document_intelligence_client = DocumentIntelligenceClient(endpoint=os.environ["DOCUMENT_LOADER_API_ENDPOINT"], credential=AzureKeyCredential(os.environ["DOCUMENT_LOADER_API_KEY"]))
    poller = document_intelligence_client.begin_analyze_document(
        api_model,
        AnalyzeDocumentRequest(url_source=url),
        output_content_format=ContentFormat.MARKDOWN,
    )

    result: AnalyzeResult = poller.result()

MyaLeoni avatar Aug 15 '24 08:08 MyaLeoni

Hi @MyaLeoni , we need more info before further investigation: Are you using the same API version as in SDK in studio? Can you share the http request details in SDK?

Thanks Bildschirmfoto 2024-08-15 um 10 23 00

I am not sure if i understand your question. We tested the same model in Studio as in python. The results are different. In the studio all models give the right table output. In the python code not. api_model="prebuilt-layout" #of the AzureDocumentLoader

MyaLeoni avatar Aug 15 '24 08:08 MyaLeoni

wen have updates to 2024-07-31 preview. Now everything is working. In 2023-07-31 (3.1 General Availability) Microsoft has no docx und xlsx support. We used it because of this information: "Document Intelligence public preview releases provide early access to features that are in active development. Features, approaches, and processes may change, prior to General Availability (GA), based on user feedback."

https://learn.microsoft.com/en-us/azure/ai-services/document-intelligence/concept-layout?view=doc-intel-4.0.0&tabs=sample-code

Question: Do we get xlsx und docx support in the next GA Version? @YalinLi0312

MyaLeoni avatar Aug 19 '24 14:08 MyaLeoni

Yes, the next GA version will support docx and xlsx in the same way as 2024-07-31-preview.

Yes, we will be switching to HTML tables in Markdown as the longer-term solution. We are aware that it consumes more tokens. But given all the limitations of Markdown tables, as you encountered above, we believe this is the best option.

bojunehsu avatar Aug 19 '24 16:08 bojunehsu

Thanks a lot for the help and information! Can you recommend a news fedd for the future, where we get such information as soon as possible?

MyaLeoni avatar Aug 19 '24 18:08 MyaLeoni

We aim to document such changes at What's New, but may not always describe the changes to such level of details. Please feel free to continue asking questions in this forum.

bojunehsu avatar Aug 19 '24 20:08 bojunehsu