openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

ChatCompletionNamedToolChoiceParam does not match the object specified in the documentation

Open raphael-foliveira opened this issue 11 months ago • 2 comments

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

  • [x] This is an issue with the Python library

Describe the bug

The object can be found here.

While the official docs states:

tool_choice: {"type": "function", "name": "get_weather"}

To Reproduce

Check the docs in the link provided

Code snippets


OS

any

Python version

any

Library version

2.9.0

raphael-foliveira avatar Dec 09 '25 17:12 raphael-foliveira

Clarification

Looking at the current implementation and the OpenAI API specification, the SDK appears to be correct. The proper format for forcing a specific function call is:

tool_choice={"type": "function", "function": {"name": "get_weather"}}
The current 
ChatCompletionNamedToolChoiceParam

correctly implements this nested structure:

class ChatCompletionNamedToolChoiceParam(TypedDict, total=False):
    function: Required[Function]  # {"name": "..."}
    type: Required[Literal["function"]]

If the official documentation shows the flattened format {"type": "function", "name": "get_weather"} without the nested function object, that may be a documentation error on the OpenAI docs side rather than an SDK issue.

Could you confirm where you saw the simplified format? A link to the specific documentation would help clarify whether this is a docs issue or an API behavior change.

sahiee-dev avatar Jan 01 '26 11:01 sahiee-dev

Sorry it took me so long to answer. It looks like it was indeed a documentation error on OpenAI's side, and it has now been fixed. Thank you!

raphael-foliveira avatar Jan 26 '26 12:01 raphael-foliveira