`Json` response type in Assistant

Recent updates to OpenAI assistant allows us to have output from Assistant in json mode.

I am getting bad request error:

openai.BadRequestError: Error code: 400 - {'error': {'message': 'Runs with `response_format` of type `json_object` type are only compatible if all tools are type `function`.', 'type': 'invalid_request_error', 'param': 'response_format', 'code': None}}

If I try to create an assistant in Python using:

assistant = client.beta.assistants.create(
        name=f"Test Assistant",
        instructions=<SOME INSTRUCTION>,
        tools=[{"type": "code_interpreter"}],
        response_format={"type": "json_object"},

It seems you can’t use tool code interpretor if you want to use json_mode as response. I am not sure about why such a restriction exists.

  • Code interpreter is powered by a tool called python, not a tool for all functions
  • The python tool internal to assistants does not take output with arguments in json
  • The response_format would affect all AI generation after the AI emits tokens for tools or to decide to respond to the user.
  • The result would be python receiving a loop of tabs or linefeeds until the max_tokens is hit, getting an error return, and then trying again multiple times.