Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 10 additions & 56 deletions libs/langchain-core/src/language_models/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,49 +560,15 @@ export abstract class BaseLanguageModel<
throw new Error("Use .toJSON() instead");
}

withStructuredOutput?<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
RunOutput extends Record<string, any> = Record<string, any>
>(
schema:
| ZodTypeV3<RunOutput>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
| Record<string, any>,
withStructuredOutput?<Output>(
schema: InteropZodType<Output> | JSONSchema,
config?: StructuredOutputMethodOptions<false>
): Runnable<BaseLanguageModelInput, RunOutput>;
): BaseLanguageModel<BaseMessage, CallOptions>;

withStructuredOutput?<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
RunOutput extends Record<string, any> = Record<string, any>
>(
schema:
| ZodTypeV3<RunOutput>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
| Record<string, any>,
withStructuredOutput?<Output>(
schema: InteropZodType<Output> | JSONSchema,
config?: StructuredOutputMethodOptions<true>
): Runnable<BaseLanguageModelInput, { raw: BaseMessage; parsed: RunOutput }>;

withStructuredOutput?<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
RunOutput extends Record<string, any> = Record<string, any>
>(
schema:
| ZodTypeV4<RunOutput>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
| Record<string, any>,
config?: StructuredOutputMethodOptions<false>
): Runnable<BaseLanguageModelInput, RunOutput>;

withStructuredOutput?<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
RunOutput extends Record<string, any> = Record<string, any>
>(
schema:
| ZodTypeV4<RunOutput>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
| Record<string, any>,
config?: StructuredOutputMethodOptions<true>
): Runnable<BaseLanguageModelInput, { raw: BaseMessage; parsed: RunOutput }>;
): BaseLanguageModel<{ raw: BaseMessage; parsed: Output }, CallOptions>;

/**
* Model wrapper that returns outputs formatted to match the given schema.
Expand All @@ -617,24 +583,12 @@ export abstract class BaseLanguageModel<
* @param {boolean | undefined} [includeRaw=false] Whether to include the raw output in the result. Defaults to false.
* @returns {Runnable<RunInput, RunOutput> | Runnable<RunInput, { raw: BaseMessage; parsed: RunOutput }>} A new runnable that calls the LLM with structured output.
*/
withStructuredOutput?<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
RunOutput extends Record<string, any> = Record<string, any>
>(
schema:
| InteropZodType<RunOutput>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
| Record<string, any>,
withStructuredOutput?<Output>(
schema: InteropZodType<Output> | JSONSchema,
config?: StructuredOutputMethodOptions<boolean>
):
| Runnable<BaseLanguageModelInput, RunOutput>
| Runnable<
BaseLanguageModelInput,
{
raw: BaseMessage;
parsed: RunOutput;
}
>;
| BaseLanguageModel<BaseMessage, CallOptions>
| BaseLanguageModel<{ raw: BaseMessage; parsed: Output }, CallOptions>;
}

/**
Expand Down
Loading