[GH-ISSUE #401] Cannot use structured outputs with Openai & providerStrategy #258

Closed
opened 2026-06-05 17:21:19 -04:00 by yindo · 1 comment
Owner

Originally created by @brnkes on GitHub (Apr 1, 2026).
Original GitHub issue: https://github.com/langchain-ai/deepagentsjs/issues/401

How to reproduce

Pull this example from docs : https://docs.langchain.com/oss/javascript/deepagents/customization#structured-output

Fix it (mentioned here : https://github.com/langchain-ai/docs/issues/2737). Specify an openai model :

const agent = createDeepAgent({
    model: new ChatOpenAIResponses({ model: 'gpt-5.4', apiKey: process.env.OPENAI_API_KEY }),
    responseFormat: providerStrategy(weatherReportSchema),
    tools: [internetSearch]
  });

I get the following error :

Error running agent: MiddlewareError: 400 Invalid schema for function 'grep': In context=(), 'required' is required to be supplied and to be an array including every key in properties. Missing 'glob'.

I suspect that this is because https://github.com/langchain-ai/deepagentsjs/blob/main/libs/deepagents/src/middleware/fs.ts#L776 uses nullable which causes the json schema to omit glob from required.

[...]
{
  [...]
  "properties": {
    "pattern": {
      "type": "string"
    },
    "path": {
      "default": "/",
      "type": "string"
    },
    "glob": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "required": [
    "pattern",
    "path"
  ],
  "additionalProperties": false
}
[...]

Partial workarounds

I flipped to a regular Langchain agent to smoke test whether this happens without deepagents' middlewares and it indeed doesn't error out.

And these hide the initial exception :

  • Using toolStrategy in lieu of providerStrategy
  • Disabling strict mode - i.e. { schema: weatherReportSchema, strict: false }

but are not viable workarounds. I seldom, but consistently, get incorrect outputs with either option : The output tool call is not invoked or it returns malformed jsons, respectively. I need to use strict mode.

Originally created by @brnkes on GitHub (Apr 1, 2026). Original GitHub issue: https://github.com/langchain-ai/deepagentsjs/issues/401 # How to reproduce Pull this example from docs : https://docs.langchain.com/oss/javascript/deepagents/customization#structured-output Fix it (mentioned here : https://github.com/langchain-ai/docs/issues/2737). Specify an openai model : ``` const agent = createDeepAgent({ model: new ChatOpenAIResponses({ model: 'gpt-5.4', apiKey: process.env.OPENAI_API_KEY }), responseFormat: providerStrategy(weatherReportSchema), tools: [internetSearch] }); ``` I get the following error : ``` Error running agent: MiddlewareError: 400 Invalid schema for function 'grep': In context=(), 'required' is required to be supplied and to be an array including every key in properties. Missing 'glob'. ``` I suspect that this is because https://github.com/langchain-ai/deepagentsjs/blob/main/libs/deepagents/src/middleware/fs.ts#L776 uses `nullable` which causes the json schema to omit `glob` from `required`. ``` [...] { [...] "properties": { "pattern": { "type": "string" }, "path": { "default": "/", "type": "string" }, "glob": { "anyOf": [ { "type": "string" }, { "type": "null" } ] } }, "required": [ "pattern", "path" ], "additionalProperties": false } [...] ``` # Partial workarounds I flipped to a regular Langchain agent to smoke test whether this happens without deepagents' middlewares and it indeed doesn't error out. And these hide the initial exception : - Using `toolStrategy` in lieu of `providerStrategy` - Disabling strict mode - i.e. `{ schema: weatherReportSchema, strict: false }` but are not viable workarounds. I seldom, but consistently, get incorrect outputs with either option : The output tool call is not invoked or it returns malformed jsons, respectively. I _need_ to use strict mode.
yindo closed this issue 2026-06-05 17:21:19 -04:00
Author
Owner

@JadenKim-dev commented on GitHub (Apr 2, 2026):

looks like the glob field just needed a .default(null). Opened a fix in #422

<!-- gh-comment-id:4176684848 --> @JadenKim-dev commented on GitHub (Apr 2, 2026): looks like the glob field just needed a `.default(null)`. Opened a fix in #422
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/deepagentsjs#258