Skip to content

Error when supplying model with function (tool) call result obtained via the responses.parse method #2374

Open
@JovanVeljanoski

Description

@JovanVeljanoski

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • This is an issue with the Python library

Describe the bug

Hi team!

I believe there is a bug when trying to update the message list with a function call results when one is using the responses.parse method.

Below I submit a working example that you can run to see the error. I also have a workaround.
The issue comes here:
When attaching the output to the message history, if one is using responses.parsed the output is of type ParsedResponseFunctionToolCall which contains the parsed_arguments property. The existence of this property raises and error.

openai.BadRequestError: Error code: 400 - {'error': {'message': "Unknown parameter: 'input[2].parsed_arguments'.", 'type': 'invalid_request_error', 'param': 'input[2].parsed_arguments', 'code': 'unknown_parameter'}}

Workaround:
This is a simple workaround: all you need to do is re-create the response output while removing the parsed_arguments:

mapping = dict(response.output[0])
del mapping['parsed_arguments']
messages.append(ParsedResponseFunctionToolCall(**mapping))

After this workaround - everything works as expected - but I think this should not be needed!


Honestly, i do not know if this is an issue with the openai python library or with the API, but I assume it is with the library.


To Reproduce

Execute the following code below to reproduce the issue.

The main bug here:

import openai
from openai.types.responses import ParsedResponseFunctionToolCall

client = openai.OpenAI()


messages = [
    {'role': 'developer', 'content': 'You are a pirate captain. You are a seasoned captain, and you give clear commands and updates.'},
    {'role': 'user', 'content': 'Do we expect a storm tonight captain?'},
    ParsedResponseFunctionToolCall(arguments='{}', call_id='call_DXbTc6kVdiZw16mSoNvWrYWD', name='CheckWeather', type='function_call', id='fc_682f45de491881988e8ab6de03e55c170900eec136ebb9a8', status='completed', parsed_arguments={'function': 'CheckWeather'}),
    {'type': 'function_call_output', 'call_id': 'call_DXbTc6kVdiZw16mSoNvWrYWD', 'output': 'Steady wind from the north, sunny, no clouds at all.'}
]


response = client.responses.parse(
    input=messages,
    model='gpt-4.1-nano-2025-04-14',
    store=False,
)

print(response.output_text)

The following example also fails, even though parsed_arguments is None (but it is explicitly specified)

messages = [
    {'role': 'developer', 'content': 'You are a pirate captain. You are a seasoned captain, and you give clear commands and updates.'},
    {'role': 'user', 'content': 'Do we expect a storm tonight captain?'},
    ParsedResponseFunctionToolCall(arguments='{}', call_id='call_DXbTc6kVdiZw16mSoNvWrYWD', name='CheckWeather', type='function_call', id='fc_682f45de491881988e8ab6de03e55c170900eec136ebb9a8', status='completed', parsed_arguments=None),
    {'type': 'function_call_output', 'call_id': 'call_DXbTc6kVdiZw16mSoNvWrYWD', 'output': 'Steady wind from the north, sunny, no clouds at all.'}
]


response = client.responses.parse(
    input=messages,
    model='gpt-4.1-nano-2025-04-14',
    store=False,
)

However, if we do not specify parsed_arguments, everything works as expected (hence the workaround)

messages = [
    {'role': 'developer', 'content': 'You are a pirate captain. You are a seasoned captain, and you give clear commands and updates.'},
    {'role': 'user', 'content': 'Do we expect a storm tonight captain?'},
    ParsedResponseFunctionToolCall(arguments='{}', call_id='call_DXbTc6kVdiZw16mSoNvWrYWD', name='CheckWeather', type='function_call', id='fc_682f45de491881988e8ab6de03e55c170900eec136ebb9a8', status='completed'),
    {'type': 'function_call_output', 'call_id': 'call_DXbTc6kVdiZw16mSoNvWrYWD', 'output': 'Steady wind from the north, sunny, no clouds at all.'}
]


response = client.responses.parse(
    input=messages,
    model='gpt-4.1-nano-2025-04-14',
    store=False,
)

Code snippets

import openai
from openai.types.responses import ParsedResponseFunctionToolCall

client = openai.OpenAI()


messages = [
    {'role': 'developer', 'content': 'You are a pirate captain. You are a seasoned captain, and you give clear commands and updates.'},
    {'role': 'user', 'content': 'Do we expect a storm tonight captain?'},
    ParsedResponseFunctionToolCall(arguments='{}', call_id='call_DXbTc6kVdiZw16mSoNvWrYWD', name='CheckWeather', type='function_call', id='fc_682f45de491881988e8ab6de03e55c170900eec136ebb9a8', status='completed', parsed_arguments={'function': 'CheckWeather'}),
    {'type': 'function_call_output', 'call_id': 'call_DXbTc6kVdiZw16mSoNvWrYWD', 'output': 'Steady wind from the north, sunny, no clouds at all.'}
]


response = client.responses.parse(
    input=messages,
    model='gpt-4.1-nano-2025-04-14',
    store=False,
)

print(response.output_text)

OS

macOS 15.4.1

Python version

Python v3.12.0

Library version

openai v1.81.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions