ChatClientStructuredOutputExtensions extension

Provides extension methods on ChatClient that simplify working with structured output.

Because the port performs no runtime reflection, callers supply the JSON Map schema describing the expected shape and a StructuredResultFromJson callback that converts the decoded JSON into the result type (upstream derives both from T via AIJsonUtilities).

on
Annotations
  • @Source(name: 'ChatClientStructuredOutputExtensions.cs', namespace: 'Microsoft.Extensions.AI', repository: 'dotnet/extensions', path: 'src/Libraries/Microsoft.Extensions.AI/ChatCompletion/')

Methods

getStructuredResponse<T>({required Iterable<ChatMessage> messages, required Map<String, dynamic> schema, required StructuredResultFromJson<T> fromJson, String? schemaName, String? schemaDescription, ChatOptions? options, bool? useJsonSchemaResponseFormat, CancellationToken? cancellationToken}) Future<StructuredChatResponse<T>>

Available on ChatClient, provided by the ChatClientStructuredOutputExtensions extension

Sends chat messages, requesting a response matching schema and deserialized via fromJson.