Skip to content

Conversation

@sdip0971
Copy link
Contributor

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!

@changeset-bot
Copy link

changeset-bot bot commented Jul 14, 2025

🦋 Changeset detected

Latest commit: 30f8eba

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@langchain/langgraph Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dqbd dqbd changed the title fix: respect strict option in responseFormat inside createReactAgent fix(langgraph): respect strict option in responseFormat inside createReactAgent Jul 16, 2025
@dqbd dqbd merged commit 6e616f5 into langchain-ai:main Jul 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Need strict option to ReAct Agent's responseFormat for JSON Schema

2 participants