Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/silver-dingos-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"langchain": patch
---

fix(langchain): Bind schemas for other types of pulled hub prompts
32 changes: 22 additions & 10 deletions langchain/src/hub/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,29 @@ export function bindOutputSchema<T extends Runnable>(loadedSequence: T) {
"schema" in loadedSequence.first &&
"last" in loadedSequence &&
loadedSequence.last !== null &&
typeof loadedSequence.last === "object" &&
"bound" in loadedSequence.last &&
loadedSequence.last.bound !== null &&
typeof loadedSequence.last.bound === "object" &&
"withStructuredOutput" in loadedSequence.last.bound &&
typeof loadedSequence.last.bound.withStructuredOutput === "function"
typeof loadedSequence.last === "object"
) {
// eslint-disable-next-line no-param-reassign
loadedSequence.last.bound = loadedSequence.last.bound.withStructuredOutput(
loadedSequence.first.schema
);
if (
"bound" in loadedSequence.last &&
loadedSequence.last.bound !== null &&
typeof loadedSequence.last.bound === "object" &&
"withStructuredOutput" in loadedSequence.last.bound &&
typeof loadedSequence.last.bound.withStructuredOutput === "function"
) {
// eslint-disable-next-line no-param-reassign
loadedSequence.last.bound =
loadedSequence.last.bound.withStructuredOutput(
loadedSequence.first.schema
);
} else if (
"withStructuredOutput" in loadedSequence.last &&
typeof loadedSequence.last.withStructuredOutput === "function"
) {
// eslint-disable-next-line no-param-reassign
loadedSequence.last = loadedSequence.last.withStructuredOutput(
loadedSequence.first.schema
);
}
}
return loadedSequence;
}
12 changes: 12 additions & 0 deletions langchain/src/hub/tests/hub.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ test("Test LangChain Hub while loading model with dynamic imports and structured
expect(typeof res.correctness).toBe("boolean");
});

test("Test LangChain Hub while loading model with dynamic imports and structured output with no binding", async () => {
const pulledPrompt = await nodePull("jacob/structured-output-2", {
includeModel: true,
});
const res = await pulledPrompt.invoke({
input:
"Who is the current president of the USA as of today? You must use the provided tool for the latest info.",
});
expect(res).not.toBeInstanceOf(AIMessage);
expect(typeof res.correctness).toBe("boolean");
});

test("Test LangChain Hub while loading model not defined in a RunnableBinding", async () => {
const promptA = await nodePull("hntrl/binding-manifest", {
includeModel: true,
Expand Down
Loading