How to Make Assistant Return JSON?

Hi everyone.

Is there a way to use the json_object response format with the assistant api?

I’ve tried the following but it brings up an “extra fields not permitted” error.


const myAssistant = await openai.beta.assistants.create({
      instructions:
        "Cool instruction",
      name: "Cool Assistant",
      tools: [{ type: "retrieval" }],
      model: "gpt-4-1106-preview",
      response_format: {type: "json_object"},
      file_ids: [],
    });

error:

BadRequestError: 400 1 validation error for Request
body → response_format
extra fields not permitted (type=value_error.extra)

Afraid JSON mode is not yet supported in the Assistants API, as of Nov 2023.

5 Likes

I am taking the assistant output and passing it though the chat completion with json mode enabled. It’s a little clunky but it works until its supported directly.

2 Likes

+1 for this feature. Was so excited about json mode and also Assistants. Bummer that it doesn’t work yet for assistants.