Method SchemaDiscoveryAsync
- Namespace
- LMKit.Extraction
- Assembly
- LM-Kit.NET.dll
SchemaDiscoveryAsync(CancellationToken)
Asynchronously discovers an optimal JSON Schema for the current input content.
public Task<string> SchemaDiscoveryAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenA token that can be used to cancel the operation while schema discovery is running.
Returns
Examples
var te = new TextExtraction(LM.LoadFromModelID("lmkit-tasks:4b-preview"));
te.SetContent(""'Hello World' blog post by Alice (2025-08-15)"");
string schemaJson = await te.SchemaDiscoveryAsync();
te.SetElementsFromJsonSchema(schemaJson);
var result = await te.ParseAsync();
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 asynchronous method does not block the calling thread. In purely synchronous contexts, use SchemaDiscovery(CancellationToken) instead.
Exceptions
- InvalidOperationException
Thrown when no content has been provided before calling this method.
- See Also