[PR #1389] [MERGED] fix(langgraph): respect strict option in responseFormat inside createReactAgent #1423

Closed
opened 2026-02-15 20:15:43 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/langgraphjs/pull/1389
Author: @sdip0971
Created: 7/14/2025
Status: Merged
Merged: 7/16/2025
Merged by: @dqbd

Base: mainHead: feat/strict-responseformat-support


📝 Commits (3)

  • 86adfb7 fix: respect strict option in responseFormat inside createReactAgent
  • 4d771a1 Lint, add tests for strict and other structured output kwargs
  • 30f8eba Create poor-avocados-guess.md

📊 Changes

3 files changed (+37 additions, -17 deletions)

View changed files

.changeset/poor-avocados-guess.md (+5 -0)
📝 libs/langgraph/src/prebuilt/react_agent_executor.ts (+20 -16)
📝 libs/langgraph/src/tests/prebuilt.test.ts (+12 -1)

📄 Description

Fixes langchain-ai/langgraphjs#1277

🛠️ What this PR does

This PR adds support for the strict flag inside the responseFormat option of createReactAgent.

Now, when strict: true is passed like:

responseFormat: {
  schema: SomeZodSchema,
  prompt: "Some system prompt",
  strict: true,
}

The LLM will correctly invoke:

model.withStructuredOutput(schema, { strict: true });

If strict is not passed, it will default to:

model.withStructuredOutput(schema);

🐛 The Problem

The strict flag was previously ignored in the logic block below:

if (typeof responseFormat === "object" && "prompt" in responseFormat && "schema" in responseFormat) {
  const { prompt, schema, strict } = responseFormat;
  model.withStructuredOutput(schema); // ⚠️ strict was never passed!
}

The Fix

  • Updated logic to respect strict flag and pass it to withStructuredOutput
  • Updated type definition of responseFormat to support { schema, strict }
responseFormat?: 
  | InteropZodType<StructuredResponseType>
  | StructuredResponseSchemaAndPrompt<StructuredResponseType>
  | { schema: InteropZodType<StructuredResponseType> | Record<string, any>; strict?: boolean }
  | Record<string, any>;

Let me know if tests need to be added or adjusted!


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langchain-ai/langgraphjs/pull/1389 **Author:** [@sdip0971](https://github.com/sdip0971) **Created:** 7/14/2025 **Status:** ✅ Merged **Merged:** 7/16/2025 **Merged by:** [@dqbd](https://github.com/dqbd) **Base:** `main` ← **Head:** `feat/strict-responseformat-support` --- ### 📝 Commits (3) - [`86adfb7`](https://github.com/langchain-ai/langgraphjs/commit/86adfb72ca5b41f9e8845682a77283d600538d7f) fix: respect strict option in responseFormat inside createReactAgent - [`4d771a1`](https://github.com/langchain-ai/langgraphjs/commit/4d771a1f290f69d1fcae5305810945ed84d1a257) Lint, add tests for strict and other structured output kwargs - [`30f8eba`](https://github.com/langchain-ai/langgraphjs/commit/30f8ebad4eeeddf546a8a9439e520d6ea9d2f06c) Create poor-avocados-guess.md ### 📊 Changes **3 files changed** (+37 additions, -17 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/poor-avocados-guess.md` (+5 -0) 📝 `libs/langgraph/src/prebuilt/react_agent_executor.ts` (+20 -16) 📝 `libs/langgraph/src/tests/prebuilt.test.ts` (+12 -1) </details> ### 📄 Description Fixes [langchain-ai/langgraphjs#1277](https://github.com/langchain-ai/langgraphjs/issues/1277) ## 🛠️ What this PR does This PR adds support for the `strict` flag inside the `responseFormat` option of `createReactAgent`. Now, when `strict: true` is passed like: ```ts responseFormat: { schema: SomeZodSchema, prompt: "Some system prompt", strict: true, } ``` The LLM will correctly invoke: ```ts model.withStructuredOutput(schema, { strict: true }); ``` If `strict` is not passed, it will default to: ```ts model.withStructuredOutput(schema); ``` --- ## 🐛 The Problem The `strict` flag was previously ignored in the logic block below: ```ts if (typeof responseFormat === "object" && "prompt" in responseFormat && "schema" in responseFormat) { const { prompt, schema, strict } = responseFormat; model.withStructuredOutput(schema); // ⚠️ strict was never passed! } ``` --- ## ✅ The Fix - ✅ Updated logic to respect `strict` flag and pass it to `withStructuredOutput` - ✅ Updated type definition of `responseFormat` to support `{ schema, strict }` ```ts responseFormat?: | InteropZodType<StructuredResponseType> | StructuredResponseSchemaAndPrompt<StructuredResponseType> | { schema: InteropZodType<StructuredResponseType> | Record<string, any>; strict?: boolean } | Record<string, any>; ``` --- Let me know if tests need to be added or adjusted! --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-15 20:15:43 -05:00
yindo closed this issue 2026-02-15 20:15:43 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#1423