How do I extract tables from azure through C# API

Vijay Prime 0 Reputation points
2025-05-08T12:08:57.2533333+00:00

User's image

User's image

Hello,
Can you please tell me how to extract tables from Azure through C# API. I am trying to get specific details from the MTC documents and for that I have created and trained a custom neural model for it and it is mapping the values of the table correctly.

The issue: Tables are returning as an empty array when I call the model through the API.

The single key value pair fields are extracting correctly when I use the API but the tables are returning as empty arrays. How do I extract the tables?
Do you have a sample code for table extraction?

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

1 answer

Sort by: Most helpful
  1. Anatoly Ponomarev 0 Reputation points Microsoft Employee
    2025-05-09T21:55:00.41+00:00

    Hi @Vijay Prime

    Thank you for using Azure Document Intelligence. Based on screenshot (thanks for providing), you've trained a custom model, and the "Mechanical Properties" field is of type 'Fixed Table'.

    In the JSON API response, you’ll find this table under (example for 'Tests''Hardness' cell):

    analyzeResult.documents[0].fields["Mechanical Properties"].valueObject["Tests"].valueObject["Hardness"]
    

    'Fixed Table' fields are represented as a "dictionary of dictionary".

    Below is a C# sample (based on Custom_extraction_model.cs ) showing how to process 'Fixed Table' output:

    //...
    DocumentIntelligenceClient client = new DocumentIntelligenceClient(new Uri(endpoint), credential);
    var analyzeOptions = new AnalyzeDocumentOptions(modelId, BinaryData.FromBytes(File.ReadAllBytes("c:\\temp\\SampleMechProp.png"))); // use your own local file
    Operation<AnalyzeResult> operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, analyzeOptions);
    AnalyzeResult result = operation.Value;
    Console.WriteLine($"Document was analyzed with model with ID: {result.ModelId}");
    foreach (AnalyzedDocument document in result.Documents)
    {
        foreach (var (fieldName, field) in document.Fields)
        {
            Console.WriteLine($"Field '{fieldName}': ");
    
            // Illustration how to read output of Fixed Tables.
            if (field.FieldType == DocumentFieldType.Dictionary) 
            {
                var columnHeaders = field.ValueDictionary.SelectMany(rowField => rowField.Value.ValueDictionary.Keys).Distinct().ToList();
                Console.WriteLine("{0,-15} {1}", "_RowKey_", string.Join(" ", columnHeaders.Select(h => $"{h,-15}")));
                Console.WriteLine(new string('-', 15 + columnHeaders.Count * 15));
                foreach (var (rowKey, rowValue) in field.ValueDictionary)
                {
                    // Using value.Content for simplicity, but value.Value%Type% can be used to get normalized value of the subfield.
                    var rowValues = columnHeaders.Select(subFieldName => rowValue.ValueDictionary.TryGetValue(subFieldName, out var value) ? value.Content ?? "" : "").ToList(); 
                    Console.WriteLine("{0,-15} {1}", rowKey, string.Join(" ", rowValues.Select(v => $"{v,-15}")));
                }
            }
            else
            {
                Console.WriteLine($"Content: '{field.Content}'");
            }
        }
    }
    
    

    I trained a sample model (similar to your) and ran this code. It prints:

    Document was analyzed with model with ID: SampleFixedTableCustomer
    Field 'Mechanical Properties':
    _row_           Hardness        Elongation %
    ---------------------------------------------
    Min             137             22.00
    Max             197
    Actual          143,146,149     30.46
    
    

    Please let me know if this doesn’t work for you.

    Note: Install and reference the Azure.AI.DocumentIntelligence C# SDK v1.0.0 (not any 1.0.0-beta.x versions).

    Best Regards,
    =Anatoly=

    0 comments No comments

Your answer