Table of Contents

Class StructuredOutputParser<T>

Namespace
AiDotNet.Postprocessing.Document
Assembly
AiDotNet.dll

StructuredOutputParser - Parses document AI outputs into structured data formats.

public class StructuredOutputParser<T> : PostprocessorBase<T, string, Dictionary<string, string>>, IPostprocessor<T, string, Dictionary<string, string>>, IDisposable

Type Parameters

T

The numeric type for calculations.

Inheritance
StructuredOutputParser<T>
Implements
Inherited Members

Remarks

StructuredOutputParser converts raw model outputs and OCR results into structured formats like JSON, tables, key-value pairs, and custom schemas.

For Beginners: AI models output text, but applications need structured data. This tool bridges that gap:

  • Convert OCR text to JSON
  • Extract key-value pairs
  • Build tabular data
  • Validate against schemas

Key features:

  • Multiple output formats
  • Schema validation
  • Custom parsing rules
  • Error handling

Example usage:

var parser = new StructuredOutputParser<float>();
var kvPairs = parser.Process(documentText);

Constructors

StructuredOutputParser()

Creates a new StructuredOutputParser with default settings.

public StructuredOutputParser()

Properties

SupportsInverse

Structured output parser does not support inverse transformation.

public override bool SupportsInverse { get; }

Property Value

bool

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Dispose(bool)

Releases resources used by the parser.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

ParseForm(string, IEnumerable<string>)

Parses a form into a structured object.

public Dictionary<string, string> ParseForm(string text, IEnumerable<string> fieldLabels)

Parameters

text string

The form text.

fieldLabels IEnumerable<string>

Labels to look for.

Returns

Dictionary<string, string>

Dictionary of field labels to values.

ParseInvoice(string)

Parses an invoice into a structured format.

public InvoiceData ParseInvoice(string text)

Parameters

text string

Returns

InvoiceData

ParseKeyValuePairs(string)

Parses text into key-value pairs.

public Dictionary<string, string> ParseKeyValuePairs(string text)

Parameters

text string

The text to parse.

Returns

Dictionary<string, string>

Dictionary of extracted key-value pairs.

ParseReceipt(string)

Parses a receipt into a structured format.

public ReceiptData ParseReceipt(string text)

Parameters

text string

Returns

ReceiptData

ParseTable(string, string)

Parses tabular text into a list of rows.

public IList<IList<string>> ParseTable(string text, string delimiter = "\t")

Parameters

text string

The text containing tabular data.

delimiter string

The column delimiter.

Returns

IList<IList<string>>

List of rows, each row being a list of cell values.

ParseTableWithHeaders(string, string)

Parses tabular text into a list of dictionaries using the first row as headers.

public IList<Dictionary<string, string>> ParseTableWithHeaders(string text, string delimiter = "\t")

Parameters

text string
delimiter string

Returns

IList<Dictionary<string, string>>

ParseToJson(string, IEnumerable<FieldExtractionRule>)

Parses text into a JSON object based on extraction rules.

public string ParseToJson(string text, IEnumerable<FieldExtractionRule> fieldRules)

Parameters

text string

The text to parse.

fieldRules IEnumerable<FieldExtractionRule>

Rules for extracting fields.

Returns

string

JSON string representation of extracted data.

ProcessCore(string)

Parses text into key-value pairs.

protected override Dictionary<string, string> ProcessCore(string input)

Parameters

input string

The text to parse.

Returns

Dictionary<string, string>

Dictionary of extracted key-value pairs.

ValidateAgainstSchema(Dictionary<string, object?>, DocumentSchema)

Validates parsed data against a schema.

public ValidationResult ValidateAgainstSchema(Dictionary<string, object?> data, DocumentSchema schema)

Parameters

data Dictionary<string, object>
schema DocumentSchema

Returns

ValidationResult

ValidateInput(string)

Validates the input text.

protected override void ValidateInput(string input)

Parameters

input string