Submitting tool outputs back to assistant

I’m currently trying to set up an assistant that gets data from a notion page. However, for some reason I’m getting this error when submitting the tool outputs:

openai.BadRequestError: Error code: 400 - {‘error’: {‘message’: ‘1 validation error for Request\nbody → tool_outputs\n extra fields not permitted (type=value_error.extra)’, ‘type’: ‘invalid_request_error’, ‘param’: None, ‘code’: None}

This is the format of my tool output list:
[
{
“tool_call_id”: [current call id]
“output”: “Could not find page.”
}
]

As far as I can tell, this is the format the documentation wants, but it still says I have an extra field. I’m also using python by the way. Does anyone know whats up?

Depends on how you have defined your function’s json schema in the function calling tool.

For example, if you have defined a function with param as “result”, you can pass the output back to the assistant as:

tool_outputs=[
    {
      "tool_call_id": tool_call_id,
      "output": {"result": "your output data from notion page here"}
    }
  ]

I have made some assumptions here because I don’t have the complete info. So, hope this helps.

I guess I should’ve clarified. Right now I’m using the openai and notion packages in python to run the commands and API. The actual function seems to work fine, but when I use this to submit the string outputs I got from the function:

client.beta.threads.runs.submit_tool_outputs(
            thread_id=monathread,
            run_id=r,
            tool_outputs=[{
                "tool_call_id": callid, # current call id in the form of a string
                "output": "Test Successful!" # test string
            }]
        )

It gives me the BadRequestError mentioned above.
I’m not sure why, cause according to the API docs, this should be the correct format, no extra fields or anything.

Here is the example request from the API reference:

client = OpenAI()

run = client.beta.threads.runs.submit_tool_outputs(
  thread_id="thread_abc123",
  run_id="run_abc123",
  tool_outputs=[
    {
      "tool_call_id": "call_abc123",
      "output": "28C"
    }
  ]
)
print(run)

It doesn’t matter what I put for my tool_outputs argument, it seems to always be formatted incorrectly

I was talking about the function json you would have added in the function calling tool. Can you share that?

{
  "name": "get_page_content",
  "description": "Get the content from blocks on a page in the user's Notion based on a list of key word or phrase. Call this function a few times with different keywords that might relate to the user's request.",
  "parameters": {
    "type": "object",
    "properties": {
      "query": {
        "type": "string",
        "description": "Single keyword to search for in the page titles, e.g., ['Notes', 'Tasks']."
      }
    },
    "required": [
      "query"
    ]
  }
}

This is the function json

Hard to help without your actual code. Did you debug / check things like the tool_call_id? Json.dump to see?

Hi.

  1. Have you called the correct tool_call_id?
  2. I guess the output type from he function you’re calling. In javascript it would be something like JSON.parse(output) to parse the output from JSON format.

Try this. This might work

tool_outputs=[
    {
      "tool_call_id": tool_call_id,
      "output": '{"query": "your output data from notion page here"}'
    }
  ]