fix(cookbook): use structured output in JS LangChain prompt example#3198
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@claude review |
There was a problem hiding this comment.
LGTM — small docs cookbook fix moving from the deprecated bind/pipe parser to withStructuredOutput.
Extended reasoning...
Overview
This PR updates the JS LangChain prompt management cookbook (one .mdx + matching .ipynb) to replace the stale model.bind({functions, function_call}).pipe(new JsonOutputFunctionsParser()) pattern with model.withStructuredOutput(schema, { method: 'functionCalling' }), plus a heading rename to match the new API.
Security risks
None. This is a docs/cookbook change with no production code, no auth/crypto/permissions surface, and no new external network or filesystem behavior.
Level of scrutiny
Low. This is a documentation-only change in a cookbook example, mechanical in nature, and follows the now-standard LangChain JS API. The diff is small (~15 lines net), and the .mdx and .ipynb are kept in sync. The author also re-landed this carefully (per recent commit history: revert then re-apply), suggesting it was already vetted.
Other factors
A pre-existing nit was surfaced as an inline comment about the duplicate ## Example 1 heading — not a defect introduced by this PR, and not worth blocking. Vercel preview is green.
f6c492d to
f1330f7
Compare
04c55fb to
900a060
Compare
What changed
Updates the JS LangChain prompt management cookbook to use the current LangChain structured output API.
The previous example used
JsonOutputFunctionsParserfromlangchain/output_parserstogether withmodel.bind(...).pipe(parser). With the current LangChain JS packages, that path is stale:model.bindis no longer available onChatOpenAI, whilewithStructuredOutput(...)is the supported path for function-calling based structured output.Why
This keeps the cookbook runnable with current LangChain JS versions and avoids a stale output parser import.
Related
Fixes Linear: LF-2221
Greptile Summary
Replaces a stale LangChain JS structured-output pattern (
JsonOutputFunctionsParser+model.bind().pipe(parser)) with the currentmodel.withStructuredOutput()API in both the MDX cookbook and its paired Jupyter notebook. The section heading is also updated to match the new approach.JsonOutputFunctionsParserimport and its instantiation, eliminating a dependency on the now-unsupportedlangchain/output_parserspath.model.withStructuredOutput(extractionFunctionSchema, { method: \"functionCalling\" }), which is the recommended API for function-calling-based structured output in current@langchain/openaiversions — the\"functionCalling\"method value is confirmed by the official LangChain JS reference docs.Confidence Score: 5/5
Safe to merge — both changed files are updated consistently and the new API call is correct per official LangChain JS docs.
The migration replaces two removed APIs (model.bind and JsonOutputFunctionsParser) with withStructuredOutput, which is the current recommended path. The method: "functionCalling" camelCase value is confirmed correct by the LangChain JS reference. Both the MDX file and the paired notebook are updated in sync, so no version drift between the two formats.
No files require special attention.
Sequence Diagram
%%{init: {'theme': 'neutral'}}%% sequenceDiagram participant User as User Code participant Langfuse participant Model as ChatOpenAI participant OpenAI as OpenAI API Note over User,OpenAI: Before (stale) User->>Langfuse: langfuse.prompt.get("extractor") Langfuse-->>User: extractorPrompt User->>Model: "model.bind({ functions, function_call }).pipe(JsonOutputFunctionsParser)" Model->>OpenAI: function_call request OpenAI-->>Model: raw function call response Model-->>User: parsed JSON via parser Note over User,OpenAI: After (current API) User->>Langfuse: langfuse.prompt.get("extractor") Langfuse-->>User: extractorPrompt User->>Model: "model.withStructuredOutput(schema, { method: "functionCalling" })" Model->>OpenAI: function calling request OpenAI-->>Model: structured response Model-->>User: parsed JSON (built-in)%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% sequenceDiagram participant User as User Code participant Langfuse participant Model as ChatOpenAI participant OpenAI as OpenAI API Note over User,OpenAI: Before (stale) User->>Langfuse: langfuse.prompt.get("extractor") Langfuse-->>User: extractorPrompt User->>Model: "model.bind({ functions, function_call }).pipe(JsonOutputFunctionsParser)" Model->>OpenAI: function_call request OpenAI-->>Model: raw function call response Model-->>User: parsed JSON via parser Note over User,OpenAI: After (current API) User->>Langfuse: langfuse.prompt.get("extractor") Langfuse-->>User: extractorPrompt User->>Model: "model.withStructuredOutput(schema, { method: "functionCalling" })" Model->>OpenAI: function calling request OpenAI-->>Model: structured response Model-->>User: parsed JSON (built-in)Reviews (1): Last reviewed commit: "fix js langchain prompt cookbook structu..." | Re-trigger Greptile