Add structured output to the model.
The OpenAI model family supports the following structured output methods:
jsonSchema: Use the response_format field in the response to return a JSON schema. Only supported with the gpt-4o-mini,
gpt-4o-mini-2024-07-18, and gpt-4o-2024-08-06 model snapshots and later.functionCalling: Function calling is useful when you are building an application that bridges the models and functionality
of your application.jsonMode: JSON mode is a more basic version of the Structured Outputs feature. While JSON mode ensures that model
output is valid JSON, Structured Outputs reliably matches the model's output to the schema you specify.
We recommend you use functionCalling or jsonSchema if it is supported for your use case.The default method is functionCalling.
withStructuredOutput<
RunOutput extends Record<string, any> = Record<string, any>
>(
outputSchema: Record<string, any> | InteropZodType<RunOutput>,
config: StructuredOutputMethodOptions<false>
): Runnable<BaseLanguageModelInput, RunOutput>| Name | Type | Description |
|---|---|---|
outputSchema* | Record<string, any> | InteropZodType<RunOutput> | |
config | StructuredOutputMethodOptions<false> |