Table of Contents

Method SchemaDiscovery

Namespace
LMKit.Extraction
Assembly
LM-Kit.NET.dll

SchemaDiscovery(CancellationToken)

Discovers an optimal JSON Schema for the current input content.

public string SchemaDiscovery(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that can be used to cancel the operation. Cancellation is best-effort; if cancellation is requested during model generation, the operation may stop early or throw.

Returns

string

A JSON string representing a single JSON Schema (draft-07) object that describes the structure inferred from the input content.

Examples

var te = new TextExtraction(LM.LoadFromModelID("lmkit-tasks:4b-preview"));
te.SetContent(""\#123 Order: 2x Widget @ 9.99, 1x Gadget @ 4.50"");
string schemaJson = te.SchemaDiscovery();
te.SetElementsFromJsonSchema(schemaJson);
var result = te.Parse();
Console.WriteLine(result.Json);

Remarks

This method analyzes the content previously supplied via SetContent(string), SetContent(Attachment), or SetContent(IEnumerable<Attachment>) and prompts the underlying language model to propose a minimal JSON Schema (draft-07) that captures the structure present in the content.

The discovered schema is returned as a JSON string containing a single JSON object. You can feed it back into the extractor by calling SetElementsFromJsonSchema(string) to configure Elements automatically.

This synchronous method blocks the calling thread. In asynchronous or UI contexts, use SchemaDiscoveryAsync(CancellationToken) instead.

Exceptions

InvalidOperationException

Thrown when no content has been provided before calling this method.