Skip to content

fix(types): add optional name field to ChatCompletionToolMessageParam#2945

Open
DanielDerefaka wants to merge 1 commit intoopenai:mainfrom
DanielDerefaka:fix/chat-completion-tool-message-name
Open

fix(types): add optional name field to ChatCompletionToolMessageParam#2945
DanielDerefaka wants to merge 1 commit intoopenai:mainfrom
DanielDerefaka:fix/chat-completion-tool-message-name

Conversation

@DanielDerefaka
Copy link

Summary

Fixes #1078

The OpenAI docs for parallel function calling include a name field in tool result messages:

messages.append({
    "tool_call_id": tool_call.id,
    "role": "tool",
    "name": function_name,  # documented but not typed
    "content": function_response,
})

However, ChatCompletionToolMessageParam did not include this field, causing mypy/pyright type errors for users following the official docs.

Changes

  • Added optional name: Optional[str] field to ChatCompletionToolMessageParam
  • Mirrors the name field already present on ChatCompletionFunctionMessageParam
  • Fully backwards compatible — no existing code is affected

Verification

from openai.types.chat import ChatCompletionToolMessageParam

def tool_result(tool_call_id: str, name: str, content: str) -> ChatCompletionToolMessageParam:
    return {
        "tool_call_id": tool_call_id,
        "role": "tool",
        "name": name,   # now type-checks cleanly
        "content": content,
    }

Passes mypy and pyright without errors.

The OpenAI docs for parallel function calling include a `name` field in
tool result messages, but `ChatCompletionToolMessageParam` did not expose
this field, causing mypy/pyright type errors when users followed the docs.

Adds an optional `name: Optional[str]` field consistent with other message
param types and the API's own documentation examples.

Fixes openai#1078
@DanielDerefaka DanielDerefaka requested a review from a team as a code owner March 9, 2026 00:36
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7086635fe3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

tool_call_id: Required[str]
"""Tool call that this message is responding to."""

name: Optional[str]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Type name as non-null when present

ChatCompletionToolMessageParam is a TypedDict(total=False), so marking name as Optional[str] makes type checkers accept an explicit "name": None payload, not just omission. That widens the request type beyond the rest of chat message params (which model optional string fields as name: str) and can lead users to send null for name, which is likely rejected where a string is expected. The field should be optional-by-presence only, i.e. name: str.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ChatCompletionToolMessageParam should have an optional name property

1 participant