Repository navigation
Description
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
parse_chat_completion(), which backs client.chat.completions.parse(), drops custom tool calls. when the model calls only a custom tool, the parsed message has tool_calls=None even though the raw completion contains the call. on a turn with both kinds, the function calls are kept and the custom ones are dropped.
root cause, on main @ f6e8480: the custom branch in src/openai/lib/_parsing/_completions.py only logs a warning and never appends the call (L136-L143), and the list it would append to is typed list[ParsedFunctionToolCall] (L117), so no parsed type can hold one.
To Reproduce
- build a chat completion whose message has one custom tool call (no network needed, snippet below)
- pass it through
parse_chat_completion - the raw completion has the call; the parsed message has
tool_calls=None
Code snippets
from openai.types.chat import ChatCompletion
from openai.lib._parsing._completions import parse_chat_completion
completion = ChatCompletion.model_validate({
"id": "chatcmpl-1", "object": "chat.completion", "created": 0, "model": "gpt-5",
"choices": [{
"index": 0, "finish_reason": "tool_calls", "logprobs": None,
"message": {
"role": "assistant", "content": None,
"tool_calls": [{
"id": "call_1", "type": "custom",
"custom": {"name": "code_exec", "input": "print('hi')"},
}],
},
}],
})
print("raw: ", [c.type for c in completion.choices[0].message.tool_calls])
parsed = parse_chat_completion(
response_format=None, input_tools=[{"type": "custom", "custom": {"name": "code_exec"}}],
chat_completion=completion,
)
print("parsed:", parsed.choices[0].message.tool_calls)output on 3.42.1:
Custom tool calls are not callable. Ignoring tool call: call_1 - code_exec
raw: ['custom']
parsed: None
suggested fix
the diff in #3505 appends the call in that branch. review on that pr found that appending alone is not enough: ParsedChatCompletionMessage.tool_calls is declared as list[ParsedFunctionToolCall], so an appended custom call is dumped as {id, type} and custom.name / custom.input are lost from model_dump(). the complete fix is to widen the parsed tool-call type to a discriminated union of ParsedFunctionToolCall and ChatCompletionMessageCustomToolCall in the generated source of truth, append in this branch, and add a regression test that dumps the whole parsed completion.
streaming is a separate gap: ChoiceDeltaToolCall.type is Optional[Literal["function"]] in 3.42.1, so a streamed custom call fails validation before it reaches this parser.
OS
macOS 26.6.2 (arm64)
Python version
3.13.13
Library version
3.42.1
Activity
Sainath-Reddy7 commentedon Nov 5, 2026
Reproduced the snippet against 3.42.1 — parsed
tool_callsisNonewhile the raw completion carries the custom call, matching the analysis of thecustombranch in_completions.py.If it would help, I'd be happy to work on the suggested fix (append in the
custombranch + widenParsedChatCompletionMessage.tool_callsto the discriminated union in the generated source, plus a whole-completion dump regression test) — or the streaming gap, if that's the preferred first step. Wanted to check the intended shape with maintainers first, since this touches the generated types.siddardh-core commentedon Nov 8, 2026
Hi @PranavMishra28, thanks for the detailed analysis and reproduction. I understand that custom tool calls are present in the raw completion but are lost during parsing, including their name and input fields. I would be interested in helping with the regression tests or a separate part of this issue if the maintainers need additional help. Is there any specific area that would be useful for another contributor to investigate?
PranavMishra28 commentedon Nov 9, 2026
@siddardh-core @Sainath-Reddy7 thanks for digging into this.
@siddardh-core, a useful test would cover both a custom-only completion and one with function + custom calls. The important check is the full completion’s
model_dump(): keeping the call in memory isn’t enough ifcustom.nameandcustom.inputdisappear during serialization. That came up in my earlier PR: #3505.@Sainath-Reddy7 I’d keep the first fix non-streaming. The current streaming delta type only allows function calls, so that needs separate direction rather than getting bundled into this fix.
One wrinkle: the repo now only accepts PRs from collaborators. We can share test cases here, but I don’t want either of you spending time preparing a PR you can’t submit. We still need maintainer guidance on the type change.
Sainath-Reddy7 commentedon Nov 9, 2026
Thanks @PranavMishra28 — here are those tests, ready for whoever implements the fix. I checked CONTRIBUTING and saw PRs are limited to collaborators, so posting them here instead.
Both are strict-xfail on the current release (
2 xfailedagainstopenai3.42.1): they turn green only when a custom call survives parsing andmodel_dump(); if the call is appended butcustom.name/custom.inputvanish from the dump (the #3505 review finding), they go XPASS and fail, which pins exactly the serialization check you called out.(Full payloads for
CUSTOM_ONLY/MIXEDare the minimal validChatCompletiondicts from the issue's reproduction; happy to attach the complete runnable file or a gist if preferred.)TejasLamba2006 commentedon Nov 9, 2026
I pushed a candidate fix to https://github.com/TejasLamba2006/openai-python/tree/fix/parse-custom-tool-calls. It preserves custom calls in
parse_chat_completion()and widens the parsed call type somodel_dump()retainscustom.nameandcustom.input. The regression test checks both parsed fields and serialized output.I could not open a pull request because repository policy restricts PRs to collaborators. The code is ready for a collaborator to review or submit.
siddardh-core commentedon Nov 10, 2026
Thank you, @PranavMishra28, @Sainath-Reddy7 and @TejasLamba2006 for investigating this issue and sharing the regression tests and candidate fix.
I understand the repository's collaborator-only PR restriction. I'll review the supplied test cases and focus on independently reproducing the serialization behaviour rather than preparing a duplicate implementation.
Thank you for clarifying the expected checks and the current limitations.