fix: apply empty-content guard to empty-string chat tool outputs#3395
Closed
ioleksiuk wants to merge 1 commit into
Closed
fix: apply empty-content guard to empty-string chat tool outputs#3395ioleksiuk wants to merge 1 commit into
ioleksiuk wants to merge 1 commit into
Conversation
Extends the fix in openai#3312 (`fix: avoid empty chat tool outputs`) to one case the original guard missed. openai#3312 added an empty-content guard that swaps the tool message body with `_OMITTED_TOOL_OUTPUT_PLACEHOLDER` when the converted content is empty. The guard was placed inside the `else` branch of the `isinstance(all_output_content, str)` check, so it only triggered when the output was a non-text-only list. When the output is the empty string `""`, `extract_all_content("")` returns `""` (the string branch), `tool_result_content` is set to `""` without ever reaching the guard, and the Chat Completions message ends up with `"content": ""` — exactly the broken shape openai#3310/openai#3312 aimed to prevent. Repro on current main: items = [ {"type": "function_call", "id": "fc_1", "call_id": "c1", "name": "get_status", "arguments": "{}"}, {"type": "function_call_output", "call_id": "c1", "output": ""}, ] msgs = Converter.items_to_messages(items) # tool msg content: '' <-- API rejects: content must be non-empty Lift the guard above the if/else so both branches go through it. `not tool_result_content` is truthy for both `""` and `[]`, so the single check covers both empty shapes.
Contributor
Author
|
Closing — on second read of #3310, the issue reporter explicitly listed "String tool outputs remain unchanged." as a deliberate edge case. The placement of #3312's guard in the Concrete reasons this PR doesn't make sense after all:
My PR conflated "empty content after filtering non-representable parts" with "user explicitly returned empty string" — those are semantically different. Apologies for the noise. |
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
Extends the fix in #3312 (`fix: avoid empty chat tool outputs`) to one case the original guard missed.
#3312 added an empty-content guard that swaps the tool message body with `_OMITTED_TOOL_OUTPUT_PLACEHOLDER` when the converted content is empty. The guard was placed inside the `else` branch of `isinstance(all_output_content, str)` at `chatcmpl_converter.py:749-769`, so it only triggered when the output was a non-text-only list. When the output is the empty string `""`, `extract_all_content("")` returns `""` (the string branch), `tool_result_content` is set to `""` without ever reaching the guard, and the Chat Completions message ends up with `"content": ""` — exactly the broken shape #3310/#3312 aimed to prevent.
Repro on current `main` (before this PR):
```python
Chat Completions API rejects: messages.X.content must be non-empty
```
Lift the guard above the `if/else` so both branches go through it. `not tool_result_content` is truthy for both `""` and `[]`, so the single check covers both empty shapes.
Test plan
Issue number
N/A — found while auditing for the same fix pattern that #3312 applied to empty lists.
Checks