ProvenPin Install

LangChain.js prompt + model + parser chain tested with a fake chat model: working versions (tested 2026-10-15)

Compose a ChatPromptTemplate, chat model and output parser with LCEL in @langchain/core, tested offline with FakeListChatModel.

passed4 passed · 0 failed2026-10-15 13:31 UTC
Status
passed
Last passed
2026-10-15 13:31 UTC
Tests
4 / 4
Language
TypeScript
Runtime
node v22.23.3
pinned versions4
@langchain/core@1.2.17zod@4.6.7tsx@4.23.15@types/node@24.19.2
run it
npm install --no-audit --no-fund --ignore-scripts=false
npm test
test environment
node v22.23.3
linux 6.17.0-1022-azure
x64
runner: github-actions 38742087302

The code

Exactly the files that passed. Your agent can pull them with get_recipe("langchain-core-fake-model-chain") (install), or see them on GitHub.

package.json
{
  "name": "langchain-core-fake-model-chain",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node --import tsx --test test/*.test.ts"
  },
  "dependencies": {
    "@langchain/core": "1.2.17",
    "zod": "4.6.7"
  },
  "devDependencies": {
    "tsx": "4.23.15",
    "@types/node": "24.19.2"
  }
}
src/chain.ts
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { StringOutputParser } from "@langchain/core/output_parsers";
import type { BaseChatModel } from "@langchain/core/language_models/chat_models";
import { z } from "zod";

const prompt = ChatPromptTemplate.fromMessages([
  ["system", "Classify the support ticket. Reply with JSON: {{\"category\": \"billing\"|\"bug\"|\"other\", \"urgent\": boolean}}"],
  ["human", "{ticket}"],
]);
const Result = z.object({ category: z.enum(["billing", "bug", "other"]), urgent: z.boolean() });

export function buildClassifier(model: BaseChatModel) {
  const chain = prompt.pipe(model).pipe(new StringOutputParser());
  return async (ticket: string) => {
    const raw = await chain.invoke({ ticket });
    const json = raw.replace(/^```(json)?\s*|```\s*$/g, "").trim(); // models often wrap JSON in fences
    return Result.parse(JSON.parse(json));
  };
}

export const formatPrompt = (ticket: string) => prompt.formatMessages({ ticket });
test/chain.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { FakeListChatModel } from "@langchain/core/utils/testing";
import { buildClassifier, formatPrompt } from "../src/chain.ts";

test("parses plain JSON output", async () => {
  const classify = buildClassifier(new FakeListChatModel({ responses: ['{"category":"billing","urgent":true}'] }));
  assert.deepEqual(await classify("I was charged twice!"), { category: "billing", urgent: true });
});

test("strips markdown fences", async () => {
  const classify = buildClassifier(new FakeListChatModel({ responses: ['```json\n{"category":"bug","urgent":false}\n```'] }));
  assert.deepEqual(await classify("button broken"), { category: "bug", urgent: false });
});

test("rejects out-of-schema output", async () => {
  const classify = buildClassifier(new FakeListChatModel({ responses: ['{"category":"sales","urgent":"yes"}'] }));
  await assert.rejects(classify("hi"));
});

test("prompt escapes literal braces and fills the variable", async () => {
  const msgs = await formatPrompt("hello");
  assert.match(String(msgs[0].content), /"category"/);
  assert.equal(msgs[1].content, "hello");
});

Connect to ProvenPin

Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.

terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp

Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.