fix(models): reject unpaired function calls in Chat Completions - #4702
Closed
ayaangazali wants to merge 1 commit into
Closed
fix(models): reject unpaired function calls in Chat Completions#4702ayaangazali wants to merge 1 commit into
ayaangazali wants to merge 1 commit into
Conversation
openai#4699 made an unpaired function_call_output raise an actionable UserError because Chat Completions cannot represent it. A function_call has the same optional call_id and the branch above it still subscripts func_call["call_id"] directly, so the same shape raises KeyError: 'call_id' instead. The input reaches the converter through an ordinary hand-built input list, and a Responses model converts it and reaches the transport, so this is the same capability difference openai#4699 documented rather than an invalid input. Raise the parallel UserError so both halves of the pair fail the same way.
Member
|
ResponseFunctionToolCallParam.call_id is a required string, and the function-calling contract pairs each function call and output through that ID. An omitted or null call_id is therefore malformed hand-built input rather than a supported Responses input shape. The proposed error also states that Responses supports unpaired function calls, which is not part of the documented contract. Improving the exception type for an invalid synthetic value is not enough reason to add another provider-conversion branch, so I am closing this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
#4699 made an unpaired
function_call_outputraise an actionableUserError, because Chat Completions has no way to represent it. The branch immediately above it has the same shape and was not covered:call_idis optional on bothResponseFunctionToolCallParamandFunctionCallOutput, so a function call without one is exactly as constructible as the output that #4699 now rejects. Today the two halves of the same pair fail differently:This is reachable from an ordinary hand-built input list, and it fails in conversion before anything is sent:
It is also the same capability difference #4699 described, not invalid input. Running that identical input against a Responses model converts cleanly and reaches the transport, failing only on the connection. So Responses preserves the item and Chat Completions cannot, which is exactly the case the existing message is worded for.
The change raises the parallel
UserErrorso both halves of the pair fail the same actionable way. Provenance for the two sides: the output guard landed one commit ago in #4699, while the call-side subscript has been unguarded since #522 extracted this converter, so the asymmetry is an uncovered branch rather than a deliberate split.Test plan
tests/models/test_openai_chatcompletions.py::test_unpaired_function_call_rejected_before_chat_request, written to mirror the #4699 test directly: sameMockTransporthandler that fails if a request is ever issued, and the same parametrization over an omitted versus explicitly nullcall_id, streaming versus non streaming, and default versus strict feature validation. Eight cases, and it asserts no request reached the wire.Verified it fails without the source change by reverting
src/: all eight fail, each withKeyError: 'call_id'..agents/skills/code-change-verification/scripts/run.shpasses end to end: format, lint, typecheck and the full suite.Issue number
None. Found while sibling-checking #4699.
Checks
.agents/skills/code-change-verification/scripts/run.sh/reviewbefore submitting this PRThis is just the other half of #4699, so the wording and the test structure are deliberately copied from it rather than reinvented. If you would rather the two branches shared one guard instead of two parallel messages, say so and I will fold them together. I'm a freshman in college and I found this by checking whether the fix you just merged had a sibling one branch up.